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 Aug 2, 2022
1 parent b3db862 commit d23fcbe
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,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 @@ -1566,38 +1567,38 @@ class PactBrokerLoaderSpec extends Specification {

@SuppressWarnings(['EmptyMethod', 'UnusedMethodParameter'])
static class IncorrectTypesOnSelectorMethod {
@au.com.dius.pact.provider.junitsupport.loader.ConsumerVersionSelectors
@PactBrokerConsumerVersionSelectors
void consumerVersionSelectors(int i) { }
}

@SuppressWarnings('UnusedMethodParameter')
static class IncorrectTypesOnSelectorMethod2 {
@au.com.dius.pact.provider.junitsupport.loader.ConsumerVersionSelectors
@PactBrokerConsumerVersionSelectors
int consumerVersionSelectors() { 0 }
}

@SuppressWarnings(['UnusedPrivateMethod', 'UnusedPrivateMethodParameter'])
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 @@ -29,7 +29,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 @@ -374,7 +373,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 d23fcbe

Please sign in to comment.