Skip to content

Commit

Permalink
Save a JSON round trip
Browse files Browse the repository at this point in the history
  • Loading branch information
leonardehrenfried committed Jan 2, 2024
1 parent 7cfbae8 commit c7395d8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ void spec() {
var regularStops = new VectorSourceLayer(vectorSource, "regularStops");
var spec = DebugStyleSpec.build(vectorSource, regularStops);

var json = ObjectMappers.ignoringExtraFields().valueToTree(spec).toPrettyString();
var json = ObjectMappers.ignoringExtraFields().valueToTree(spec);
var expectation = RES.fileToString("style.json");
assertEqualJson(expectation, json);
}
Expand Down
15 changes: 13 additions & 2 deletions src/test/java/org/opentripplanner/test/support/JsonAssertions.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import static org.junit.jupiter.api.Assertions.assertEquals;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.opentripplanner.standalone.config.framework.json.JsonSupport;

Expand All @@ -15,9 +16,19 @@ public class JsonAssertions {
*/
public static void assertEqualJson(String expected, String actual) {
try {
var act = MAPPER.readTree(actual);
assertEqualJson(expected, MAPPER.readTree(actual));
} catch (JsonProcessingException e) {
throw new RuntimeException(e);
}
}

/**
* @see JsonAssertions#assertEqualJson(String, String)
*/
public static void assertEqualJson(String expected, JsonNode actual) {
try {
var exp = MAPPER.readTree(expected);
assertEquals(JsonSupport.prettyPrint(exp), JsonSupport.prettyPrint(act));
assertEquals(JsonSupport.prettyPrint(exp), JsonSupport.prettyPrint(actual));
} catch (JsonProcessingException e) {
throw new RuntimeException(e);
}
Expand Down

0 comments on commit c7395d8

Please sign in to comment.