pull/17614/head
Phillip Webb 5 years ago
parent 0d92af7d55
commit 6c0dbacfce

@ -25,7 +25,8 @@ import java.lang.annotation.Target;
import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.beans.factory.annotation.Qualifier;
/** /**
* Qualifier for beans that are needed to convert {@link Endpoint} input parameters. * Qualifier for beans that are needed to convert {@link Endpoint @Endpoint} input
* parameters.
* *
* @author Chao Chang * @author Chao Chang
* @since 2.2.0 * @since 2.2.0

@ -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))));

Loading…
Cancel
Save