Added more tests to have better coverage

This commit is contained in:
Alex Xandra Albert Sim
2018-04-11 14:47:17 +07:00
parent a181c6576f
commit 2068fdc8ca
2 changed files with 82 additions and 0 deletions

View File

@@ -84,6 +84,21 @@ class JaxRsClientMethodBuilderSpec extends Specification implements WireMockStub
}
}
@Shared
Contract contractDslWithAbsentCookies = Contract.make {
request {
method "GET"
url "/foo"
cookies {
cookie 'cookie-key': absent()
}
}
response {
status 200
body([status: 'OK'])
}
}
def "should generate assertions for simple response body with #methodBuilderName"() {
given:
Contract contractDsl = Contract.make {
@@ -1286,6 +1301,19 @@ DATA
SyntaxChecker.tryToCompile("JaxRsClientJUnitMethodBodyBuilder", blockBuilder.toString())
}
def "should not generate cookie assertions with absent value in JAX-RS JUnit test"() {
given:
MethodBodyBuilder builder = new JaxRsClientJUnitMethodBodyBuilder(contractDslWithAbsentCookies, properties)
BlockBuilder blockBuilder = new BlockBuilder(" ")
when:
builder.appendTo(blockBuilder)
def test = blockBuilder.toString()
then:
!test.contains("cookie")
and:
SyntaxChecker.tryToCompile("JaxRsClientJunitMethodBodyBuilder", blockBuilder.toString())
}
def "should generate test for cookies with string value in JAX-RS Spock test"() {
given:
MethodBodyBuilder builder = new JaxRsClientSpockMethodRequestProcessingBodyBuilder(contractDslWithCookiesValue, properties)
@@ -1315,4 +1343,17 @@ DATA
and:
SyntaxChecker.tryToCompile("JaxRsClientSpockMethodRequestProcessingBodyBuilder", blockBuilder.toString())
}
def "should not generate cookie assertions with absent value in JAX-RS Spock test"() {
given:
MethodBodyBuilder builder = new JaxRsClientSpockMethodRequestProcessingBodyBuilder(contractDslWithAbsentCookies, properties)
BlockBuilder blockBuilder = new BlockBuilder(" ")
when:
builder.appendTo(blockBuilder)
def test = blockBuilder.toString()
then:
!test.contains("cookie")
and:
SyntaxChecker.tryToCompile("JaxRsClientSpockMethodRequestProcessingBodyBuilder", blockBuilder.toString())
}
}

View File

@@ -88,6 +88,21 @@ class MockMvcMethodBodyBuilderSpec extends Specification implements WireMockStub
}
}
@Shared
Contract contractDslWithAbsentCookies = Contract.make {
request {
method "GET"
url "/foo"
cookies {
cookie 'cookie-key': absent()
}
}
response {
status 200
body([status: 'OK'])
}
}
@Shared
// tag::contract_with_regex[]
Contract dslWithOptionalsInString = Contract.make {
@@ -2491,6 +2506,19 @@ DocumentContext parsedJson = JsonPath.parse(json);
SyntaxChecker.tryToCompile("MockMvcJUnitMethodBodyBuilder", blockBuilder.toString())
}
def "should not generate JUnit cookie assertion with absent cookie"() {
given:
MethodBodyBuilder builder = new MockMvcJUnitMethodBodyBuilder(contractDslWithAbsentCookies, properties)
BlockBuilder blockBuilder = new BlockBuilder(" ")
when:
builder.appendTo(blockBuilder)
def test = blockBuilder.toString()
then:
!test.contains("cookie")
and:
SyntaxChecker.tryToCompile("MockMvcJUnitMethodBodyBuilder", blockBuilder.toString())
}
def "should generate spock assertions with cookies"() {
given:
MethodBodyBuilder builder = new MockMvcSpockMethodRequestProcessingBodyBuilder(contractDslWithCookiesValue, properties)
@@ -2521,4 +2549,17 @@ DocumentContext parsedJson = JsonPath.parse(json);
SyntaxChecker.tryToCompile("MockMvcSpockMethodRequestProcessingBodyBuilder", blockBuilder.toString())
}
def "should not generate spock cookie assertion with absent cookie"() {
given:
MethodBodyBuilder builder = new MockMvcSpockMethodRequestProcessingBodyBuilder(contractDslWithAbsentCookies, properties)
BlockBuilder blockBuilder = new BlockBuilder(" ")
when:
builder.appendTo(blockBuilder)
def test = blockBuilder.toString()
then:
!test.contains("cookie")
and:
SyntaxChecker.tryToCompile("MockMvcSpockMethodRequestProcessingBodyBuilder", blockBuilder.toString())
}
}