Skip to content

Commit

Permalink
fix: JUNIT 5 - Successful test result was being published after state…
Browse files Browse the repository at this point in the history
… change method failed #1058
  • Loading branch information
Ronald Holshausen committed Apr 10, 2020
1 parent 6d88608 commit aead5fa
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<Any> = mutableListOf()
var executionContext: Map<String, Any>? = null
Expand Down Expand Up @@ -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)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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
}

}

0 comments on commit aead5fa

Please sign in to comment.