Skip to content

Commit 8bf077e

Browse files
author
Ronald Holshausen
committedMar 21, 2020
fix: corrected junit 5 tests to support injecting the mock server in a before callback
1 parent 9332e4f commit 8bf077e

File tree

4 files changed

+167
-127
lines changed

4 files changed

+167
-127
lines changed
 

‎consumer/pact-jvm-consumer-junit5/build.gradle

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ dependencies {
1111
testCompile "org.codehaus.groovy:groovy-xml:${project.groovyVersion}"
1212
testCompile 'org.apache.commons:commons-io:1.3.2'
1313
testRuntime "org.junit.vintage:junit-vintage-engine:${project.junit5Version}"
14+
testRuntime "org.junit.jupiter:junit-jupiter-engine:${project.junit5Version}"
1415
testCompile project(path: ":consumer:pact-jvm-consumer-java8", configuration: 'default')
1516
testCompile 'org.hamcrest:hamcrest:2.1'
1617
testCompile('org.spockframework:spock-core:2.0-M2-groovy-3.0') {

‎consumer/pact-jvm-consumer-junit5/src/main/kotlin/au/com/dius/pact/consumer/junit5/PactConsumerTestExt.kt

+127-116
Original file line numberDiff line numberDiff line change
@@ -135,169 +135,178 @@ class JUnit5MockServerSupport(private val baseMockServer: BaseMockServer) : Mock
135135

136136
class PactConsumerTestExt : Extension, BeforeTestExecutionCallback, BeforeAllCallback, ParameterResolver, AfterTestExecutionCallback, AfterAllCallback {
137137
override fun supportsParameter(parameterContext: ParameterContext, extensionContext: ExtensionContext): Boolean {
138-
val store = extensionContext.getStore(ExtensionContext.Namespace.create("pact-jvm"))
139-
if (store["providerInfo"] != null) {
140-
val providerInfo = store["providerInfo"] as ProviderInfo
141-
val type = parameterContext.parameter.type
142-
return when (providerInfo.providerType) {
143-
ProviderType.ASYNCH -> when {
144-
type.isAssignableFrom(List::class.java) -> true
145-
type.isAssignableFrom(MessagePact::class.java) -> true
146-
else -> false
147-
}
148-
else -> when {
149-
type.isAssignableFrom(MockServer::class.java) -> true
150-
type.isAssignableFrom(RequestResponsePact::class.java) -> true
151-
else -> false
152-
}
138+
val providerInfo = lookupProviderInfo(extensionContext).first
139+
val type = parameterContext.parameter.type
140+
return when (providerInfo.providerType) {
141+
ProviderType.ASYNCH -> when {
142+
type.isAssignableFrom(List::class.java) -> true
143+
type.isAssignableFrom(MessagePact::class.java) -> true
144+
else -> false
145+
}
146+
else -> when {
147+
type.isAssignableFrom(MockServer::class.java) -> true
148+
type.isAssignableFrom(RequestResponsePact::class.java) -> true
149+
else -> false
153150
}
154-
} else {
155-
return false
156151
}
157152
}
158153

159154
override fun resolveParameter(parameterContext: ParameterContext, extensionContext: ExtensionContext): Any {
160-
val store = extensionContext.getStore(ExtensionContext.Namespace.create("pact-jvm"))
161-
if (store["providerInfo"] != null) {
162-
val providerInfo = store["providerInfo"] as ProviderInfo
163-
val type = parameterContext.parameter.type
164-
return when (providerInfo.providerType) {
165-
ProviderType.ASYNCH -> {
166-
val pact = store["pact"] as MessagePact
167-
when {
168-
type.isAssignableFrom(List::class.java) -> pact.messages
169-
type.isAssignableFrom(MessagePact::class.java) -> pact
170-
else -> throw UnsupportedOperationException("Could not inject parameter $type into test method")
171-
}
155+
val providerInfo = lookupProviderInfo(extensionContext)
156+
val store = extensionContext.getStore(NAMESPACE)
157+
val type = parameterContext.parameter.type
158+
return when (providerInfo.first.providerType) {
159+
ProviderType.ASYNCH -> {
160+
val pact = lookupPact(providerInfo.first, providerInfo.second, extensionContext) as MessagePact
161+
when {
162+
type.isAssignableFrom(List::class.java) -> pact.messages
163+
type.isAssignableFrom(MessagePact::class.java) -> pact
164+
else -> throw UnsupportedOperationException("Could not inject parameter $type into test method")
172165
}
173-
else -> {
174-
val pact = store["pact"] as RequestResponsePact
175-
when {
176-
type.isAssignableFrom(MockServer::class.java) -> store["mockServer"]
177-
type.isAssignableFrom(RequestResponsePact::class.java) -> pact
178-
else -> throw UnsupportedOperationException("Could not inject parameter $type into test method")
179-
}
166+
}
167+
else -> {
168+
when {
169+
type.isAssignableFrom(MockServer::class.java) -> setupMockServer(providerInfo.first, providerInfo.second, extensionContext)!!
170+
type.isAssignableFrom(RequestResponsePact::class.java) -> store["pact"] as RequestResponsePact
171+
else -> throw UnsupportedOperationException("Could not inject parameter $type into test method")
180172
}
181173
}
182-
} else {
183-
return false
184174
}
185175
}
186176

187177
override fun beforeAll(context: ExtensionContext) {
188-
val store = context.getStore(ExtensionContext.Namespace.create("pact-jvm"))
178+
val store = context.getStore(NAMESPACE)
189179
store.put("executedFragments", mutableListOf<Method>())
190180
}
191181

192182
override fun beforeTestExecution(context: ExtensionContext) {
193183
val (providerInfo, pactMethod) = lookupProviderInfo(context)
194-
195184
logger.debug { "providerInfo = $providerInfo" }
196185

197-
val store = context.getStore(ExtensionContext.Namespace.create("pact-jvm"))
198-
val executedFragments = store["executedFragments"] as MutableList<Method>
199-
val pact = lookupPact(providerInfo, pactMethod, context, executedFragments)
200-
store.put("pact", pact)
201-
store.put("providerInfo", providerInfo)
186+
setupMockServer(providerInfo, pactMethod, context)
187+
}
202188

203-
if (providerInfo.providerType != ProviderType.ASYNCH) {
189+
private fun setupMockServer(providerInfo: ProviderInfo, pactMethod: String, context: ExtensionContext): MockServer? {
190+
val store = context.getStore(NAMESPACE)
191+
return if (providerInfo.providerType != ProviderType.ASYNCH && store["mockServer"] == null) {
204192
val config = providerInfo.mockServerConfig()
205193
store.put("mockServerConfig", config)
206-
val mockServer = mockServer(pact as RequestResponsePact, config) as BaseMockServer
194+
val mockServer = mockServer(lookupPact(providerInfo, pactMethod, context) as RequestResponsePact, config) as BaseMockServer
207195
mockServer.start()
208196
mockServer.waitForServer()
209197
store.put("mockServer", JUnit5MockServerSupport(mockServer))
198+
mockServer
199+
} else {
200+
store["mockServer"] as MockServer?
210201
}
211202
}
212203

213204
fun lookupProviderInfo(context: ExtensionContext): Pair<ProviderInfo, String> {
214-
val methodAnnotation = if (AnnotationSupport.isAnnotated(context.requiredTestMethod, PactTestFor::class.java)) {
215-
logger.debug { "Found @PactTestFor annotation on test method" }
216-
val annotation = AnnotationSupport.findAnnotation(context.requiredTestMethod, PactTestFor::class.java).get()
217-
ProviderInfo.fromAnnotation(annotation) to annotation.pactMethod
205+
val store = context.getStore(NAMESPACE)
206+
return if (store["providerInfo"] != null) {
207+
(store["providerInfo"] as ProviderInfo) to store["pactMethod"].toString()
218208
} else {
219-
null
220-
}
209+
val methodAnnotation = if (AnnotationSupport.isAnnotated(context.requiredTestMethod, PactTestFor::class.java)) {
210+
logger.debug { "Found @PactTestFor annotation on test method" }
211+
val annotation = AnnotationSupport.findAnnotation(context.requiredTestMethod, PactTestFor::class.java).get()
212+
ProviderInfo.fromAnnotation(annotation) to annotation.pactMethod
213+
} else {
214+
null
215+
}
221216

222-
val classAnnotation = if (AnnotationSupport.isAnnotated(context.requiredTestClass, PactTestFor::class.java)) {
223-
logger.debug { "Found @PactTestFor annotation on test class" }
224-
val annotation = AnnotationSupport.findAnnotation(context.requiredTestClass, PactTestFor::class.java).get()
225-
ProviderInfo.fromAnnotation(annotation) to annotation.pactMethod
226-
} else {
227-
null
228-
}
217+
val classAnnotation = if (AnnotationSupport.isAnnotated(context.requiredTestClass, PactTestFor::class.java)) {
218+
logger.debug { "Found @PactTestFor annotation on test class" }
219+
val annotation = AnnotationSupport.findAnnotation(context.requiredTestClass, PactTestFor::class.java).get()
220+
ProviderInfo.fromAnnotation(annotation) to annotation.pactMethod
221+
} else {
222+
null
223+
}
229224

230-
return when {
231-
classAnnotation != null && methodAnnotation != null -> Pair(methodAnnotation.first.merge(classAnnotation.first),
232-
if (methodAnnotation.second.isNotEmpty()) methodAnnotation.second else classAnnotation.second)
233-
classAnnotation != null -> classAnnotation
234-
methodAnnotation != null -> methodAnnotation
235-
else -> {
236-
logger.debug { "No @PactTestFor annotation found on test class, using defaults" }
237-
ProviderInfo() to ""
225+
val providerInfo = when {
226+
classAnnotation != null && methodAnnotation != null -> Pair(methodAnnotation.first.merge(classAnnotation.first),
227+
if (methodAnnotation.second.isNotEmpty()) methodAnnotation.second else classAnnotation.second)
228+
classAnnotation != null -> classAnnotation
229+
methodAnnotation != null -> methodAnnotation
230+
else -> {
231+
logger.debug { "No @PactTestFor annotation found on test class, using defaults" }
232+
ProviderInfo() to ""
233+
}
238234
}
235+
236+
store.put("providerInfo", providerInfo.first)
237+
store.put("pactMethod", providerInfo.second)
238+
239+
providerInfo
239240
}
240241
}
241242

242243
fun lookupPact(
243244
providerInfo: ProviderInfo,
244245
pactMethod: String,
245-
context: ExtensionContext,
246-
executedFragments: MutableList<Method>
246+
context: ExtensionContext
247247
): BasePact<out Interaction> {
248-
val providerName = if (providerInfo.providerName.isEmpty()) "default" else providerInfo.providerName
249-
val methods = AnnotationSupport.findAnnotatedMethods(context.requiredTestClass, Pact::class.java,
250-
HierarchyTraversalMode.TOP_DOWN)
251-
252-
val method = when {
253-
pactMethod.isNotEmpty() -> {
254-
logger.debug { "Looking for @Pact method named '$pactMethod' for provider '$providerName'" }
255-
methods.firstOrNull { it.name == pactMethod }
256-
}
257-
providerInfo.providerName.isEmpty() -> {
258-
logger.debug { "Looking for first @Pact method" }
259-
methods.firstOrNull()
260-
}
261-
else -> {
262-
logger.debug { "Looking for first @Pact method for provider '$providerName'" }
263-
methods.firstOrNull {
264-
val annotationProviderName = AnnotationSupport.findAnnotation(it, Pact::class.java).get().provider
265-
annotationProviderName.isEmpty() || annotationProviderName == providerInfo.providerName
248+
val store = context.getStore(NAMESPACE)
249+
if (store["pact"] == null) {
250+
val providerName = if (providerInfo.providerName.isEmpty()) "default" else providerInfo.providerName
251+
val methods = AnnotationSupport.findAnnotatedMethods(context.requiredTestClass, Pact::class.java,
252+
HierarchyTraversalMode.TOP_DOWN)
253+
254+
val method = when {
255+
pactMethod.isNotEmpty() -> {
256+
logger.debug { "Looking for @Pact method named '$pactMethod' for provider '$providerName'" }
257+
methods.firstOrNull { it.name == pactMethod }
258+
}
259+
providerInfo.providerName.isEmpty() -> {
260+
logger.debug { "Looking for first @Pact method" }
261+
methods.firstOrNull()
262+
}
263+
else -> {
264+
logger.debug { "Looking for first @Pact method for provider '$providerName'" }
265+
methods.firstOrNull {
266+
val annotationProviderName = AnnotationSupport.findAnnotation(it, Pact::class.java).get().provider
267+
annotationProviderName.isEmpty() || annotationProviderName == providerInfo.providerName
268+
}
266269
}
267270
}
268-
}
269271

270-
val providerType = providerInfo.providerType ?: ProviderType.SYNCH
271-
if (method == null) {
272-
throw UnsupportedOperationException("No method annotated with @Pact was found on test class " +
273-
context.requiredTestClass.simpleName + " for provider '${providerInfo.providerName}'")
274-
} else if (providerType == ProviderType.SYNCH && !JUnitTestSupport.conformsToSignature(method)) {
275-
throw UnsupportedOperationException("Method ${method.name} does not conform to required method signature " +
276-
"'public RequestResponsePact xxx(PactDslWithProvider builder)'")
277-
} else if (providerType == ProviderType.ASYNCH && !JUnitTestSupport.conformsToMessagePactSignature(method)) {
278-
throw UnsupportedOperationException("Method ${method.name} does not conform to required method signature " +
279-
"'public MessagePact xxx(MessagePactBuilder builder)'")
280-
}
272+
val providerType = providerInfo.providerType ?: ProviderType.SYNCH
273+
if (method == null) {
274+
throw UnsupportedOperationException("No method annotated with @Pact was found on test class " +
275+
context.requiredTestClass.simpleName + " for provider '${providerInfo.providerName}'")
276+
} else if (providerType == ProviderType.SYNCH && !JUnitTestSupport.conformsToSignature(method)) {
277+
throw UnsupportedOperationException("Method ${method.name} does not conform to required method signature " +
278+
"'public RequestResponsePact xxx(PactDslWithProvider builder)'")
279+
} else if (providerType == ProviderType.ASYNCH && !JUnitTestSupport.conformsToMessagePactSignature(method)) {
280+
throw UnsupportedOperationException("Method ${method.name} does not conform to required method signature " +
281+
"'public MessagePact xxx(MessagePactBuilder builder)'")
282+
}
281283

282-
val pactAnnotation = AnnotationSupport.findAnnotation(method, Pact::class.java).get()
283-
logger.debug { "Invoking method '${method.name}' to get Pact for the test " +
284-
"'${context.testMethod.map { it.name }.orElse("unknown")}'" }
285-
286-
val provider = parseExpression(pactAnnotation.provider).toString()
287-
val providerNameToUse = if (provider.isNotEmpty()) provider else providerName
288-
val pact = when (providerType) {
289-
ProviderType.SYNCH, ProviderType.UNSPECIFIED -> ReflectionSupport.invokeMethod(method, context.requiredTestInstance,
290-
ConsumerPactBuilder.consumer(pactAnnotation.consumer).hasPactWith(providerNameToUse)) as BasePact<*>
291-
ProviderType.ASYNCH -> ReflectionSupport.invokeMethod(method, context.requiredTestInstance,
292-
MessagePactBuilder.consumer(pactAnnotation.consumer).hasPactWith(providerNameToUse)) as BasePact<*>
284+
val pactAnnotation = AnnotationSupport.findAnnotation(method, Pact::class.java).get()
285+
logger.debug {
286+
"Invoking method '${method.name}' to get Pact for the test " +
287+
"'${context.testMethod.map { it.name }.orElse("unknown")}'"
288+
}
289+
290+
val provider = parseExpression(pactAnnotation.provider).toString()
291+
val providerNameToUse = if (provider.isNotEmpty()) provider else providerName
292+
val pact = when (providerType) {
293+
ProviderType.SYNCH, ProviderType.UNSPECIFIED -> ReflectionSupport.invokeMethod(method, context.requiredTestInstance,
294+
ConsumerPactBuilder.consumer(pactAnnotation.consumer).hasPactWith(providerNameToUse)) as BasePact<*>
295+
ProviderType.ASYNCH -> ReflectionSupport.invokeMethod(method, context.requiredTestInstance,
296+
MessagePactBuilder.consumer(pactAnnotation.consumer).hasPactWith(providerNameToUse)) as BasePact<*>
297+
}
298+
val executedFragments = store["executedFragments"] as MutableList<Method>
299+
executedFragments.add(method)
300+
store.put("pact", pact)
301+
return pact
302+
} else {
303+
return store["pact"] as BasePact<out Interaction>
293304
}
294-
executedFragments.add(method)
295-
return pact
296305
}
297306

298307
override fun afterTestExecution(context: ExtensionContext) {
299308
if (!context.executionException.isPresent) {
300-
val store = context.getStore(ExtensionContext.Namespace.create("pact-jvm"))
309+
val store = context.getStore(NAMESPACE)
301310
val providerInfo = store["providerInfo"] as ProviderInfo
302311
val pactDirectory = lookupPactDirectory(context)
303312
if (providerInfo.providerType != ProviderType.ASYNCH) {
@@ -338,7 +347,7 @@ class PactConsumerTestExt : Extension, BeforeTestExecutionCallback, BeforeAllCal
338347

339348
override fun afterAll(context: ExtensionContext) {
340349
if (!context.executionException.isPresent) {
341-
val store = context.getStore(ExtensionContext.Namespace.create("pact-jvm"))
350+
val store = context.getStore(NAMESPACE)
342351
val executedFragments = store["executedFragments"] as MutableList<Method>
343352
val methods = AnnotationSupport.findAnnotatedMethods(context.requiredTestClass, Pact::class.java,
344353
HierarchyTraversalMode.TOP_DOWN)
@@ -355,5 +364,7 @@ class PactConsumerTestExt : Extension, BeforeTestExecutionCallback, BeforeAllCal
355364
}
356365
}
357366

358-
companion object : KLogging()
367+
companion object : KLogging() {
368+
val NAMESPACE = ExtensionContext.Namespace.create("pact-jvm")
369+
}
359370
}

‎consumer/pact-jvm-consumer-junit5/src/test/groovy/au/com/dius/pact/consumer/junit5/PactConsumerTestExtTest.groovy

+32-11
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import au.com.dius.pact.core.model.PactSpecVersion
77
import au.com.dius.pact.core.model.Provider
88
import au.com.dius.pact.core.model.RequestResponsePact
99
import org.hamcrest.Matchers
10+
import org.junit.jupiter.api.BeforeEach
1011
import org.junit.jupiter.api.DisplayName
1112
import org.junit.jupiter.api.Test
1213
import org.junit.jupiter.api.extension.ExtensionContext
@@ -20,6 +21,20 @@ class PactConsumerTestExtTest {
2021
private providerInfo = new ProviderInfo()
2122
private pact = new RequestResponsePact(new Provider('junit5_provider'),
2223
new Consumer('junit5_consumer'), [])
24+
private ExtensionContext.Store mockStore
25+
26+
@BeforeEach
27+
void setup() {
28+
mockStore = [
29+
'get': { param ->
30+
switch (param) {
31+
case 'executedFragments': []; break
32+
default: null
33+
}
34+
},
35+
'put': { param, value -> }
36+
] as ExtensionContext.Store
37+
}
2338

2439
class TestClassInvalidSignature {
2540
@Pact(provider = 'junit5_provider', consumer = 'junit5_consumer')
@@ -80,7 +95,7 @@ class PactConsumerTestExtTest {
8095
void test1() {
8196
assertThrows(UnsupportedOperationException) {
8297
def context = ['getTestClass': { Optional.of(PactConsumerTestExtTest) } ] as ExtensionContext
83-
subject.lookupPact(providerInfo, '', context, [])
98+
subject.lookupPact(providerInfo, '', context)
8499
}
85100
}
86101

@@ -89,7 +104,7 @@ class PactConsumerTestExtTest {
89104
void test2() {
90105
assertThrows(UnsupportedOperationException) {
91106
def context = ['getTestClass': { Optional.of(PactConsumerTestExtTest) } ] as ExtensionContext
92-
subject.lookupPact(providerInfo, 'test', context, [])
107+
subject.lookupPact(providerInfo, 'test', context)
93108
}
94109
}
95110

@@ -98,7 +113,7 @@ class PactConsumerTestExtTest {
98113
void test3() {
99114
assertThrows(UnsupportedOperationException) {
100115
def context = ['getTestClass': { Optional.of(TestClassInvalidSignature) } ] as ExtensionContext
101-
subject.lookupPact(providerInfo, 'pactMethod', context, [])
116+
subject.lookupPact(providerInfo, 'pactMethod', context)
102117
}
103118
}
104119

@@ -107,7 +122,7 @@ class PactConsumerTestExtTest {
107122
void test4() {
108123
assertThrows(UnsupportedOperationException) {
109124
def context = ['getTestClass': { Optional.of(TestClass) } ] as ExtensionContext
110-
subject.lookupPact(providerInfo, 'pactMethod', context, [])
125+
subject.lookupPact(providerInfo, 'pactMethod', context)
111126
}
112127
}
113128

@@ -117,10 +132,11 @@ class PactConsumerTestExtTest {
117132
def context = [
118133
'getTestClass': { Optional.of(TestClass) },
119134
'getTestInstance': { Optional.of(new TestClass()) },
120-
'getTestMethod': { Optional.empty() }
135+
'getTestMethod': { Optional.empty() },
136+
'getStore': { mockStore }
121137
] as ExtensionContext
122138
def pact = subject.lookupPact(new ProviderInfo('junit5_provider', 'localhost', '8080',
123-
PactSpecVersion.V3, ProviderType.SYNCH), 'pactMethod', context, [])
139+
PactSpecVersion.V3, ProviderType.SYNCH), 'pactMethod', context)
124140
assertThat(pact, Matchers.is(this.pact))
125141
}
126142

@@ -131,7 +147,8 @@ class PactConsumerTestExtTest {
131147
def context = [
132148
'getTestClass': { Optional.of(TestClass) },
133149
'getTestInstance': { Optional.of(instance) },
134-
'getTestMethod': { Optional.of(TestClass.methods.find { it.name == 'pactMethod' }) }
150+
'getTestMethod': { Optional.of(TestClass.methods.find { it.name == 'pactMethod' }) },
151+
'getStore': { mockStore }
135152
] as ExtensionContext
136153
def providerInfo = subject.lookupProviderInfo(context)
137154
assertThat(providerInfo.first.providerName, Matchers.is(''))
@@ -148,7 +165,8 @@ class PactConsumerTestExtTest {
148165
def context = [
149166
'getTestClass': { Optional.of(TestClassWithClassLevelAnnotation) },
150167
'getTestInstance': { Optional.of(instance) },
151-
'getTestMethod': { Optional.of(TestClassWithClassLevelAnnotation.methods.find { it.name == 'pactMethod' }) }
168+
'getTestMethod': { Optional.of(TestClassWithClassLevelAnnotation.methods.find { it.name == 'pactMethod' }) },
169+
'getStore': { mockStore }
152170
] as ExtensionContext
153171
def providerInfo = subject.lookupProviderInfo(context)
154172
assertThat(providerInfo.first.providerName, Matchers.is('TestClassWithClassLevelAnnotation'))
@@ -165,7 +183,8 @@ class PactConsumerTestExtTest {
165183
def context = [
166184
'getTestClass': { Optional.of(TestClassWithMethodLevelAnnotation) },
167185
'getTestInstance': { Optional.of(instance) },
168-
'getTestMethod': { Optional.of(TestClassWithMethodLevelAnnotation.methods.find { it.name == 'pactMethod' }) }
186+
'getTestMethod': { Optional.of(TestClassWithMethodLevelAnnotation.methods.find { it.name == 'pactMethod' }) },
187+
'getStore': { mockStore }
169188
] as ExtensionContext
170189
def providerInfo = subject.lookupProviderInfo(context)
171190
assertThat(providerInfo.first.providerName, Matchers.is('TestClassWithMethodLevelAnnotation'))
@@ -184,7 +203,8 @@ class PactConsumerTestExtTest {
184203
'getTestInstance': { Optional.of(instance) },
185204
'getTestMethod': {
186205
Optional.of(TestClassWithMethodAndClassLevelAnnotation.methods.find { it.name == 'pactMethod' })
187-
}
206+
},
207+
'getStore': { mockStore }
188208
] as ExtensionContext
189209
def providerInfo = subject.lookupProviderInfo(context)
190210
assertThat(providerInfo.first.providerName, Matchers.is('TestClassWithMethodAndClassLevelAnnotation'))
@@ -203,7 +223,8 @@ class PactConsumerTestExtTest {
203223
'getTestInstance': { Optional.of(instance) },
204224
'getTestMethod': {
205225
Optional.of(TestClassWithMethodAndClassLevelAnnotation2.methods.find { it.name == 'pactMethod' })
206-
}
226+
},
227+
'getStore': { mockStore }
207228
] as ExtensionContext
208229
def providerInfo = subject.lookupProviderInfo(context)
209230
assertThat(providerInfo.first.pactVersion, Matchers.is(PactSpecVersion.V3))

‎consumer/pact-jvm-consumer-junit5/src/test/java/au/com/dius/pact/consumer/junit5/ArticlesTest.java

+7
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import org.apache.commons.io.IOUtils;
1010
import org.apache.http.HttpResponse;
1111
import org.apache.http.client.fluent.Request;
12+
import org.junit.jupiter.api.BeforeEach;
1213
import org.junit.jupiter.api.Test;
1314
import org.junit.jupiter.api.extension.ExtendWith;
1415

@@ -19,6 +20,7 @@
1920
import static org.hamcrest.MatcherAssert.assertThat;
2021
import static org.hamcrest.Matchers.equalTo;
2122
import static org.hamcrest.Matchers.is;
23+
import static org.hamcrest.Matchers.notNullValue;
2224

2325
@ExtendWith(PactConsumerTestExt.class)
2426
@PactTestFor(providerName = "ArticlesProvider", port = "1234")
@@ -27,6 +29,11 @@ public class ArticlesTest {
2729
"Content-Type", "application/json"
2830
});
2931

32+
@BeforeEach
33+
public void setUp(MockServer mockServer) {
34+
assertThat(mockServer, is(notNullValue()));
35+
}
36+
3037
@Pact(consumer = "ArticlesConsumer")
3138
public RequestResponsePact articles(PactDslWithProvider builder) {
3239
return builder

0 commit comments

Comments
 (0)
Please sign in to comment.