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

commit 6d5fa67ebe9f0fde78d4e14b32053ec2e502b2a3
Author: Otavio Rodolfo Piske <angusyo...@gmail.com>
AuthorDate: Mon Apr 22 13:32:51 2024 +0200

    (chores) camel-core: fix incorrect test without assertions
---
 .../org/apache/camel/impl/RouteNoOutputTest.java   | 23 +++++++++++++---------
 .../CreateRouteWithNonExistingEndpointTest.java    | 10 ++++++----
 ...RouteWithConstantFieldFromExchangeFailTest.java | 11 ++++++-----
 3 files changed, 26 insertions(+), 18 deletions(-)

diff --git 
a/core/camel-core/src/test/java/org/apache/camel/impl/RouteNoOutputTest.java 
b/core/camel-core/src/test/java/org/apache/camel/impl/RouteNoOutputTest.java
index 2a6e7d47586..5163b71c6b1 100644
--- a/core/camel-core/src/test/java/org/apache/camel/impl/RouteNoOutputTest.java
+++ b/core/camel-core/src/test/java/org/apache/camel/impl/RouteNoOutputTest.java
@@ -19,31 +19,36 @@ package org.apache.camel.impl;
 import org.apache.camel.ContextTestSupport;
 import org.apache.camel.FailedToCreateRouteException;
 import org.apache.camel.builder.RouteBuilder;
+import org.junit.jupiter.api.Assertions;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
 
-import static org.junit.jupiter.api.Assertions.assertThrows;
 import static org.junit.jupiter.api.Assertions.assertTrue;
 
 public class RouteNoOutputTest extends ContextTestSupport {
+    private Exception exception;
 
     @Override
     @BeforeEach
     public void setUp() {
+        try {
+            super.setUp();
+        } catch (Exception e) {
+            exception = e;
+        }
 
-        Exception e = assertThrows(Exception.class, super::setUp,
-                "Should have thrown exception");
 
-        FailedToCreateRouteException failed = 
assertIsInstanceOf(FailedToCreateRouteException.class, e);
-        assertTrue(failed.getRouteId().matches("route[0-9]+"));
-        assertIsInstanceOf(IllegalArgumentException.class, e.getCause());
-        assertTrue(e.getCause().getMessage().matches(
-                "Route route[0-9]+\\Q has no output processors. You need to 
add outputs to the route such as to(\"log:foo\").\\E"));
     }
 
     @Test
     public void testDummy() {
-        // noop
+        Assertions.assertNotNull(exception, "Should have thrown exception");
+
+        FailedToCreateRouteException failed = 
assertIsInstanceOf(FailedToCreateRouteException.class, exception);
+        assertTrue(failed.getRouteId().matches("route[0-9]+"));
+        assertIsInstanceOf(IllegalArgumentException.class, 
exception.getCause());
+        assertTrue(exception.getCause().getMessage().matches(
+                "Route route[0-9]+\\Q has no output processors. You need to 
add outputs to the route such as to(\"log:foo\").\\E"));
     }
 
     @Override
diff --git 
a/core/camel-core/src/test/java/org/apache/camel/processor/CreateRouteWithNonExistingEndpointTest.java
 
b/core/camel-core/src/test/java/org/apache/camel/processor/CreateRouteWithNonExistingEndpointTest.java
index c73b4c5ca13..0890247943b 100644
--- 
a/core/camel-core/src/test/java/org/apache/camel/processor/CreateRouteWithNonExistingEndpointTest.java
+++ 
b/core/camel-core/src/test/java/org/apache/camel/processor/CreateRouteWithNonExistingEndpointTest.java
@@ -23,12 +23,16 @@ import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.fail;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
 
 public class CreateRouteWithNonExistingEndpointTest extends ContextTestSupport 
{
+    private Exception exception = null;
 
     @Test
     public void testCreateRouteWithBadEndpoint() {
+        assertNotNull(exception, "Should have failed to create a route to a 
non-existent endpoint!");
+        NoSuchEndpointException nse = 
assertIsInstanceOf(NoSuchEndpointException.class, exception.getCause());
+        assertEquals("thisUriDoesNotExist", nse.getUri(), "uri");
     }
 
     @Override
@@ -36,11 +40,9 @@ public class CreateRouteWithNonExistingEndpointTest extends 
ContextTestSupport {
     public void setUp() {
         try {
             super.setUp();
-            fail("Should have failed to create this route!");
         } catch (Exception e) {
             log.debug("Caught expected exception: {}", e.getMessage(), e);
-            NoSuchEndpointException nse = 
assertIsInstanceOf(NoSuchEndpointException.class, e.getCause());
-            assertEquals("thisUriDoesNotExist", nse.getUri(), "uri");
+            exception = e;
         }
     }
 
diff --git 
a/core/camel-core/src/test/java/org/apache/camel/processor/RouteWithConstantFieldFromExchangeFailTest.java
 
b/core/camel-core/src/test/java/org/apache/camel/processor/RouteWithConstantFieldFromExchangeFailTest.java
index 8108acf6498..461440a317b 100644
--- 
a/core/camel-core/src/test/java/org/apache/camel/processor/RouteWithConstantFieldFromExchangeFailTest.java
+++ 
b/core/camel-core/src/test/java/org/apache/camel/processor/RouteWithConstantFieldFromExchangeFailTest.java
@@ -22,13 +22,16 @@ import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.fail;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
 
 public class RouteWithConstantFieldFromExchangeFailTest extends 
ContextTestSupport {
+    private Exception exception;
 
     @Test
     public void testFail() {
-        // noop as its tested that it fails on startup
+        assertNotNull(exception, "Should have thrown an exception");
+        IllegalArgumentException iae = 
assertIsInstanceOf(IllegalArgumentException.class, exception.getCause());
+        assertEquals("Constant field with name: XXX not found on 
Exchange.class", iae.getMessage());
     }
 
     @Override
@@ -36,10 +39,8 @@ public class RouteWithConstantFieldFromExchangeFailTest 
extends ContextTestSuppo
     public void setUp() {
         try {
             super.setUp();
-            fail("Should have thrown an exception");
         } catch (Exception e) {
-            IllegalArgumentException iae = 
assertIsInstanceOf(IllegalArgumentException.class, e.getCause());
-            assertEquals("Constant field with name: XXX not found on 
Exchange.class", iae.getMessage());
+            exception = e;
         }
     }
 

Reply via email to