From 38461d04b2e3c0b2fe1911f89880af66f6fdc6dd Mon Sep 17 00:00:00 2001 From: Guillaume Smet Date: Mon, 9 Oct 2023 15:32:04 +0200 Subject: [PATCH] Reset test status on success and set the exception on abort Fixes #36250 --- ...stractQuarkusTestWithContextExtension.java | 24 +++++++++++++++++++ .../test/junit/QuarkusTestExtensionState.java | 8 +++++++ 2 files changed, 32 insertions(+) diff --git a/test-framework/junit5/src/main/java/io/quarkus/test/junit/AbstractQuarkusTestWithContextExtension.java b/test-framework/junit5/src/main/java/io/quarkus/test/junit/AbstractQuarkusTestWithContextExtension.java index 68b1b601ed90c..84cd277f333b4 100644 --- a/test-framework/junit5/src/main/java/io/quarkus/test/junit/AbstractQuarkusTestWithContextExtension.java +++ b/test-framework/junit5/src/main/java/io/quarkus/test/junit/AbstractQuarkusTestWithContextExtension.java @@ -52,6 +52,16 @@ public void testFailed(ExtensionContext context, Throwable cause) { markTestAsFailed(context, cause); } + @Override + public void testSuccessful(ExtensionContext context) { + markTestAsSuccessful(context); + } + + @Override + public void testAborted(ExtensionContext context, Throwable cause) { + markTestAsAborted(context, cause); + } + protected QuarkusTestExtensionState getState(ExtensionContext context) { ExtensionContext.Store store = getStoreFromContext(context); QuarkusTestExtensionState state = store.get(QuarkusTestExtensionState.class.getName(), QuarkusTestExtensionState.class); @@ -92,4 +102,18 @@ protected void markTestAsFailed(ExtensionContext context, Throwable throwable) { state.setTestFailed(throwable); } } + + protected void markTestAsSuccessful(ExtensionContext context) { + QuarkusTestExtensionState state = getState(context); + if (state != null) { + state.setTestSuccessful(); + } + } + + protected void markTestAsAborted(ExtensionContext context, Throwable throwable) { + QuarkusTestExtensionState state = getState(context); + if (state != null) { + state.setTestAborted(throwable); + } + } } diff --git a/test-framework/junit5/src/main/java/io/quarkus/test/junit/QuarkusTestExtensionState.java b/test-framework/junit5/src/main/java/io/quarkus/test/junit/QuarkusTestExtensionState.java index 6024cb50f400c..d1dd44eff7d3c 100644 --- a/test-framework/junit5/src/main/java/io/quarkus/test/junit/QuarkusTestExtensionState.java +++ b/test-framework/junit5/src/main/java/io/quarkus/test/junit/QuarkusTestExtensionState.java @@ -49,6 +49,14 @@ public void close() throws IOException { } } + protected void setTestSuccessful() { + setTestFailed(null); + } + + protected void setTestAborted(Throwable failure) { + setTestFailed(failure); + } + protected void setTestFailed(Throwable failure) { try { this.testErrorCause = failure;