Merge branch '5.2.x'

This commit is contained in:
Sam Brannen
2020-08-01 16:42:31 +02:00
3 changed files with 36 additions and 19 deletions

View File

@@ -26,6 +26,7 @@ import org.hamcrest.MatcherAssert;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;
@@ -108,10 +109,18 @@ public class JsonPathExpectationsHelper {
}
actualValue = actualValueList.get(0);
}
else if (actualValue != null && expectedValue != null) {
if (!actualValue.getClass().equals(expectedValue.getClass())) {
else if (actualValue != null && expectedValue != null &&
!actualValue.getClass().equals(expectedValue.getClass())) {
try {
actualValue = evaluateJsonPath(content, expectedValue.getClass());
}
catch (AssertionError error) {
String message = String.format(
"At JSON path \"%s\", value <%s> of type <%s> cannot be converted to type <%s>",
this.expression, actualValue, ClassUtils.getDescriptiveType(actualValue),
ClassUtils.getDescriptiveType(expectedValue));
throw new AssertionError(message, error.getCause());
}
}
AssertionErrors.assertEquals("JSON path \"" + this.expression + "\"", expectedValue, actualValue);
}
@@ -298,7 +307,7 @@ public class JsonPathExpectationsHelper {
/**
* Variant of {@link #evaluateJsonPath(String)} with a target type.
* This can be useful for matching numbers reliably for example coercing an
* <p>This can be useful for matching numbers reliably for example coercing an
* integer into a double.
* @param content the content to evaluate against
* @return the result of the evaluation