You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by or...@apache.org on 2021/01/29 13:04:50 UTC

[camel] branch master updated: (chores) camel-test-junit5: cleanups (#4957)

This is an automated email from the ASF dual-hosted git repository.

orpiske pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/master by this push:
     new 8a9c507  (chores) camel-test-junit5: cleanups (#4957)
8a9c507 is described below

commit 8a9c50749dc4dc63467179f0df28340f91c5ed1c
Author: Otavio Rodolfo Piske <or...@users.noreply.github.com>
AuthorDate: Fri Jan 29 14:04:28 2021 +0100

    (chores) camel-test-junit5: cleanups (#4957)
    
    Includes:
    - cleanup log messages
    - avoid catching Throwable because it could also catch Java Errors that shouldn't be handled
    - rename a context variable to avoid confusion with the class member one
    - use a lambda to simplify sendBody
    - remove from the method signature exceptions that are never thrown
---
 .../apache/camel/test/junit5/CamelTestSupport.java | 48 ++++++++++------------
 1 file changed, 22 insertions(+), 26 deletions(-)

diff --git a/components/camel-test-junit5/src/main/java/org/apache/camel/test/junit5/CamelTestSupport.java b/components/camel-test-junit5/src/main/java/org/apache/camel/test/junit5/CamelTestSupport.java
index fa8d4e5..16604ab 100644
--- a/components/camel-test-junit5/src/main/java/org/apache/camel/test/junit5/CamelTestSupport.java
+++ b/components/camel-test-junit5/src/main/java/org/apache/camel/test/junit5/CamelTestSupport.java
@@ -150,7 +150,7 @@ public abstract class CamelTestSupport
         if (support != null && support.isCreateCamelContextPerClass()) {
             try {
                 support.tearDownCreateCamelContextPerClass();
-            } catch (Throwable e) {
+            } catch (Exception e) {
                 // ignore
             }
         }
@@ -335,7 +335,7 @@ public abstract class CamelTestSupport
     @BeforeEach
     public void setUp() throws Exception {
         LOG.info("********************************************************************************");
-        LOG.info("Testing: " + currentTestName + "(" + getClass().getName() + ")");
+        LOG.info("Testing: {} ({})", currentTestName, getClass().getName());
         LOG.info("********************************************************************************");
 
         if (isCreateCamelContextPerClass()) {
@@ -482,7 +482,7 @@ public abstract class CamelTestSupport
         if (isUseRouteBuilder()) {
             RoutesBuilder[] builders = createRouteBuilders();
             for (RoutesBuilder builder : builders) {
-                LOG.debug("Using created route builder: " + builder);
+                LOG.debug("Using created route builder: {}", builder);
                 context.addRoutes(builder);
             }
             replaceFromEndpoints();
@@ -496,9 +496,9 @@ public abstract class CamelTestSupport
             }
         } else {
             replaceFromEndpoints();
-            LOG.debug("Using route builder from the created context: " + context);
+            LOG.debug("Using route builder from the created context: {}", context);
         }
-        LOG.debug("Routing Rules are: " + context.getRoutes());
+        LOG.debug("Routing Rules are: {}", context.getRoutes());
 
         assertValidContext(context);
     }
@@ -523,8 +523,8 @@ public abstract class CamelTestSupport
         long time = watch.taken();
 
         LOG.info("********************************************************************************");
-        LOG.info("Testing done: " + currentTestName + "(" + getClass().getName() + ")");
-        LOG.info("Took: " + TimeUtils.printDuration(time) + " (" + time + " millis)");
+        LOG.info("Testing done: {} ({})", currentTestName, getClass().getName());
+        LOG.info("Took: {} ({} millis)", TimeUtils.printDuration(time), time);
 
         // if we should dump route stats, then write that to a file
         if (isRouteCoverageEnabled()) {
@@ -672,7 +672,7 @@ public abstract class CamelTestSupport
         doStopCamelContext(context, camelContextService);
     }
 
-    private static void doStopCamelContext(CamelContext context, Service camelContextService) throws Exception {
+    private static void doStopCamelContext(CamelContext context, Service camelContextService) {
         if (camelContextService != null) {
             if (camelContextService == threadService.get()) {
                 threadService.remove();
@@ -689,8 +689,7 @@ public abstract class CamelTestSupport
     }
 
     private static void doStopTemplates(
-            ConsumerTemplate consumer, ProducerTemplate template, FluentProducerTemplate fluentTemplate)
-            throws Exception {
+            ConsumerTemplate consumer, ProducerTemplate template, FluentProducerTemplate fluentTemplate) {
         if (consumer != null) {
             if (consumer == threadConsumer.get()) {
                 threadConsumer.remove();
@@ -729,13 +728,14 @@ public abstract class CamelTestSupport
     protected CamelContext createCamelContext() throws Exception {
         Registry registry = createCamelRegistry();
 
-        CamelContext context;
+        CamelContext retContext;
         if (registry != null) {
-            context = new DefaultCamelContext(registry);
+            retContext = new DefaultCamelContext(registry);
         } else {
-            context = new DefaultCamelContext();
+            retContext = new DefaultCamelContext();
         }
-        return context;
+
+        return retContext;
     }
 
     /**
@@ -866,11 +866,9 @@ public abstract class CamelTestSupport
      * @param body        the body for the message
      */
     protected void sendBody(String endpointUri, final Object body) {
-        template.send(endpointUri, new Processor() {
-            public void process(Exchange exchange) {
-                Message in = exchange.getIn();
-                in.setBody(body);
-            }
+        template.send(endpointUri, exchange -> {
+            Message in = exchange.getIn();
+            in.setBody(body);
         });
     }
 
@@ -882,13 +880,11 @@ public abstract class CamelTestSupport
      * @param headers     any headers to set on the message
      */
     protected void sendBody(String endpointUri, final Object body, final Map<String, Object> headers) {
-        template.send(endpointUri, new Processor() {
-            public void process(Exchange exchange) {
-                Message in = exchange.getIn();
-                in.setBody(body);
-                for (Map.Entry<String, Object> entry : headers.entrySet()) {
-                    in.setHeader(entry.getKey(), entry.getValue());
-                }
+        template.send(endpointUri, exchange -> {
+            Message in = exchange.getIn();
+            in.setBody(body);
+            for (Map.Entry<String, Object> entry : headers.entrySet()) {
+                in.setHeader(entry.getKey(), entry.getValue());
             }
         });
     }