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:
committed by
Marcin Grzejszczak
parent
6ed344e976
commit
6e65f36c31
@@ -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:
|
||||
|
||||
@@ -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) }
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user