Skip to content

Commit

Permalink
feat: reproduce code based on comment in issue
Browse files Browse the repository at this point in the history
  • Loading branch information
arvgord committed Oct 26, 2024
1 parent 56e40cd commit dcb75b6
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions src/test/java/com/arvgord/JacksonSortingTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class JacksonSortingTest {

private final ObjectMapper objectMapper = new ObjectMapper();

private final String JSON_INPUT = """
private final String INPUT_JSON = """
{
"b": 2,
"a": 1,
Expand All @@ -31,7 +31,7 @@ public class JacksonSortingTest {
}
""";

private final String JSON_OUTPUT_SECOND = """
private final String SECOND_JSON_OUTPUT = """
{
"transactionId": "test",
"a": 1,
Expand All @@ -53,7 +53,7 @@ public class JacksonSortingTest {
}
""";

private final String JSON_OUTPUT_THIRD = """
private final String THIRD_JSON_OUTPUT = """
{
"transactionId": "test",
"c": [
Expand All @@ -75,28 +75,28 @@ public class JacksonSortingTest {
}
""";

private <T> void testSerializationDeserialization(String resultOutput, Class<T> clazz) throws Exception {
T deserializedObject = objectMapper.readValue(JSON_INPUT, clazz);
private <T> void testSerializationDeserialization(String outputResult, Class<T> clazz) throws Exception {
T deserializedObject = objectMapper.readValue(INPUT_JSON, clazz);
String serializedJson = objectMapper.writeValueAsString(deserializedObject);

String expectedJson = objectMapper.readTree(resultOutput).toPrettyString();
String expectedJson = objectMapper.readTree(outputResult).toPrettyString();
String actualJson = objectMapper.readTree(serializedJson).toPrettyString();

assertEquals(expectedJson, actualJson);
}

@Test
public void testSerializationAndDeserializationForFirstObject() throws Exception {
testSerializationDeserialization(JSON_INPUT, FirstObject.class);
testSerializationDeserialization(INPUT_JSON, FirstObject.class);
}

@Test
public void testSerializationAndDeserializationForSecondObject() throws Exception {
testSerializationDeserialization(JSON_OUTPUT_SECOND, SecondObject.class);
testSerializationDeserialization(SECOND_JSON_OUTPUT, SecondObject.class);
}

@Test
public void testSerializationAndDeserializationForThirdObject() throws Exception {
testSerializationDeserialization(JSON_OUTPUT_THIRD, ThirdObject.class);
testSerializationDeserialization(THIRD_JSON_OUTPUT, ThirdObject.class);
}
}

0 comments on commit dcb75b6

Please sign in to comment.