mirror of
https://github.com/spring-projects/spring-boot.git
synced 2026-10-05 16:59:28 +00:00
Improve null-safety of JsonContentAssert
See gh-46926
This commit is contained in:
+14
-4
@@ -1000,9 +1000,11 @@ public class JsonContentAssert extends AbstractAssert<JsonContentAssert, CharSeq
|
||||
if (this.actual == null) {
|
||||
return compareForNull(expectedJson);
|
||||
}
|
||||
if (expectedJson == null) {
|
||||
return fail("Expected JSON but got null");
|
||||
}
|
||||
try {
|
||||
return JSONCompare.compareJSON((expectedJson != null) ? expectedJson.toString() : null,
|
||||
this.actual.toString(), compareMode);
|
||||
return JSONCompare.compareJSON(expectedJson.toString(), this.actual.toString(), compareMode);
|
||||
}
|
||||
catch (Exception ex) {
|
||||
if (ex instanceof RuntimeException runtimeException) {
|
||||
@@ -1016,9 +1018,11 @@ public class JsonContentAssert extends AbstractAssert<JsonContentAssert, CharSeq
|
||||
if (this.actual == null) {
|
||||
return compareForNull(expectedJson);
|
||||
}
|
||||
if (expectedJson == null) {
|
||||
return fail("Expected JSON but got null");
|
||||
}
|
||||
try {
|
||||
return JSONCompare.compareJSON((expectedJson != null) ? expectedJson.toString() : null,
|
||||
this.actual.toString(), comparator);
|
||||
return JSONCompare.compareJSON(expectedJson.toString(), this.actual.toString(), comparator);
|
||||
}
|
||||
catch (Exception ex) {
|
||||
if (ex instanceof RuntimeException runtimeException) {
|
||||
@@ -1037,6 +1041,12 @@ public class JsonContentAssert extends AbstractAssert<JsonContentAssert, CharSeq
|
||||
return result;
|
||||
}
|
||||
|
||||
private JSONCompareResult fail(String message) {
|
||||
JSONCompareResult result = new JSONCompareResult();
|
||||
result.fail(message);
|
||||
return result;
|
||||
}
|
||||
|
||||
private JsonContentAssert assertNotFailed(JSONCompareResult result) {
|
||||
if (result.failed()) {
|
||||
failWithMessage("JSON Comparison failure: %s", result.getMessage());
|
||||
|
||||
Reference in New Issue
Block a user