@@ -30,6 +30,7 @@ import au.com.dius.pact.core.support.expressions.DataType
30
30
import au.com.dius.pact.core.support.expressions.ExpressionParser
31
31
import au.com.dius.pact.core.support.isNotEmpty
32
32
import io.github.oshai.kotlinlogging.KLogging
33
+ import org.apache.hc.core5.util.ReflectionUtils
33
34
import org.junit.jupiter.api.Disabled
34
35
import org.junit.jupiter.api.Nested
35
36
import org.junit.jupiter.api.TestTemplate
@@ -268,36 +269,38 @@ class PactConsumerTestExt : Extension, BeforeTestExecutionCallback, BeforeAllCal
268
269
): BasePact {
269
270
val store = context.getStore(NAMESPACE )
270
271
val key = " pact:${providerInfo.providerName} "
272
+ var methods = pactMethods
273
+ if (methods.isEmpty()) {
274
+ methods = AnnotationSupport .findAnnotatedMethods(context.requiredTestClass, Pact ::class .java, HierarchyTraversalMode .TOP_DOWN )
275
+ .map { m -> m.name}
276
+ }
277
+
271
278
return when {
272
279
store[key] != null -> store[key] as BasePact
273
280
else -> {
274
- val pact = if (pactMethods.isEmpty()) {
275
- lookupPact(providerInfo, " " , context)
276
- } else {
277
- val head = pactMethods.first()
278
- val tail = pactMethods.drop(1 )
279
- val initial = lookupPact(providerInfo, head, context)
280
- tail.fold(initial) { acc, method ->
281
- val pact = lookupPact(providerInfo, method, context)
282
-
283
- if (pact.provider != acc.provider) {
284
- // Should not really get here, as the Pacts should have been sorted by provider
285
- throw IllegalArgumentException (" You are using different Pacts with different providers for the same test" +
286
- " ('${acc.provider} ') and '${pact.provider} '). A separate test (and ideally a separate test class)" +
287
- " should be used for each provider." )
288
- }
281
+ val head = methods.first()
282
+ val tail = methods.drop(1 )
283
+ val initial = lookupPact(providerInfo, head, context)
284
+ val pact = tail.fold(initial) { acc, method ->
285
+ val pact = lookupPact(providerInfo, method, context)
286
+
287
+ if (pact.provider != acc.provider) {
288
+ // Should not really get here, as the Pacts should have been sorted by provider
289
+ throw IllegalArgumentException (" You are using different Pacts with different providers for the same test" +
290
+ " ('${acc.provider} ') and '${pact.provider} '). A separate test (and ideally a separate test class)" +
291
+ " should be used for each provider." )
292
+ }
289
293
290
- if (pact.consumer != acc.consumer) {
291
- logger.warn {
292
- " WARNING: You are using different Pacts with different consumers for the same test " +
293
- " ('${acc.consumer} ') and '${pact.consumer} '). The second consumer will be ignored and dropped from " +
294
- " the Pact and the interactions merged. If this is not your intention, you need to create a " +
295
- " separate test for each consumer."
296
- }
294
+ if (pact.consumer != acc.consumer) {
295
+ logger.warn {
296
+ " WARNING: You are using different Pacts with different consumers for the same test " +
297
+ " ('${acc.consumer} ') and '${pact.consumer} '). The second consumer will be ignored and dropped from " +
298
+ " the Pact and the interactions merged. If this is not your intention, you need to create a " +
299
+ " separate test for each consumer."
297
300
}
298
-
299
- acc.mergeInteractions(pact.interactions) as BasePact
300
301
}
302
+
303
+ acc.mergeInteractions(pact.interactions) as BasePact
301
304
}
302
305
store.put(key, pact)
303
306
pact
0 commit comments