Merge branch '1.0.x'
This commit is contained in:
@@ -316,7 +316,7 @@ abstract class MethodBodyBuilder {
|
||||
String path = quotedAndEscaped(it.path())
|
||||
Object retrievedValue = value(copiedBody, it)
|
||||
String valueAsParam = retrievedValue instanceof String ? quotedAndEscaped(retrievedValue.toString()) : retrievedValue.toString()
|
||||
if (path.contains("[*]") && MatchingType.regexRelated(it.matchingType())) {
|
||||
if (arrayRelated(path) && MatchingType.regexRelated(it.matchingType())) {
|
||||
buildCustomMatchingConditionForEachElement(bb, path, valueAsParam)
|
||||
} else {
|
||||
String comparisonMethod = it.matchingType() == MatchingType.EQUALITY ? "isEqualTo" : "matches"
|
||||
@@ -341,6 +341,10 @@ abstract class MethodBodyBuilder {
|
||||
processBodyElement(bb, "", convertedResponseBody)
|
||||
}
|
||||
|
||||
protected boolean arrayRelated(String path) {
|
||||
return path.contains("[*]") || path.contains("..")
|
||||
}
|
||||
|
||||
protected void buildCustomMatchingConditionForEachElement(BlockBuilder bb, String path, String valueAsParam) {
|
||||
String method = "assertThat(parsedJson.read(${path}, java.util.Collection.class)).allElementsMatch(${valueAsParam})"
|
||||
bb.addLine(postProcessJsonPathCall(method))
|
||||
@@ -394,7 +398,7 @@ abstract class MethodBodyBuilder {
|
||||
|
||||
private String sizeCheckPrefix(BodyMatcher bodyMatcher) {
|
||||
String prefix = "has"
|
||||
if (bodyMatcher.path().contains("[*]")) {
|
||||
if (arrayRelated(bodyMatcher.path())) {
|
||||
prefix = prefix + "Flattened"
|
||||
}
|
||||
return prefix + "Size"
|
||||
|
||||
@@ -223,6 +223,7 @@ class MockMvcMethodBodyBuilderWithMatchersSpec extends Specification implements
|
||||
def test = blockBuilder.toString()
|
||||
then:
|
||||
test.contains('assertThat(parsedJson.read("' + rootElement + '.phoneNumbers[*].number", java.util.Collection.class)).allElementsMatch("^[0-9]{3} [0-9]{3}-[0-9]{4}' + rootElement + '")')
|
||||
test.contains('assertThat(parsedJson.read("' + rootElement + '..number", java.util.Collection.class)).allElementsMatch("^[0-9]{3} [0-9]{3}-[0-9]{4}' + rootElement + '")')
|
||||
!test.contains('cursor')
|
||||
and:
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user