Skip to content

Commit fc6fe46

Browse files
author
Ronald Holshausen
committedFeb 9, 2020
fix: JUnit 5 test provider now throws an exception if there are no Pacts to verify #1007
1 parent 913bcf3 commit fc6fe46

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed
 

‎provider/pact-jvm-provider-junit5/src/main/kotlin/au/com/dius/pact/provider/junit5/PactJUnit5VerificationProvider.kt

+5
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,11 @@ class PactVerificationInvocationContextProvider : TestTemplateInvocationContextP
380380
val tests = pactSources.flatMap { pact ->
381381
pact.first.interactions.map { PactVerificationExtension(pact.first, pact.second, it, serviceName, consumerName) }
382382
}
383+
384+
if (tests.isEmpty()) {
385+
throw UnsupportedOperationException("No Pact files where found to verify")
386+
}
387+
383388
return tests.stream() as Stream<TestTemplateInvocationContext>
384389
}
385390

‎provider/pact-jvm-provider-junit5/src/test/groovy/au/com/dius/pact/provider/junit5/PactVerificationInvocationContextProviderSpec.groovy

+22
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package au.com.dius.pact.provider.junit5
22

33
import au.com.dius.pact.core.model.Pact
4+
import au.com.dius.pact.provider.junit.Consumer
45
import au.com.dius.pact.provider.junit.Provider
56
import au.com.dius.pact.provider.junit.State
67
import au.com.dius.pact.provider.junit.loader.PactFilter
@@ -11,6 +12,7 @@ import au.com.dius.pact.provider.junit.loader.PactSource
1112
import au.com.dius.pact.provider.junit.target.Target
1213
import au.com.dius.pact.provider.junit.target.TestTarget
1314
import org.junit.jupiter.api.extension.ExtensionContext
15+
import spock.lang.Issue
1416
import spock.lang.Specification
1517
import spock.lang.Unroll
1618

@@ -30,6 +32,14 @@ class PactVerificationInvocationContextProviderSpec extends Specification {
3032

3133
}
3234

35+
@Provider('myAwesomeService')
36+
@Consumer('doesNotExist')
37+
@PactFolder('pacts')
38+
static class TestClassWithNoPacts {
39+
@TestTarget
40+
Target target
41+
}
42+
3343
static class InvalidStateChangeTestClass {
3444

3545
@State('one')
@@ -148,6 +158,18 @@ class PactVerificationInvocationContextProviderSpec extends Specification {
148158
extensions.count() == 1
149159
}
150160

161+
@Issue('#1007')
162+
def 'provideTestTemplateInvocationContexts throws an exception if there are no pacts to verify'() {
163+
when:
164+
provider.provideTestTemplateInvocationContexts(['getTestClass': {
165+
Optional.of(TestClassWithNoPacts)
166+
} ] as ExtensionContext)
167+
168+
then:
169+
def exp = thrown(UnsupportedOperationException)
170+
exp.message == 'No Pact files where found to verify'
171+
}
172+
151173
@Unroll
152174
def 'throws an exception if there are invalid state change methods'() {
153175
when:

0 commit comments

Comments
 (0)
Please sign in to comment.