-
-
Notifications
You must be signed in to change notification settings - Fork 200
Expand file tree
/
Copy pathValueResolveTest.java
More file actions
65 lines (54 loc) · 1.8 KB
/
ValueResolveTest.java
File metadata and controls
65 lines (54 loc) · 1.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/*
* Jooby https://jooby.io
* Apache License Version 2.0 https://jooby.io/LICENSE.txt
* Copyright 2014 Edgar Espina
*/
package io.jooby;
import static org.junit.jupiter.api.Assertions.assertEquals;
import java.util.NoSuchElementException;
import org.junit.jupiter.api.Test;
import io.jooby.internal.HashValue;
import io.jooby.value.Value;
public class ValueResolveTest {
@Test
public void resolveOne() {
Value value = Value.value(null, "foo", "bar");
assertEquals("bar", value.resolve("${foo}"));
assertEquals("- bar", value.resolve("- ${foo}"));
assertEquals("bar-", value.resolve("${foo}-"));
assertEquals("-", value.resolve("-"));
assertEquals("", value.resolve(""));
}
@Test
public void resolveComplexWithoutRoot() {
HashValue value = new HashValue(null, null);
value.put("foo.bar", "baz");
assertEquals("baz", value.resolve("${foo.bar}"));
assertEquals("-baz-", value.resolve("-${foo.bar}-"));
}
@Test
public void resolveComplex() {
HashValue value = new HashValue(null, null);
value.put("firstname", "Pedro");
value.put("lastname", "Picapiedra");
assertEquals("Hi Pedro Picapiedra!", value.resolve("Hi ${firstname} ${lastname}!"));
}
@Test
public void resolveComplexWithRoot() {
HashValue value = new HashValue(null, "foo");
value.put("bar", "baz");
assertEquals("baz", value.resolve("${foo.bar}"));
assertEquals("-baz-", value.resolve("-${foo.bar}-"));
}
@Test
public void resolveMissing() {
try {
Value value = Value.value(null, "x", "y");
assertEquals("bar", value.resolve("${foo}"));
} catch (NoSuchElementException x) {
assertEquals("Missing ${foo} at 1:1", x.getMessage());
}
Value value = Value.value(null, "x", "y");
assertEquals("${foo}", value.resolve("${foo}", true));
}
}