Skip to content

Commit 5444ca5

Browse files
committed
apply FP DRY principle in assertEquivalentLionWebJson
1 parent eed7af5 commit 5444ca5

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

core/src/test/java/org/lionweb/lioncore/java/serialization/JsonSerializationTest.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
import java.io.InputStream;
1313
import java.io.InputStreamReader;
1414
import java.util.*;
15+
import java.util.function.Consumer;
16+
import java.util.function.Function;
1517
import java.util.stream.Collectors;
1618

1719
import static org.junit.Assert.assertEquals;
@@ -78,14 +80,12 @@ public void reserializeLibrary() {
7880
private void assertEquivalentLionWebJson(JsonArray expected, JsonArray actual) {
7981
Map<String, JsonObject> expectedElements = new HashMap<>();
8082
Map<String, JsonObject> actualElements = new HashMap<>();
81-
expected.forEach(e -> {
83+
Function<Map<String, JsonObject>, Consumer<JsonElement>> idCollector = collection -> e -> {
8284
String id = e.getAsJsonObject().get("id").getAsString();
83-
expectedElements.put(id, e.getAsJsonObject());
84-
});
85-
actual.forEach(e -> {
86-
String id = e.getAsJsonObject().get("id").getAsString();
87-
actualElements.put(id, e.getAsJsonObject());
88-
});
85+
collection.put(id, e.getAsJsonObject());
86+
};
87+
expected.forEach(idCollector.apply(expectedElements));
88+
actual.forEach(idCollector.apply(actualElements));
8989
Set<String> unexpectedIDs = new HashSet<>(actualElements.keySet());
9090
unexpectedIDs.removeAll(expectedElements.keySet());
9191
Set<String> missingIDs = new HashSet<>(expectedElements.keySet());

0 commit comments

Comments
 (0)