Skip to content

Commit

Permalink
Use jsonunit for json round-trip tests
Browse files Browse the repository at this point in the history
  • Loading branch information
iyourshaw committed Feb 27, 2025
1 parent 72bb7ab commit 1a1c530
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
2 changes: 2 additions & 0 deletions j2735-2024/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ dependencies {
testImplementation 'commons-io:commons-io:2.18.0'
testImplementation 'org.xmlunit:xmlunit-core:2.10.0'
testImplementation 'org.xmlunit:xmlunit-matchers:2.10.0'
testImplementation 'net.javacrumbs.json-unit:json-unit:4.1.0'


testRuntimeOnly 'org.junit.platform:junit-platform-launcher'

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package j2735.BasicSafetyMessage;


import j2735.Common.BSMcoreData;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*;
Expand All @@ -13,6 +13,7 @@
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
import static org.xmlunit.matchers.CompareMatcher.isIdenticalTo;
import static net.javacrumbs.jsonunit.JsonMatchers.jsonEquals;

public class BasicSafetyMessageTest extends BaseSerializeTest<BasicSafetyMessage> {

Expand All @@ -26,6 +27,8 @@ public void canDeserializeXml_NoExtensionsTest(String resourcePath) throws IOExc
String xml = loadResource(resourcePath);
BasicSafetyMessage bsm = fromXml(xml);
assertThat(bsm, notNullValue());
BSMcoreData coreData = bsm.getCoreData();
assertThat(coreData, notNullValue());
}

@ParameterizedTest
Expand All @@ -40,10 +43,20 @@ public void canRoundTripXml_NoExtensionsTest(String resourcePath) throws IOExcep

@ParameterizedTest
@MethodSource("getJsonResourcesNoExtensions")
public void jsonDeserializeNoExtensionsTest(String resourcePath) throws IOException {
public void canDeserialize_NoExtensionsTest(String resourcePath) throws IOException {
String json = loadResource(resourcePath);
BasicSafetyMessage bsm = fromJson(json);
assertThat(bsm, notNullValue());
}

@ParameterizedTest
@MethodSource("getJsonResourcesNoExtensions")
public void canRoundTripJson_NoExtensionsTest(String resourcePath) throws IOException {
String json = loadResource(resourcePath);
BasicSafetyMessage bsm = fromJson(json);
assertThat(bsm, notNullValue());
String roundTripJson = toJson(bsm);
assertThat(roundTripJson, jsonEquals(json));
}

private static Stream<Arguments> getXmlResourcesNoExtensions() {
Expand Down

0 comments on commit 1a1c530

Please sign in to comment.