Skip to content

Commit 7b5b600

Browse files
hyehayes-googlespullara
authored andcommitted
remove usage of immutablemap
1 parent c402e4e commit 7b5b600

File tree

1 file changed

+20
-13
lines changed

1 file changed

+20
-13
lines changed

compiler/src/test/java/com/github/mustachejava/SpecTest.java

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import com.fasterxml.jackson.databind.ObjectMapper;
55
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
66
import com.fasterxml.jackson.dataformat.yaml.YAMLMapper;
7-
import com.google.common.collect.ImmutableMap;
87
import org.junit.Test;
98

109
import java.io.IOException;
@@ -63,10 +62,10 @@ private void run(JsonNode spec) {
6362
int success = 0;
6463
int whitespace = 0;
6564
Map<String, Object> functionMap = new HashMap<String, Object>() {{
66-
put("Interpolation", mapWithConstantLambda("world"));
67-
put("Interpolation - Expansion", mapWithConstantLambda("{{planet}}"));
68-
put("Interpolation - Alternate Delimiters", mapWithConstantLambda("|planet| => {{planet}}"));
69-
put("Interpolation - Multiple Calls",ImmutableMap.of("lambda", new Function<String, String>() {
65+
put("Interpolation", singletonMapWithConstantLambda("world"));
66+
put("Interpolation - Expansion", singletonMapWithConstantLambda("{{planet}}"));
67+
put("Interpolation - Alternate Delimiters", singletonMapWithConstantLambda("|planet| => {{planet}}"));
68+
put("Interpolation - Multiple Calls",singletonMap("lambda", new Function<String, String>() {
7069

7170
int calls = 0;
7271

@@ -75,20 +74,20 @@ public String apply(String input) {
7574
return String.valueOf(++calls);
7675
}
7776
}));
78-
put("Escaping", mapWithConstantLambda(">"));
79-
put("Section", ImmutableMap.of(
77+
put("Escaping", singletonMapWithConstantLambda(">"));
78+
put("Section", singletonMap(
8079
"lambda",
8180
(TemplateFunction) (input) -> input.equals("{{x}}") ? "yes" : "no"));
82-
put("Section - Expansion", ImmutableMap.of(
81+
put("Section - Expansion", singletonMap(
8382
"lambda",
8483
(TemplateFunction) (input) -> input + "{{planet}}" + input));
85-
put("Section - Alternate Delimiters", ImmutableMap.of(
84+
put("Section - Alternate Delimiters", singletonMap(
8685
"lambda",
8786
(TemplateFunction) (input) -> input + "{{planet}} => |planet|" + input));
88-
put("Section - Multiple Calls", ImmutableMap.of(
87+
put("Section - Multiple Calls", singletonMap(
8988
"lambda",
9089
(TemplateFunction) (input) -> "__" + input + "__"));
91-
put("Inverted Section", mapWithConstantLambda(false));
90+
put("Inverted Section", singletonMapWithConstantLambda(false));
9291
}};
9392
for (final JsonNode test : spec.get("tests")) {
9493
boolean failed = false;
@@ -155,7 +154,15 @@ private JsonNode getSpec(String spec) throws IOException {
155154
"/spec/specs/" + spec))).readValueAsTree();
156155
}
157156

158-
private static Map<String, Function<String, Object>> mapWithConstantLambda(Object value) {
159-
return ImmutableMap.of("lambda", (input) -> value);
157+
private static Map<String, Function<String, Object>> singletonMapWithConstantLambda(Object value) {
158+
return new HashMap<String, Function<String, Object>>() {{
159+
put("lambda", (input) -> value);
160+
}};
161+
}
162+
163+
private static Map<String, Object> singletonMap(String key, Object value) {
164+
return new HashMap<String, Object>() {{
165+
put(key, value);
166+
}};
160167
}
161168
}

0 commit comments

Comments
 (0)