Skip to content

Commit

Permalink
Use JSONAssert to compare JSON strings (#3116)
Browse files Browse the repository at this point in the history
  • Loading branch information
219sansim authored Dec 10, 2023
1 parent 80439b6 commit 845956c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
6 changes: 6 additions & 0 deletions elide-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,12 @@
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.skyscreamer</groupId>
<artifactId>jsonassert</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
Expand Down
15 changes: 13 additions & 2 deletions elide-core/src/test/java/com/yahoo/elide/jsonapi/JsonApiTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.fail;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.doThrow;
Expand Down Expand Up @@ -52,9 +53,11 @@
import example.Parent;

import org.apache.commons.collections4.IterableUtils;
import org.json.JSONException;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.Answers;
import org.skyscreamer.jsonassert.JSONAssert;

import jakarta.validation.ConstraintViolation;
import jakarta.validation.ConstraintViolationException;
Expand Down Expand Up @@ -236,7 +239,11 @@ public void writeSingleIncluded() throws JsonProcessingException {
String doc = mapper.writeJsonApiDocument(jsonApiDocument);
assertEquals(data, jsonApiDocument.getData());

assertEquals(expected, doc);
try {
JSONAssert.assertEquals(expected, doc, true);
} catch (JSONException e) {
fail(e);
}
checkEquality(jsonApiDocument);
}

Expand Down Expand Up @@ -332,7 +339,11 @@ public void writeListIncluded() throws JsonProcessingException {
String doc = mapper.writeJsonApiDocument(jsonApiDocument);
assertEquals(data, jsonApiDocument.getData());

assertEquals(expected, doc);
try {
JSONAssert.assertEquals(expected, doc, true);
} catch (JSONException e) {
fail(e);
}
checkEquality(jsonApiDocument);
}

Expand Down

0 comments on commit 845956c

Please sign in to comment.