|
|
@ -1101,7 +1101,7 @@ public class JsonContentAssert extends AbstractAssert<JsonContentAssert, CharSeq
|
|
|
|
void assertHasValue(Class<?> type, String expectedDescription) {
|
|
|
|
void assertHasValue(Class<?> type, String expectedDescription) {
|
|
|
|
Object value = getValue(true);
|
|
|
|
Object value = getValue(true);
|
|
|
|
if (value == null || isIndefiniteAndEmpty()) {
|
|
|
|
if (value == null || isIndefiniteAndEmpty()) {
|
|
|
|
failWithMessage(getNoValueMessage());
|
|
|
|
failWithNoValueMessage();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (type != null && !type.isInstance(value)) {
|
|
|
|
if (type != null && !type.isInstance(value)) {
|
|
|
|
failWithMessage(getExpectedValueMessage(expectedDescription));
|
|
|
|
failWithMessage(getExpectedValueMessage(expectedDescription));
|
|
|
@ -1133,21 +1133,21 @@ public class JsonContentAssert extends AbstractAssert<JsonContentAssert, CharSeq
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Exception ex) {
|
|
|
|
catch (Exception ex) {
|
|
|
|
if (required) {
|
|
|
|
if (required) {
|
|
|
|
failWithMessage("%s. %s", getNoValueMessage(), ex.getMessage());
|
|
|
|
failWithNoValueMessage();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void failWithNoValueMessage() {
|
|
|
|
|
|
|
|
failWithMessage("No value at JSON path \"%s\"", this.expression);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private Object read() {
|
|
|
|
private Object read() {
|
|
|
|
CharSequence json = JsonContentAssert.this.actual;
|
|
|
|
CharSequence json = JsonContentAssert.this.actual;
|
|
|
|
return this.jsonPath.read((json != null) ? json.toString() : null, JsonContentAssert.this.configuration);
|
|
|
|
return this.jsonPath.read((json != null) ? json.toString() : null, JsonContentAssert.this.configuration);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private String getNoValueMessage() {
|
|
|
|
|
|
|
|
return "No value at JSON path \"" + this.expression + "\"";
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private String getExpectedValueMessage(String expectedDescription) {
|
|
|
|
private String getExpectedValueMessage(String expectedDescription) {
|
|
|
|
return String.format("Expected %s at JSON path \"%s\" but found: %s", expectedDescription, this.expression,
|
|
|
|
return String.format("Expected %s at JSON path \"%s\" but found: %s", expectedDescription, this.expression,
|
|
|
|
ObjectUtils.nullSafeToString(StringUtils.quoteIfString(getValue(false))));
|
|
|
|
ObjectUtils.nullSafeToString(StringUtils.quoteIfString(getValue(false))));
|
|
|
|