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:

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

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:

- 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
testClassHasSelectorsMethodeven, because its not contained intestClass?.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
- fix: raise an exception when the consumerVersionSelectors method has the wrong signature #1594 — committed to pact-foundation/pact-jvm by uglyog 2 years ago
- fix: support consumer version selector methods on Kotlin test classes #1594 — committed to pact-foundation/pact-jvm by uglyog 2 years ago
- fix: raise an exception when the consumerVersionSelectors method has the wrong signature #1594 — committed to pact-foundation/pact-jvm by uglyog 2 years ago
Fix confirmed, this code works now:
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!