From aead5fa0e679249d80d3267bfede7a77d57ca11e Mon Sep 17 00:00:00 2001 From: Ronald Holshausen Date: Fri, 10 Apr 2020 12:28:09 +1000 Subject: [PATCH] fix: JUNIT 5 - Successful test result was being published after state change method failed #1058 --- .../pact/provider/junit5/PactJUnit5VerificationProvider.kt | 7 ++++--- .../junit5/PactVerificationStateChangeExtensionSpec.groovy | 4 +++- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/provider/pact-jvm-provider-junit5/src/main/kotlin/au/com/dius/pact/provider/junit5/PactJUnit5VerificationProvider.kt b/provider/pact-jvm-provider-junit5/src/main/kotlin/au/com/dius/pact/provider/junit5/PactJUnit5VerificationProvider.kt index ac507e49da..1d69d45083 100644 --- a/provider/pact-jvm-provider-junit5/src/main/kotlin/au/com/dius/pact/provider/junit5/PactJUnit5VerificationProvider.kt +++ b/provider/pact-jvm-provider-junit5/src/main/kotlin/au/com/dius/pact/provider/junit5/PactJUnit5VerificationProvider.kt @@ -63,7 +63,7 @@ data class PactVerificationContext @JvmOverloads constructor( var providerInfo: ProviderInfo = ProviderInfo(), val consumerName: String, val interaction: Interaction, - internal var testExecutionResult: TestResult = TestResult.Ok + var testExecutionResult: TestResult = TestResult.Ok ) { val stateChangeHandlers: MutableList = mutableListOf() var executionContext: Map? = null @@ -291,8 +291,9 @@ class PactVerificationStateChangeExtension( testContext.executionContext = mapOf("providerState" to providerStateContext) } catch (e: Exception) { logger.error(e) { "Provider state change callback failed" } - testResultAccumulator.updateTestResult(pact, interaction, TestResult.Failed(description = "Provider state change callback failed", - results = listOf(mapOf("exception" to e)))) + testContext.testExecutionResult = TestResult.Failed(description = "Provider state change callback failed", + results = listOf(mapOf("exception" to e))) + throw AssertionError("Provider state change callback failed", e) } } diff --git a/provider/pact-jvm-provider-junit5/src/test/groovy/au/com/dius/pact/provider/junit5/PactVerificationStateChangeExtensionSpec.groovy b/provider/pact-jvm-provider-junit5/src/test/groovy/au/com/dius/pact/provider/junit5/PactVerificationStateChangeExtensionSpec.groovy index 75d0d6e4d4..07e5a4d802 100644 --- a/provider/pact-jvm-provider-junit5/src/test/groovy/au/com/dius/pact/provider/junit5/PactVerificationStateChangeExtensionSpec.groovy +++ b/provider/pact-jvm-provider-junit5/src/test/groovy/au/com/dius/pact/provider/junit5/PactVerificationStateChangeExtensionSpec.groovy @@ -113,6 +113,7 @@ class PactVerificationStateChangeExtensionSpec extends Specification { def context = Mock(ExtensionContext) { getStore(_) >> store getRequiredTestClass() >> TestClass + getRequiredTestInstance() >> testInstance } def target = Mock(TestTarget) IProviderVerifier verifier = Mock() @@ -128,7 +129,8 @@ class PactVerificationStateChangeExtensionSpec extends Specification { verificationExtension.beforeTestExecution(context) then: - 1 * testResultAcc.updateTestResult(_, interaction, { it instanceof TestResult.Failed }) + thrown(AssertionError) + verificationContext.testExecutionResult instanceof TestResult.Failed } }