|
22 | 22 | import java.io.IOException; |
23 | 23 | import java.util.LinkedHashMap; |
24 | 24 | import java.util.Map; |
| 25 | +import java.util.Set; |
| 26 | +import java.util.stream.Collectors; |
| 27 | +import java.util.stream.Stream; |
25 | 28 |
|
26 | | -import org.junit.Ignore; |
| 29 | +import org.apache.commons.lang3.StringUtils; |
27 | 30 | import org.junit.Test; |
28 | 31 |
|
29 | 32 | import com.github.jknack.handlebars.context.JavaBeanValueResolver; |
@@ -57,28 +60,29 @@ public String getBody() { |
57 | 60 | .build(); |
58 | 61 | } |
59 | 62 |
|
60 | | - @Ignore |
| 63 | + @Test |
61 | 64 | public void eachKeyWithString() throws IOException { |
62 | | - String result = compile("{{#each this}}{{@key}} {{/each}}").apply("String"); |
| 65 | + Set<String> result = Stream.of(StringUtils.split( |
| 66 | + compile("{{#each this}}{{@key}} {{/each}}").apply(configureContext("String")), " ")) |
| 67 | + .collect(Collectors.toSet()); |
63 | 68 |
|
64 | | - String expected1 = "empty bytes "; |
65 | | - String expected2 = "bytes empty "; |
66 | | - assertTrue(result.equals(expected1) || result.equals(expected2)); |
| 69 | + Set<String> expected = Stream.of("empty", "bytes").collect(Collectors.toSet()); |
| 70 | + assertTrue(result.containsAll(expected)); |
67 | 71 | } |
68 | 72 |
|
69 | | - @Ignore |
| 73 | + @Test |
70 | 74 | public void eachKeyWithInt() throws IOException { |
71 | | - shouldCompileTo("{{#each this}}{{@key}} {{/each}}", 7, ""); |
| 75 | + shouldCompileTo("{{#each this}}{{@key}} {{/each}}", configureContext(7), ""); |
72 | 76 | } |
73 | 77 |
|
74 | 78 | @Test |
75 | 79 | public void eachKeyWithJavaBean() throws IOException { |
76 | 80 | Blog blog = new Blog("Handlebars.java", "..."); |
77 | | - String result = compile("{{#each this}}{{@key}}: {{this}} {{/each}}").apply(configureContext(blog)); |
| 81 | + Set<String> result = Stream.of(StringUtils.split(compile("{{#each this}}{{@key}}:{{this}} {{/each}}").apply(configureContext(blog)), " ")).collect( |
| 82 | + Collectors.toSet()); |
78 | 83 |
|
79 | | - String expected1 = "body: ... title: Handlebars.java "; |
80 | | - String expected2 = "title: Handlebars.java body: ... "; |
81 | | - assertTrue(result.equals(expected1) || result.equals(expected2)); |
| 84 | + Set<String> expected = Stream.of("body:...", "title:Handlebars.java").collect(Collectors.toSet()); |
| 85 | + assertTrue(result.containsAll(expected)); |
82 | 86 | } |
83 | 87 |
|
84 | 88 | @Test |
|
0 commit comments