diff --git a/gradle.properties b/gradle.properties index f3d61e579d..6e4259495e 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,7 +1,7 @@ bytebuddyVersion=1.10.8 commonsLang3Version=3.12.0 commonsCollections4=4.4 -groovyVersion=3.0.9 +groovyVersion=3.0.14 guavaVersion=30.1.1-jre httpBuilderVersion=1.0.4 httpClientVersion=5.1 diff --git a/provider/junit/src/main/kotlin/au/com/dius/pact/provider/junit/PactRunner.kt b/provider/junit/src/main/kotlin/au/com/dius/pact/provider/junit/PactRunner.kt index ccfa164e58..d999c60f44 100644 --- a/provider/junit/src/main/kotlin/au/com/dius/pact/provider/junit/PactRunner.kt +++ b/provider/junit/src/main/kotlin/au/com/dius/pact/provider/junit/PactRunner.kt @@ -1,6 +1,7 @@ package au.com.dius.pact.provider.junit import au.com.dius.pact.core.model.Pact +import au.com.dius.pact.core.support.Utils import au.com.dius.pact.core.support.expressions.DataType import au.com.dius.pact.core.support.expressions.ExpressionParser import au.com.dius.pact.core.support.expressions.SystemPropertyResolver diff --git a/provider/junit5/src/test/groovy/au/com/dius/pact/provider/junit5/PactVerificationInvocationContextProviderSpec.groovy b/provider/junit5/src/test/groovy/au/com/dius/pact/provider/junit5/PactVerificationInvocationContextProviderSpec.groovy index 984a91c4aa..6cb75b40e1 100644 --- a/provider/junit5/src/test/groovy/au/com/dius/pact/provider/junit5/PactVerificationInvocationContextProviderSpec.groovy +++ b/provider/junit5/src/test/groovy/au/com/dius/pact/provider/junit5/PactVerificationInvocationContextProviderSpec.groovy @@ -16,17 +16,17 @@ import au.com.dius.pact.provider.junitsupport.loader.PactSource import au.com.dius.pact.provider.junitsupport.loader.PactUrl import au.com.dius.pact.provider.junitsupport.target.Target import au.com.dius.pact.provider.junitsupport.target.TestTarget +import org.apache.commons.lang3.JavaVersion +import org.apache.commons.lang3.SystemUtils import org.junit.jupiter.api.extension.ExtensionContext -import spock.lang.Ignore import spock.lang.Issue +import spock.lang.Requires import spock.lang.Specification import spock.lang.Unroll import spock.util.environment.RestoreSystemProperties import java.util.stream.Collectors -// TODO: Groovy mocks don't work on JDK 16 -@Ignore @SuppressWarnings(['EmptyMethod', 'UnusedMethodParameter', 'LineLength']) class PactVerificationInvocationContextProviderSpec extends Specification { @@ -132,6 +132,8 @@ class PactVerificationInvocationContextProviderSpec extends Specification { } @Unroll + // TODO: Groovy mocks don't work on JDK 16 + @Requires(reason = "Groovy mocks don't work on JDK 16", value = { SystemUtils.isJavaVersionAtMost(JavaVersion.JAVA_15) }) def 'only supports tests with a provider annotation'() { expect: provider.supportsTestTemplate(['getTestClass': { Optional.of(testClass) } ] as ExtensionContext) == isSupported @@ -144,6 +146,8 @@ class PactVerificationInvocationContextProviderSpec extends Specification { ChildClass | true } + // TODO: Groovy mocks don't work on JDK 16 + @Requires(reason = "Groovy mocks don't work on JDK 16", value = { SystemUtils.isJavaVersionAtMost(JavaVersion.JAVA_15) }) def 'findPactSources throws an exception if there are no defined pact sources on the test class'() { when: provider.findPactSources(['getTestClass': { @@ -158,11 +162,15 @@ class PactVerificationInvocationContextProviderSpec extends Specification { def 'findPactSources returns a pact loader for each discovered pact source annotation'() { when: def sources = provider.findPactSources([ - 'getTestClass': { Optional.of(TestClassWithAnnotation) } ] as ExtensionContext - ) + 'getTestClass': { Optional.of(TestClassWithAnnotation) }, + 'getRequiredTestClass': { TestClassWithAnnotation }, + 'getTestInstance': { Optional.empty() } + ] as ExtensionContext) def childSources = provider.findPactSources([ - 'getTestClass': { Optional.of(ChildClass) } ] as ExtensionContext - ) + 'getTestClass': { Optional.of(ChildClass) }, + 'getRequiredTestClass': { ChildClass }, + 'getTestInstance': { Optional.empty() } + ] as ExtensionContext) then: sources.size() == 1 @@ -178,8 +186,10 @@ class PactVerificationInvocationContextProviderSpec extends Specification { def 'findPactSources returns a pact loader for each discovered pact source on any annotations'() { when: def sources = provider.findPactSources([ - 'getTestClass': { Optional.of(TestClassWithPactSourceOnAnnotation) } ] as ExtensionContext - ) + 'getTestClass': { Optional.of(TestClassWithPactSourceOnAnnotation) }, + 'getRequiredTestClass': { TestClassWithPactSourceOnAnnotation }, + 'getTestInstance': { Optional.empty() } + ] as ExtensionContext) then: sources.size() == 1 sources.first() instanceof PactFolderLoader @@ -189,8 +199,10 @@ class PactVerificationInvocationContextProviderSpec extends Specification { def 'returns a junit extension for each interaction in all the discovered pact files'() { when: def extensions = provider.provideTestTemplateInvocationContexts([ - 'getTestClass': { Optional.of(TestClassWithAnnotation) } ] as ExtensionContext - ) + 'getTestClass': { Optional.of(TestClassWithAnnotation) }, + 'getRequiredTestClass': { TestClassWithAnnotation }, + 'getTestInstance': { Optional.empty() } + ] as ExtensionContext) then: extensions.count() == 3 @@ -199,8 +211,10 @@ class PactVerificationInvocationContextProviderSpec extends Specification { def 'supports filtering the discovered pact files'() { when: def extensions = provider.provideTestTemplateInvocationContexts([ - 'getTestClass': { Optional.of(ChildClass) } ] as ExtensionContext - ) + 'getTestClass': { Optional.of(ChildClass) }, + 'getRequiredTestClass': { ChildClass }, + 'getTestInstance': { Optional.empty() } + ] as ExtensionContext) then: extensions.count() == 1 @@ -214,8 +228,10 @@ class PactVerificationInvocationContextProviderSpec extends Specification { when: def extensions = provider.provideTestTemplateInvocationContexts([ - 'getTestClass': { Optional.of(TestClassWithAnnotation) } ] as ExtensionContext - ) + 'getTestClass': { Optional.of(TestClassWithAnnotation) }, + 'getRequiredTestClass': { TestClassWithAnnotation }, + 'getTestInstance': { Optional.empty() } + ] as ExtensionContext) then: extensions.count() == 1 @@ -224,9 +240,11 @@ class PactVerificationInvocationContextProviderSpec extends Specification { @Issue('#1007') def 'provideTestTemplateInvocationContexts throws an exception if there are no pacts to verify'() { when: - provider.provideTestTemplateInvocationContexts(['getTestClass': { - Optional.of(TestClassWithNoPacts) - } ] as ExtensionContext) + provider.provideTestTemplateInvocationContexts([ + 'getTestClass': { Optional.of(TestClassWithNoPacts) }, + 'getRequiredTestClass': { TestClassWithNoPacts }, + 'getTestInstance': { Optional.empty() } + ] as ExtensionContext) then: def exp = thrown(NoPactsFoundException) @@ -236,9 +254,11 @@ class PactVerificationInvocationContextProviderSpec extends Specification { @Issue('#768') def 'returns a dummy test if there are no pacts to verify and IgnoreNoPactsToVerify is present'() { when: - def result = provider.provideTestTemplateInvocationContexts(['getTestClass': { - Optional.of(TestClassWithNoPactsWithIgnore) - } ] as ExtensionContext).iterator().toList() + def result = provider.provideTestTemplateInvocationContexts([ + 'getTestClass': { Optional.of(TestClassWithNoPactsWithIgnore) }, + 'getRequiredTestClass': { TestClassWithNoPactsWithIgnore }, + 'getTestInstance': { Optional.empty() } + ] as ExtensionContext).iterator().toList() then: result.size() == 1 @@ -274,8 +294,10 @@ class PactVerificationInvocationContextProviderSpec extends Specification { when: def extensions = provider.provideTestTemplateInvocationContexts([ - 'getTestClass': { Optional.of(TestClassWithEmptyProvider) } ] as ExtensionContext - ).collect(Collectors.toList()) + 'getTestClass': { Optional.of(TestClassWithEmptyProvider) }, + 'getRequiredTestClass': { TestClassWithEmptyProvider }, + 'getTestInstance': { Optional.empty() } + ] as ExtensionContext).collect(Collectors.toList()) then: !extensions.empty @@ -285,9 +307,11 @@ class PactVerificationInvocationContextProviderSpec extends Specification { @Issue('#1225') def 'provideTestTemplateInvocationContexts throws an exception if load request fails with an exception'() { when: - provider.provideTestTemplateInvocationContexts(['getTestClass': { - Optional.of(TestClassWithInvalidUrl) - } ] as ExtensionContext) + provider.provideTestTemplateInvocationContexts([ + 'getTestClass': { Optional.of(TestClassWithInvalidUrl) }, + 'getRequiredTestClass': { TestClassWithInvalidUrl }, + 'getTestInstance': { Optional.empty() } + ] as ExtensionContext) then: thrown(UnknownHostException) diff --git a/provider/lein/src/main/groovy/au/com/dius/pact/provider/lein/LeinVerifierProxy.groovy b/provider/lein/src/main/groovy/au/com/dius/pact/provider/lein/LeinVerifierProxy.groovy index 6df154ed57..7495c5b9f5 100644 --- a/provider/lein/src/main/groovy/au/com/dius/pact/provider/lein/LeinVerifierProxy.groovy +++ b/provider/lein/src/main/groovy/au/com/dius/pact/provider/lein/LeinVerifierProxy.groovy @@ -28,11 +28,12 @@ class LeinVerifierProxy { List verifyProvider(ProviderInfo provider) { verifier.verificationSource = 'lein' - verifier.projectHasProperty = { property -> - this.hasProperty.invoke(Clojure.read(":$property"), args) + verifier.projectHasProperty = { String property -> + def value = this.hasProperty.invoke(Clojure.read(":$property"), args) + value instanceof Boolean ? value : false } - verifier.projectGetProperty = { property -> - this.getProperty.invoke(Clojure.read(":$property"), args) + verifier.projectGetProperty = { String property -> + this.getProperty.invoke(Clojure.read(":$property"), args)?.toString() } verifier.pactLoadFailureMessage = { ConsumerInfo consumer -> "You must specify the pact file to execute for consumer '${consumer.name}' (use :pact-file or :pact-source)" diff --git a/provider/src/test/groovy/au/com/dius/pact/provider/readme/ReadmeExamplePactJVMProviderJUnitTest.groovy b/provider/src/test/groovy/au/com/dius/pact/provider/readme/ReadmeExamplePactJVMProviderJUnitTest.groovy index badb19d355..a228d21441 100644 --- a/provider/src/test/groovy/au/com/dius/pact/provider/readme/ReadmeExamplePactJVMProviderJUnitTest.groovy +++ b/provider/src/test/groovy/au/com/dius/pact/provider/readme/ReadmeExamplePactJVMProviderJUnitTest.groovy @@ -56,7 +56,7 @@ class ReadmeExamplePactJVMProviderJUnitTest { consumer.setPactSource(new UrlSource( ReadmeExamplePactJVMProviderJUnitTest.getResource('/pacts/zoo_app-animal_service.json').toString())) - testConsumerPact = DefaultPactReader.INSTANCE.loadPact(consumer.getPactSource()) as Pact + testConsumerPact = DefaultPactReader.INSTANCE.loadPact(consumer.getPactSource()) } @Test