Assert size of collections on the request side; fixes gh-824

This commit is contained in:
Marcin Grzejszczak
2018-12-20 14:53:38 +01:00
parent 6969d233b8
commit 9c7c896115
21 changed files with 202 additions and 117 deletions

View File

@@ -73,6 +73,13 @@ class BodyMatchers {
return new MatchingTypeValue(MatchingType.EQUALITY, null)
}
MatchingTypeValue byType(@DelegatesTo(MatchingTypeValueHolder) Closure closure) {
MatchingTypeValueHolder matchingTypeValue = new MatchingTypeValueHolder()
closure.delegate = matchingTypeValue
closure()
return matchingTypeValue.matchingTypeValue
}
boolean equals(o) {
if (this.is(o)) return true
if (this.getClass() != o.class) return false
@@ -147,3 +154,26 @@ class MatchingTypeValue {
*/
Integer maxTypeOccurrence
}
@CompileStatic
@ToString(includePackage = false)
@EqualsAndHashCode
class MatchingTypeValueHolder {
MatchingTypeValue matchingTypeValue = new MatchingTypeValue(type: MatchingType.TYPE)
MatchingTypeValue minOccurrence(int number) {
this.matchingTypeValue.minTypeOccurrence = number
return this.matchingTypeValue
}
MatchingTypeValue maxOccurrence(int number) {
this.matchingTypeValue.maxTypeOccurrence = number
return this.matchingTypeValue
}
MatchingTypeValue occurrence(int number) {
this.matchingTypeValue.minTypeOccurrence = number
this.matchingTypeValue.maxTypeOccurrence = number
return this.matchingTypeValue
}
}

View File

@@ -16,9 +16,7 @@
package org.springframework.cloud.contract.spec.internal
import groovy.transform.CompileStatic
import groovy.transform.EqualsAndHashCode
import groovy.transform.ToString
/**
* Body matchers for the response side (output message, REST response)
*
@@ -38,31 +36,7 @@ class ResponseBodyMatchers extends BodyMatchers {
return new MatchingTypeValue(MatchingType.COMMAND, new ExecutionProperty(execute))
}
MatchingTypeValue byType(@DelegatesTo(MatchingTypeValueHolder) Closure closure) {
MatchingTypeValueHolder matchingTypeValue = new MatchingTypeValueHolder()
closure.delegate = matchingTypeValue
closure()
return matchingTypeValue.matchingTypeValue
}
MatchingTypeValue byNull() {
return new MatchingTypeValue(MatchingType.NULL, null)
}
}
@CompileStatic
@ToString(includePackage = false)
@EqualsAndHashCode
class MatchingTypeValueHolder {
MatchingTypeValue matchingTypeValue = new MatchingTypeValue(type: MatchingType.TYPE)
MatchingTypeValue minOccurrence(int number) {
this.matchingTypeValue.minTypeOccurrence = number
return this.matchingTypeValue
}
MatchingTypeValue maxOccurrence(int number) {
this.matchingTypeValue.maxTypeOccurrence = number
return this.matchingTypeValue
}
}