Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
*
* @author Phillip Webb
* @author Andy Wilkinson
* @author Camille Vienot
* @since 1.4.0
*/
public class JsonContentAssert extends AbstractAssert<JsonContentAssert, CharSequence> {
Expand Down Expand Up @@ -96,7 +97,8 @@ public JsonContentAssert isEqualTo(Object expected) {
if (expected instanceof Resource) {
return isEqualToJson((Resource) expected);
}
throw new AssertionError("Unsupport type for JSON assert " + expected.getClass());
failWithMessage("Unsupport type for JSON assert {}", expected.getClass());
return null;
}

/**
Expand Down Expand Up @@ -432,7 +434,8 @@ public JsonContentAssert isNotEqualTo(Object expected) {
if (expected instanceof Resource) {
return isNotEqualToJson((Resource) expected);
}
throw new AssertionError("Unsupport type for JSON assert " + expected.getClass());
failWithMessage("Unsupport type for JSON assert {]", expected.getClass());
return null;
}

/**
Expand Down Expand Up @@ -1031,14 +1034,14 @@ private JSONCompareResult compareForNull(CharSequence expectedJson) {

private JsonContentAssert assertNotFailed(JSONCompareResult result) {
if (result.failed()) {
throw new AssertionError("JSON Comparison failure: " + result.getMessage());
failWithMessage("JSON Comparison failure: {}", result.getMessage());
}
return this;
}

private JsonContentAssert assertNotPassed(JSONCompareResult result) {
if (result.passed()) {
throw new AssertionError("JSON Comparison failure: " + result.getMessage());
failWithMessage("JSON Comparison failure: {}", result.getMessage());
}
return this;
}
Expand All @@ -1064,32 +1067,32 @@ public void assertHasEmptyValue() {
if (ObjectUtils.isEmpty(getValue(false)) || isIndefiniteAndEmpty()) {
return;
}
throw new AssertionError(getExpectedValueMessage("an empty value"));
failWithMessage(getExpectedValueMessage("an empty value"));
}

public void assertDoesNotHaveEmptyValue() {
if (!ObjectUtils.isEmpty(getValue(false))) {
return;
}
throw new AssertionError(getExpectedValueMessage("a non-empty value"));
failWithMessage(getExpectedValueMessage("a non-empty value"));

}

public void assertHasValue(Class<?> type, String expectedDescription) {
Object value = getValue(true);
if (value == null || isIndefiniteAndEmpty()) {
throw new AssertionError(getNoValueMessage());
failWithMessage(getNoValueMessage());
}
if (type != null && !type.isInstance(value)) {
throw new AssertionError(getExpectedValueMessage(expectedDescription));
failWithMessage(getExpectedValueMessage(expectedDescription));
}
}

public void assertDoesNotHaveValue() {
if (getValue(false) == null || isIndefiniteAndEmpty()) {
return;
}
throw new AssertionError(getExpectedValueMessage("no value"));
failWithMessage(getExpectedValueMessage("no value"));
}

private boolean isIndefiniteAndEmpty() {
Expand All @@ -1110,10 +1113,10 @@ public Object getValue(boolean required) {
return this.jsonPath.read((json != null) ? json.toString() : null);
}
catch (Exception ex) {
if (!required) {
return null;
if (required) {
failWithMessage("{}. {}", getNoValueMessage(), ex.getMessage());
}
throw new AssertionError(getNoValueMessage() + ". " + ex.getMessage());
return null;
}
}

Expand Down