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 08b00d74fd3 (chores) camel-core: fix misleading test failure messages
08b00d74fd3 is described below

commit 08b00d74fd348122343e3540f45877c26a45f555
Author: Otavio Rodolfo Piske <[email protected]>
AuthorDate: Thu Jul 7 09:27:18 2022 +0200

    (chores) camel-core: fix misleading test failure messages
    
    Also cleanup exception tests
---
 .../services/org/apache/camel/other.properties     |  2 +-
 core/camel-core/src/generated/resources/core.json  |  2 +-
 .../apache/camel/builder/ExceptionBuilderTest.java | 74 +++++++---------------
 3 files changed, 25 insertions(+), 53 deletions(-)

diff --git 
a/core/camel-core/src/generated/resources/META-INF/services/org/apache/camel/other.properties
 
b/core/camel-core/src/generated/resources/META-INF/services/org/apache/camel/other.properties
index b473e0ed7bd..164ca29489d 100644
--- 
a/core/camel-core/src/generated/resources/META-INF/services/org/apache/camel/other.properties
+++ 
b/core/camel-core/src/generated/resources/META-INF/services/org/apache/camel/other.properties
@@ -2,6 +2,6 @@
 name=core
 groupId=org.apache.camel
 artifactId=camel-core
-version=3.18.0-SNAPSHOT
+version=3.19.0-SNAPSHOT
 projectName=Camel :: Core
 projectDescription=The Core Camel Framework
diff --git a/core/camel-core/src/generated/resources/core.json 
b/core/camel-core/src/generated/resources/core.json
index ffe00830022..8627fe2283e 100644
--- a/core/camel-core/src/generated/resources/core.json
+++ b/core/camel-core/src/generated/resources/core.json
@@ -9,6 +9,6 @@
     "supportLevel": "Stable",
     "groupId": "org.apache.camel",
     "artifactId": "camel-core",
-    "version": "3.18.0-SNAPSHOT"
+    "version": "3.19.0-SNAPSHOT"
   }
 }
diff --git 
a/core/camel-core/src/test/java/org/apache/camel/builder/ExceptionBuilderTest.java
 
b/core/camel-core/src/test/java/org/apache/camel/builder/ExceptionBuilderTest.java
index ef1dd802d1a..9607bf84609 100644
--- 
a/core/camel-core/src/test/java/org/apache/camel/builder/ExceptionBuilderTest.java
+++ 
b/core/camel-core/src/test/java/org/apache/camel/builder/ExceptionBuilderTest.java
@@ -30,8 +30,8 @@ import org.apache.camel.RuntimeCamelException;
 import org.apache.camel.component.mock.MockEndpoint;
 import org.junit.jupiter.api.Test;
 
-import static org.junit.jupiter.api.Assertions.assertTrue;
-import static org.junit.jupiter.api.Assertions.fail;
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
+import static org.junit.jupiter.api.Assertions.assertThrows;
 
 /**
  * Unit test to test exception configuration
@@ -52,15 +52,11 @@ public class ExceptionBuilderTest extends 
ContextTestSupport {
         mock.expectedMessageCount(1);
         mock.expectedHeaderReceived(MESSAGE_INFO, "Damm a NPE");
 
-        try {
-            template.sendBody("direct:a", "Hello NPE");
-            fail("Should have thrown a NullPointerException");
-        } catch (RuntimeCamelException e) {
-            boolean b = e.getCause() instanceof NullPointerException;
-            assertTrue(b);
-            // expected
-        }
+        final RuntimeCamelException e
+                = assertThrows(RuntimeCamelException.class, () -> 
template.sendBody("direct:a", "Hello NPE"),
+                        "Should have thrown a RuntimeCamelException");
 
+        assertInstanceOf(NullPointerException.class, e.getCause(), "Exception 
cause should have been a NullPointerException");
         MockEndpoint.assertIsSatisfied(result, mock);
     }
 
@@ -72,15 +68,10 @@ public class ExceptionBuilderTest extends 
ContextTestSupport {
         mock.expectedMessageCount(1);
         mock.expectedHeaderReceived(MESSAGE_INFO, "Damm somekind of IO 
exception");
 
-        try {
-            template.sendBody("direct:a", "Hello IO");
-            fail("Should have thrown a IOException");
-        } catch (RuntimeCamelException e) {
-            boolean b = e.getCause() instanceof IOException;
-            assertTrue(b);
-            // expected
-        }
+        Exception e = assertThrows(RuntimeCamelException.class, () -> 
template.sendBody("direct:a", "Hello IO"),
+                "Should have thrown a RuntimeCamelException");
 
+        assertInstanceOf(IOException.class, e.getCause(), "Should have thrown 
a IOException");
         MockEndpoint.assertIsSatisfied(result, mock);
     }
 
@@ -92,14 +83,9 @@ public class ExceptionBuilderTest extends ContextTestSupport 
{
         mock.expectedMessageCount(1);
         mock.expectedHeaderReceived(MESSAGE_INFO, "Damm just exception");
 
-        try {
-            template.sendBody("direct:a", "Hello Exception");
-            fail("Should have thrown a Exception");
-        } catch (RuntimeCamelException e) {
-            boolean b = e.getCause() instanceof Exception;
-            assertTrue(b);
-            // expected
-        }
+        Exception e = assertThrows(RuntimeCamelException.class, () -> 
template.sendBody("direct:a", "Hello Exception"),
+                "Should have thrown a RuntimeCamelException");
+        assertInstanceOf(Exception.class, e.getCause(), "Should have thrown a 
IOException");
 
         MockEndpoint.assertIsSatisfied(result, mock);
     }
@@ -112,15 +98,9 @@ public class ExceptionBuilderTest extends 
ContextTestSupport {
         mock.expectedMessageCount(1);
         mock.expectedHeaderReceived(MESSAGE_INFO, "Damm my business is not 
going to well");
 
-        try {
-            template.sendBody("direct:a", "Hello business");
-            fail("Should have thrown a MyBusinessException");
-        } catch (RuntimeCamelException e) {
-            boolean b = e.getCause() instanceof MyBusinessException;
-            assertTrue(b);
-            // expected
-        }
-
+        Exception e = assertThrows(RuntimeCamelException.class, () -> 
template.sendBody("direct:a", "Hello business"),
+                "Should have thrown a RuntimeCamelException");
+        assertInstanceOf(MyBusinessException.class, e.getCause(), "Should have 
thrown a MyBusinessException");
         MockEndpoint.assertIsSatisfied(result, mock);
     }
 
@@ -133,14 +113,10 @@ public class ExceptionBuilderTest extends 
ContextTestSupport {
         mock.expectedMessageCount(1);
         mock.expectedHeaderReceived(MESSAGE_INFO, "Damm some security error");
 
-        try {
-            template.sendBody("direct:a", "I am not allowed to do this");
-            fail("Should have thrown a GeneralSecurityException");
-        } catch (RuntimeCamelException e) {
-            boolean b = e.getCause() instanceof GeneralSecurityException;
-            assertTrue(b);
-            // expected
-        }
+        Exception e
+                = assertThrows(RuntimeCamelException.class, () -> 
template.sendBody("direct:a", "I am not allowed to do this"),
+                        "Should have thrown a RuntimeCamelException");
+        assertInstanceOf(GeneralSecurityException.class, e.getCause(), "Should 
have thrown a GeneralSecurityException");
 
         MockEndpoint.assertIsSatisfied(result, mock);
     }
@@ -154,14 +130,10 @@ public class ExceptionBuilderTest extends 
ContextTestSupport {
         mock.expectedMessageCount(1);
         mock.expectedHeaderReceived(MESSAGE_INFO, "Damm some access error");
 
-        try {
-            template.sendBody("direct:a", "I am not allowed to access this");
-            fail("Should have thrown a GeneralSecurityException");
-        } catch (RuntimeCamelException e) {
-            boolean b = e.getCause() instanceof IllegalAccessException;
-            assertTrue(b);
-            // expected
-        }
+        Exception e = assertThrows(RuntimeCamelException.class,
+                () -> template.sendBody("direct:a", "I am not allowed to 
access this"),
+                "Should have thrown a RuntimeCamelException");
+        assertInstanceOf(IllegalAccessException.class, e.getCause(), "Should 
have thrown a IllegalAccessException");
 
         MockEndpoint.assertIsSatisfied(result, mock);
     }

Reply via email to