Skip to content

Commit aead5fa

Browse files
author
Ronald Holshausen
committedApr 10, 2020
fix: JUNIT 5 - Successful test result was being published after state change method failed #1058
1 parent 6d88608 commit aead5fa

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed
 

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

+4-3
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ data class PactVerificationContext @JvmOverloads constructor(
6363
var providerInfo: ProviderInfo = ProviderInfo(),
6464
val consumerName: String,
6565
val interaction: Interaction,
66-
internal var testExecutionResult: TestResult = TestResult.Ok
66+
var testExecutionResult: TestResult = TestResult.Ok
6767
) {
6868
val stateChangeHandlers: MutableList<Any> = mutableListOf()
6969
var executionContext: Map<String, Any>? = null
@@ -291,8 +291,9 @@ class PactVerificationStateChangeExtension(
291291
testContext.executionContext = mapOf("providerState" to providerStateContext)
292292
} catch (e: Exception) {
293293
logger.error(e) { "Provider state change callback failed" }
294-
testResultAccumulator.updateTestResult(pact, interaction, TestResult.Failed(description = "Provider state change callback failed",
295-
results = listOf(mapOf("exception" to e))))
294+
testContext.testExecutionResult = TestResult.Failed(description = "Provider state change callback failed",
295+
results = listOf(mapOf("exception" to e)))
296+
throw AssertionError("Provider state change callback failed", e)
296297
}
297298
}
298299

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

+3-1
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ class PactVerificationStateChangeExtensionSpec extends Specification {
113113
def context = Mock(ExtensionContext) {
114114
getStore(_) >> store
115115
getRequiredTestClass() >> TestClass
116+
getRequiredTestInstance() >> testInstance
116117
}
117118
def target = Mock(TestTarget)
118119
IProviderVerifier verifier = Mock()
@@ -128,7 +129,8 @@ class PactVerificationStateChangeExtensionSpec extends Specification {
128129
verificationExtension.beforeTestExecution(context)
129130

130131
then:
131-
1 * testResultAcc.updateTestResult(_, interaction, { it instanceof TestResult.Failed })
132+
thrown(AssertionError)
133+
verificationContext.testExecutionResult instanceof TestResult.Failed
132134
}
133135

134136
}

0 commit comments

Comments
 (0)
Please sign in to comment.