From 57c030189bd030ba4417dfd56bd6a45f0371890c Mon Sep 17 00:00:00 2001 From: Olga Maciaszek-Sharma Date: Sun, 21 Feb 2016 18:00:24 +0100 Subject: [PATCH] Fixed handling execution properties in JUnit tests. --- .../accurest/builder/JUnitMethodBodyBuilder.groovy | 9 ++++++++- .../builder/MockMvcJunitMethodBuilderSpec.groovy | 4 +--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/accurest-core/src/main/groovy/io/codearte/accurest/builder/JUnitMethodBodyBuilder.groovy b/accurest-core/src/main/groovy/io/codearte/accurest/builder/JUnitMethodBodyBuilder.groovy index f6153341d1..d3365490d0 100644 --- a/accurest-core/src/main/groovy/io/codearte/accurest/builder/JUnitMethodBodyBuilder.groovy +++ b/accurest-core/src/main/groovy/io/codearte/accurest/builder/JUnitMethodBodyBuilder.groovy @@ -64,7 +64,14 @@ abstract class JUnitMethodBodyBuilder extends MethodBodyBuilder { @Override protected void processBodyElement(BlockBuilder blockBuilder, String property, Map.Entry entry) { - processBodyElement(blockBuilder, property + """.get(\\\"$entry.key\\\")""", entry.value) + processBodyElement(blockBuilder, property + getMapKeyReferenceString(entry), entry.value) + } + + private String getMapKeyReferenceString(Map.Entry entry) { + if (entry.value instanceof ExecutionProperty){ + return "." + entry.key + } + return """.get(\\\"$entry.key\\\")""" } @Override diff --git a/accurest-core/src/test/groovy/io/codearte/accurest/builder/MockMvcJunitMethodBuilderSpec.groovy b/accurest-core/src/test/groovy/io/codearte/accurest/builder/MockMvcJunitMethodBuilderSpec.groovy index f3bd466005..0fa9e420f0 100644 --- a/accurest-core/src/test/groovy/io/codearte/accurest/builder/MockMvcJunitMethodBuilderSpec.groovy +++ b/accurest-core/src/test/groovy/io/codearte/accurest/builder/MockMvcJunitMethodBuilderSpec.groovy @@ -740,8 +740,6 @@ class MockMvcJunitMethodBuilderSpec extends Specification implements WireMockStu } @Issue('72') - @Ignore - //TODO: fix exec method for jUnit def "should make the execute method work"() { given: GroovyDsl contractDsl = GroovyDsl.make { @@ -781,7 +779,7 @@ class MockMvcJunitMethodBuilderSpec extends Specification implements WireMockStu builder.appendTo(blockBuilder) def jUnitTest = blockBuilder.toString() then: - jUnitTest.contains('''assertThatRejectionReasonIsNull(parsedJson.read('$.rejectionReason'))''') + jUnitTest.contains('''assertThatRejectionReasonIsNull(parsedJson.read("$.rejectionReason"))''') } def "should support inner map and list definitions"() {