Skip to content

Commit

Permalink
refactor: rename ConsumerVersionSelectors annotation so it does not c…
Browse files Browse the repository at this point in the history
…lash with the model class
  • Loading branch information
uglyog committed Jul 5, 2022
1 parent 8335063 commit a471761
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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> consumerVersionSelectors() {
new SelectorBuilder().environment('CorrectSelectorMethod2').build()
}
}

static class CorrectSelectorMethod3 {
@au.com.dius.pact.provider.junitsupport.loader.ConsumerVersionSelectors
@PactBrokerConsumerVersionSelectors
static List<ConsumerVersionSelectors> consumerVersionSelectors() {
new SelectorBuilder().environment('CorrectSelectorMethod3').build()
}
Expand Down
6 changes: 3 additions & 3 deletions provider/junit5/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
@Inherited
public @interface ConsumerVersionSelectors { }
public @interface PactBrokerConsumerVersionSelectors { }
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<au.com.dius.pact.provider.junitsupport.loader.ConsumerVersionSelectors>() != null
method.findAnnotation<PactBrokerConsumerVersionSelectors>() != null
&& (
// static method
method.parameters.isEmpty()
Expand Down

0 comments on commit a471761

Please sign in to comment.