You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by "orpiske (via GitHub)" <gi...@apache.org> on 2024/07/02 16:59:52 UTC

Re: [PR] Avoid NPE on Camel Tests [camel]

orpiske commented on code in PR #14641:
URL: https://github.com/apache/camel/pull/14641#discussion_r1654756707


##########
components/camel-test/camel-test-junit5/src/main/java/org/apache/camel/test/junit5/CamelTestSupport.java:
##########
@@ -144,15 +145,16 @@ public void beforeAll(ExtensionContext context) {
             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(Objects.nonNull(contextManager)) {
+            contextManager.stop();
+        }

Review Comment:
   Just do it like I did on my other PR. 



##########
components/camel-test/camel-test-junit5/src/main/java/org/apache/camel/test/junit5/CamelTestSupport.java:
##########
@@ -144,15 +145,16 @@ public void beforeAll(ExtensionContext context) {
             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(Objects.nonNull(contextManager)) {
+            contextManager.stop();
+        }

Review Comment:
   For instance:
   ```
    if (contextManager != null) {
               // It may be null in some occasion, such as when failing to initialize the context
               contextManager.stop();
           }
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org