From a47176118917db6053717c842f6c72cfafc38f84 Mon Sep 17 00:00:00 2001 From: Ronald Holshausen Date: Tue, 5 Jul 2022 17:04:10 +1000 Subject: [PATCH] refactor: rename ConsumerVersionSelectors annotation so it does not clash with the model class --- .../junit/loader/PactBrokerLoaderSpec.groovy | 14 +++++++------- provider/junit5/README.md | 6 +++--- .../loader/IConsumerVersionSelectors.java | 2 +- ...ava => PactBrokerConsumerVersionSelectors.java} | 2 +- .../junitsupport/loader/PactBrokerLoader.kt | 3 +-- 5 files changed, 13 insertions(+), 14 deletions(-) rename provider/src/main/java/au/com/dius/pact/provider/junitsupport/loader/{ConsumerVersionSelectors.java => PactBrokerConsumerVersionSelectors.java} (83%) diff --git a/provider/junit/src/test/groovy/au/com/dius/pact/provider/junit/loader/PactBrokerLoaderSpec.groovy b/provider/junit/src/test/groovy/au/com/dius/pact/provider/junit/loader/PactBrokerLoaderSpec.groovy index 397e746f7c..32112e7542 100644 --- a/provider/junit/src/test/groovy/au/com/dius/pact/provider/junit/loader/PactBrokerLoaderSpec.groovy +++ b/provider/junit/src/test/groovy/au/com/dius/pact/provider/junit/loader/PactBrokerLoaderSpec.groovy @@ -3,7 +3,6 @@ package au.com.dius.pact.provider.junit.loader import au.com.dius.pact.core.model.Pact import au.com.dius.pact.core.model.PactBrokerSource import au.com.dius.pact.core.model.PactReader -import au.com.dius.pact.core.pactbroker.ConsumerVersionSelector import au.com.dius.pact.core.pactbroker.ConsumerVersionSelectors import au.com.dius.pact.core.pactbroker.IPactBrokerClient import au.com.dius.pact.core.pactbroker.InvalidHalResponse @@ -14,6 +13,7 @@ import au.com.dius.pact.core.support.expressions.ExpressionParser import au.com.dius.pact.core.support.expressions.SystemPropertyResolver import au.com.dius.pact.core.support.expressions.ValueResolver import au.com.dius.pact.provider.junitsupport.loader.IConsumerVersionSelectors +import au.com.dius.pact.provider.junitsupport.loader.PactBrokerConsumerVersionSelectors import au.com.dius.pact.provider.junitsupport.loader.SelectorBuilder import au.com.dius.pact.provider.junitsupport.loader.VersionSelector import au.com.dius.pact.provider.junitsupport.loader.NoPactsFoundException @@ -1568,36 +1568,36 @@ class PactBrokerLoaderSpec extends Specification { } static class IncorrectTypesOnSelectorMethod { - @au.com.dius.pact.provider.junitsupport.loader.ConsumerVersionSelectors + @PactBrokerConsumerVersionSelectors void consumerVersionSelectors(int i) {} } static class IncorrectTypesOnSelectorMethod2 { - @au.com.dius.pact.provider.junitsupport.loader.ConsumerVersionSelectors + @PactBrokerConsumerVersionSelectors int consumerVersionSelectors() { 0 } } static class IncorrectScopeOnSelectorMethod { - @au.com.dius.pact.provider.junitsupport.loader.ConsumerVersionSelectors + @PactBrokerConsumerVersionSelectors private SelectorBuilder consumerVersionSelectors() { null } } static class CorrectSelectorMethod implements IConsumerVersionSelectors { - @au.com.dius.pact.provider.junitsupport.loader.ConsumerVersionSelectors + @PactBrokerConsumerVersionSelectors SelectorBuilder consumerVersionSelectors() { new SelectorBuilder().environment('CorrectSelectorMethod') } } static class CorrectSelectorMethod2 { - @au.com.dius.pact.provider.junitsupport.loader.ConsumerVersionSelectors + @PactBrokerConsumerVersionSelectors List consumerVersionSelectors() { new SelectorBuilder().environment('CorrectSelectorMethod2').build() } } static class CorrectSelectorMethod3 { - @au.com.dius.pact.provider.junitsupport.loader.ConsumerVersionSelectors + @PactBrokerConsumerVersionSelectors static List consumerVersionSelectors() { new SelectorBuilder().environment('CorrectSelectorMethod3').build() } diff --git a/provider/junit5/README.md b/provider/junit5/README.md index 4fc53bf103..b6339d1382 100644 --- a/provider/junit5/README.md +++ b/provider/junit5/README.md @@ -123,13 +123,13 @@ If you are using a Pact broker to host your Pact files, you can select the Pacts There are a few ways to do this. ### Using an annotated method with a builder -You can add a static method to your test class annotated with `au.com.dius.pact.provider.junitsupport.loader.ConsumerVersionSelectors` +You can add a static method to your test class annotated with `au.com.dius.pact.provider.junitsupport.loader.PactBrokerConsumerVersionSelectors` which returns a `SelectorBuilder`. The builder will allow you to specify the selectors to use in a type-safe manner. For example: ```java - @au.com.dius.pact.provider.junitsupport.loader.ConsumerVersionSelectors + @au.com.dius.pact.provider.junitsupport.loader.PactBrokerConsumerVersionSelectors static SelectorBuilder consumerVersionSelectors() { // Select Pacts for consumers deployed to production with branch 'FEAT-123' return new SelectorBuilder() @@ -141,7 +141,7 @@ For example: Or for example where the branch is set with the `BRANCH_NAME` environment variable: ```java - @au.com.dius.pact.provider.junitsupport.loader.ConsumerVersionSelectors + @au.com.dius.pact.provider.junitsupport.loader.PactBrokerConsumerVersionSelectors static SelectorBuilder consumerVersionSelectors() { // Select Pacts for consumers deployed to production with branch from CI build return new SelectorBuilder() diff --git a/provider/src/main/java/au/com/dius/pact/provider/junitsupport/loader/IConsumerVersionSelectors.java b/provider/src/main/java/au/com/dius/pact/provider/junitsupport/loader/IConsumerVersionSelectors.java index 6e0ab5a682..38181e1850 100644 --- a/provider/src/main/java/au/com/dius/pact/provider/junitsupport/loader/IConsumerVersionSelectors.java +++ b/provider/src/main/java/au/com/dius/pact/provider/junitsupport/loader/IConsumerVersionSelectors.java @@ -7,6 +7,6 @@ public interface IConsumerVersionSelectors { /** * Return the consumer version selectors to use in the test */ - @au.com.dius.pact.provider.junitsupport.loader.ConsumerVersionSelectors + @PactBrokerConsumerVersionSelectors SelectorBuilder consumerVersionSelectors(); } diff --git a/provider/src/main/java/au/com/dius/pact/provider/junitsupport/loader/ConsumerVersionSelectors.java b/provider/src/main/java/au/com/dius/pact/provider/junitsupport/loader/PactBrokerConsumerVersionSelectors.java similarity index 83% rename from provider/src/main/java/au/com/dius/pact/provider/junitsupport/loader/ConsumerVersionSelectors.java rename to provider/src/main/java/au/com/dius/pact/provider/junitsupport/loader/PactBrokerConsumerVersionSelectors.java index bbc9e47169..c4cb85adab 100644 --- a/provider/src/main/java/au/com/dius/pact/provider/junitsupport/loader/ConsumerVersionSelectors.java +++ b/provider/src/main/java/au/com/dius/pact/provider/junitsupport/loader/PactBrokerConsumerVersionSelectors.java @@ -8,4 +8,4 @@ @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.METHOD) @Inherited -public @interface ConsumerVersionSelectors { } +public @interface PactBrokerConsumerVersionSelectors { } diff --git a/provider/src/main/kotlin/au/com/dius/pact/provider/junitsupport/loader/PactBrokerLoader.kt b/provider/src/main/kotlin/au/com/dius/pact/provider/junitsupport/loader/PactBrokerLoader.kt index 4ce6cb63bb..c1a82fbb3a 100644 --- a/provider/src/main/kotlin/au/com/dius/pact/provider/junitsupport/loader/PactBrokerLoader.kt +++ b/provider/src/main/kotlin/au/com/dius/pact/provider/junitsupport/loader/PactBrokerLoader.kt @@ -28,7 +28,6 @@ import java.net.URISyntaxException import kotlin.reflect.KCallable import kotlin.reflect.KClass import kotlin.reflect.KParameter -import kotlin.reflect.KType import kotlin.reflect.KVisibility import kotlin.reflect.full.findAnnotation import kotlin.reflect.full.isSubtypeOf @@ -376,7 +375,7 @@ open class PactBrokerLoader( fun testClassHasSelectorsMethod(testClass: Class<*>?): KCallable<*>? { val projectedType = SelectorBuilder::class.starProjectedType return testClass?.kotlin?.members?.firstOrNull { method -> - method.findAnnotation() != null + method.findAnnotation() != null && ( // static method method.parameters.isEmpty()