pact-jvm: Exception using new consumer version selector method in kotlin

Hi,

I started to migrate the @Deprecated consumerVersionSelectors = [ ] in the @PactBroker annotation by the new way, using @PactBrokerConsumerVersionSelectors method like this. See bottom line:

image

However when running my PactTest that ran using commented-out code above, I get this exception:

image

I debugged a bit your library and figured, that this line tries to invoke the identified selectorsMethod with a testInstance param that is Optional.empty() though. I find it strange that invokeSelectorsMethod thinks my selector method has 1 param even though it doesn’t. This circumstance is explicitly handled in testClassHasSelectorsMethod:

image

  • Kotlin version: 1.7.10
  • Pact version: 4.3.13
  • junit5: yes, PactVerificationInvocationContextProvider

What else I tried:

  • Moving my selector method out of abstract class and into to concrete test class
  • Making it “kotlin static” leads to not running into my breakpoint in testClassHasSelectorsMethod even, because its not contained in testClass?.kotlin?.members:
companion object {
        @PactBrokerConsumerVersionSelectors
        @JvmStatic
        fun consumerVersionSelectors(): SelectorBuilder = SelectorBuilder().branch("my-branch")
    }

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 15 (14 by maintainers)

Commits related to this issue

Most upvoted comments

Fix confirmed, this code works now:

@PactBrokerConsumerVersionSelectors
fun consumerVersionSelectors(): SelectorBuilder = SelectorBuilder()
     .branch("main")
     .environment("prod")
     .environment("qa")
     .environment("int")

Thanks a lot for this fast workflow, fix released just 3 days later, that’s amazing.

@viktorgt PACT has released the fix tonight.

I’ve updated the function, it will support both normal functions, abstract base classes as well as companion objects now. See https://github.com/pact-foundation/pact-jvm/blob/master/provider/junit5/src/test/kotlin/au/com/dius/pact/provider/junit5/ConsumerVersionSelectorKotlinTest.kt

For Spring tests, it is better to use @ExtendWith(PactVerificationSpringProvider::class)

Ah! You created a PR to fix the docs. What a champion!