This is an automated email from the ASF dual-hosted git repository. orpiske pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/main by this push: new fc3c098e768 CAMEL-20838: Avoid NPE on Camel Tests (#14641) fc3c098e768 is described below commit fc3c098e7683a5b20072208757b18eda169b544b Author: Marco Santarelli <santa...@users.noreply.github.com> AuthorDate: Thu Jun 27 07:44:23 2024 +0200 CAMEL-20838: Avoid NPE on Camel Tests (#14641) * CAMEL-20838: Ensure camel context is created before tests are run also for transient context. * CAMEL-20838: Set legacy contextManager in store only if created in beforeAll * CAMEL-20838: Revert unwanted changes * CAMEL-20838: use != for null-check --- .../java/org/apache/camel/test/junit5/CamelTestSupport.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/components/camel-test/camel-test-junit5/src/main/java/org/apache/camel/test/junit5/CamelTestSupport.java b/components/camel-test/camel-test-junit5/src/main/java/org/apache/camel/test/junit5/CamelTestSupport.java index ec4c7335369..629c35e4599 100644 --- a/components/camel-test/camel-test-junit5/src/main/java/org/apache/camel/test/junit5/CamelTestSupport.java +++ b/components/camel-test/camel-test-junit5/src/main/java/org/apache/camel/test/junit5/CamelTestSupport.java @@ -144,15 +144,17 @@ public abstract class CamelTestSupport extends AbstractTestSupport testConfigurationBuilder.withCreateCamelContextPerClass(perClassPresent); contextManager = contextManagerFactory.createContextManager(ContextManagerFactory.Type.BEFORE_ALL, testConfigurationBuilder, camelContextConfiguration); + ExtensionContext.Store globalStore = context.getStore(ExtensionContext.Namespace.GLOBAL); + contextManager.setGlobalStore(globalStore); } - - ExtensionContext.Store globalStore = context.getStore(ExtensionContext.Namespace.GLOBAL); - contextManager.setGlobalStore(globalStore); } @Override public void afterAll(ExtensionContext context) { - contextManager.stop(); + if (contextManager != null) { + // It may be null in some occasion, such as when failing to initialize the context + contextManager.stop(); + } } /** @@ -339,7 +341,6 @@ public abstract class CamelTestSupport extends AbstractTestSupport @Deprecated(since = "4.7.0") protected void stopCamelContext() throws Exception { contextManager.stopCamelContext(); - } @Deprecated(since = "4.7.0")