replaced ".class" with ".getClass()" (#513)

... so that the actual class of the object is returned instead of
potentially an element with key "class" if object is a Map
This commit is contained in:
Tom Hombergs
2018-01-11 10:18:37 +01:00
committed by Marcin Grzejszczak
parent 6ed344e976
commit 6e65f36c31
2 changed files with 32 additions and 1 deletions

View File

@@ -468,7 +468,7 @@ abstract class MethodBodyBuilder {
// we want to make the type more generic (e.g. not ArrayList but List)
protected Class classToCheck(Object elementFromBody) {
switch (elementFromBody.class) {
switch (elementFromBody.getClass()) {
case List:
return List
case Set:

View File

@@ -487,4 +487,35 @@ DocumentContext parsedJson = JsonPath.parse(json);
"JaxRsClientJUnitMethodBodyBuilder" | { Contract dsl -> new JaxRsClientJUnitMethodBodyBuilder(dsl, properties) }
}
@Issue("#509")
def "classToCheck() should return class of object"() {
given:
Contract contractDsl = Contract.make {
request {
method 'POST'
url '/api/users'
}
response {
status 200
}
}
MethodBodyBuilder builder = methodBuilder(contractDsl)
when:
Map<String, String> map = new LinkedHashMap<>()
Integer number = Integer.valueOf(42)
List<String> list = new ArrayList<>()
Set<String> set = new HashSet<>()
then:
builder.classToCheck(map) == Map.class
and:
builder.classToCheck(number) == Integer.class
and:
builder.classToCheck(list) == List.class
and:
builder.classToCheck(set) == Set.class
where:
methodBuilderName | methodBuilder
"MockMvcSpockMethodBuilder" | { Contract dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl, properties) }
}
}