Tests fail to compile when the contract contains a long value (#358)

without this change when a contract contains a long value inside the body, then the code fails to compile since the provided number is assumed to be an integer.
with this change we're appending an L literal to that value for the compiler to assume that it's a long value.
This commit is contained in:
Felipe Adorno
2017-07-17 17:35:38 -03:00
committed by Marcin Grzejszczak
parent 28abd6fdce
commit 421b669361
2 changed files with 35 additions and 1 deletions

View File

@@ -174,7 +174,7 @@ class DelegatingJsonVerifiable implements MethodBufferingJsonVerifiable {
if (this.delegate.isAssertingAValueInArray() && containsAMatcher) {
readyToCheck.methodsBuffer.offer(".value()");
} else {
readyToCheck.appendMethodWithValue("isEqualTo", String.valueOf(value));
readyToCheck.appendMethodWithValue("isEqualTo", value instanceof Long ? String.valueOf(value).concat("L") : String.valueOf(value));
}
return readyToCheck;
}

View File

@@ -281,4 +281,38 @@ DocumentContext parsedJson = JsonPath.parse(json);
"JaxRsClientJUnitMethodBodyBuilder" | { Contract dsl -> new JaxRsClientJUnitMethodBodyBuilder(dsl, properties) } | { String testBody -> testBody.contains('assertThat(response.getHeaderString("Content-Length")).isEqualTo(4);') && testBody.contains('assertThat(response.getHeaderString("Content-Type")).matches("application/pdf.*");') }
}
def "should put L on long values [#methodBuilderName]"() {
given:
Contract contractDsl = Contract.make {
request {
method GET()
url "test"
}
response {
status 200
body(
"createdAt": 1502766000000,
"updatedAt": 1499476115000
)
}
}
MethodBodyBuilder builder = methodBuilder(contractDsl)
BlockBuilder blockBuilder = new BlockBuilder(" ")
when:
builder.appendTo(blockBuilder)
then:
blockBuilder.toString().contains("""assertThatJson(parsedJson).field("['createdAt']").isEqualTo(1502766000000L)""")
blockBuilder.toString().contains("""assertThatJson(parsedJson).field("['updatedAt']").isEqualTo(1499476115000L)""")
and:
SyntaxChecker.tryToCompileWithoutCompileStatic(methodBuilderName, blockBuilder.toString())
and:
stubMappingIsValidWireMockStub(contractDsl)
where:
methodBuilderName | methodBuilder
"MockMvcSpockMethodBuilder" | { Contract dsl -> new MockMvcSpockMethodRequestProcessingBodyBuilder(dsl, properties) }
"MockMvcJUnitMethodBuilder" | { Contract dsl -> new MockMvcJUnitMethodBodyBuilder(dsl, properties) }
"JaxRsClientSpockMethodRequestProcessingBodyBuilder" | { Contract dsl -> new JaxRsClientSpockMethodRequestProcessingBodyBuilder(dsl, properties) }
"JaxRsClientJUnitMethodBodyBuilder" | { Contract dsl -> new JaxRsClientJUnitMethodBodyBuilder(dsl, properties) }
}
}