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

davsclaus 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 623579040f1 CAMEL-21196: modernized assertions in camel-core.model 
(#15728)
623579040f1 is described below

commit 623579040f11c60aff3c62a75d0c5ffbcddef534
Author: LostArtist <[email protected]>
AuthorDate: Thu Sep 26 19:21:13 2024 +0200

    CAMEL-21196: modernized assertions in camel-core.model (#15728)
---
 .../model/ProcessorTypeConfigurationTest.java      | 14 +++---
 .../model/RouteConfigurationOnCompletionTest.java  | 18 ++-----
 .../RoutesConfigurationBuilderIdOrPatternTest.java | 23 ++++-----
 .../model/RoutesConfigurationErrorHandlerTest.java | 11 ++---
 .../model/StartingRoutesErrorReportedTest.java     | 55 ++++++++++------------
 5 files changed, 50 insertions(+), 71 deletions(-)

diff --git 
a/core/camel-core/src/test/java/org/apache/camel/model/ProcessorTypeConfigurationTest.java
 
b/core/camel-core/src/test/java/org/apache/camel/model/ProcessorTypeConfigurationTest.java
index d6dc474f150..10ed72d5fbd 100644
--- 
a/core/camel-core/src/test/java/org/apache/camel/model/ProcessorTypeConfigurationTest.java
+++ 
b/core/camel-core/src/test/java/org/apache/camel/model/ProcessorTypeConfigurationTest.java
@@ -21,7 +21,7 @@ import org.apache.camel.builder.RouteBuilder;
 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.assertThrows;
 
 /**
  * Unit test to verify end-user exceptions for miss configuration
@@ -30,17 +30,15 @@ public class ProcessorTypeConfigurationTest extends 
ContextTestSupport {
 
     @Test
     public void testProcessorRefMissConfigured() {
-        try {
+        Exception e = assertThrows(Exception.class, () -> {
             context.addRoutes(new RouteBuilder() {
                 public void configure() {
                     from("direct:in").process("hello");
                 }
             });
-            fail("Should have thrown IllegalArgumentException");
-        } catch (Exception e) {
-            assertEquals("No bean could be found in the registry for: hello of 
type: org.apache.camel.Processor",
-                    e.getCause().getMessage());
-        }
-    }
+        }, "Should have thrown IllegalArgumentException");
 
+        assertEquals("No bean could be found in the registry for: hello of 
type: org.apache.camel.Processor",
+                e.getCause().getMessage());
+    }
 }
diff --git 
a/core/camel-core/src/test/java/org/apache/camel/model/RouteConfigurationOnCompletionTest.java
 
b/core/camel-core/src/test/java/org/apache/camel/model/RouteConfigurationOnCompletionTest.java
index 152fd49a7ac..128e6f42f1e 100644
--- 
a/core/camel-core/src/test/java/org/apache/camel/model/RouteConfigurationOnCompletionTest.java
+++ 
b/core/camel-core/src/test/java/org/apache/camel/model/RouteConfigurationOnCompletionTest.java
@@ -23,7 +23,7 @@ import org.apache.camel.builder.RouteConfigurationBuilder;
 import org.apache.camel.processor.OnCompletionTest;
 import org.junit.jupiter.api.Test;
 
-import static org.junit.jupiter.api.Assertions.fail;
+import static org.junit.jupiter.api.Assertions.assertThrows;
 
 public class RouteConfigurationOnCompletionTest extends ContextTestSupport {
 
@@ -58,12 +58,8 @@ public class RouteConfigurationOnCompletionTest extends 
ContextTestSupport {
         getMockEndpoint("mock:fail").expectedMessageCount(1);
         getMockEndpoint("mock:result").expectedMessageCount(0);
 
-        try {
-            template.sendBody("direct:start", "Kaboom");
-            fail("Should have thrown exception");
-        } catch (Exception e) {
-            // expected
-        }
+        assertThrows(Exception.class, () -> template.sendBody("direct:start", 
"Kaboom"),
+                "Should have thrown exception");
 
         assertMockEndpointsSatisfied();
     }
@@ -75,12 +71,8 @@ public class RouteConfigurationOnCompletionTest extends 
ContextTestSupport {
         getMockEndpoint("mock:result").expectedBodiesReceived("Bye World");
 
         template.sendBody("direct:start", "Hello World");
-        try {
-            template.sendBody("direct:start", "Kaboom");
-            fail("Should throw exception");
-        } catch (Exception e) {
-            // expected
-        }
+        assertThrows(Exception.class, () -> template.sendBody("direct:start", 
"Kaboom"),
+                "Should throw exception");
 
         assertMockEndpointsSatisfied();
     }
diff --git 
a/core/camel-core/src/test/java/org/apache/camel/model/RoutesConfigurationBuilderIdOrPatternTest.java
 
b/core/camel-core/src/test/java/org/apache/camel/model/RoutesConfigurationBuilderIdOrPatternTest.java
index f7c8b3bcbe6..6ba8c11b723 100644
--- 
a/core/camel-core/src/test/java/org/apache/camel/model/RoutesConfigurationBuilderIdOrPatternTest.java
+++ 
b/core/camel-core/src/test/java/org/apache/camel/model/RoutesConfigurationBuilderIdOrPatternTest.java
@@ -31,7 +31,7 @@ import org.junit.jupiter.api.Test;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertNull;
-import static org.junit.jupiter.api.Assertions.fail;
+import static org.junit.jupiter.api.Assertions.assertThrows;
 
 public class RoutesConfigurationBuilderIdOrPatternTest extends 
ContextTestSupport {
 
@@ -84,12 +84,9 @@ public class RoutesConfigurationBuilderIdOrPatternTest 
extends ContextTestSuppor
 
         getMockEndpoint("mock:error").expectedBodiesReceived("Bye World");
 
-        try {
-            template.sendBody("direct:start", "Hello World");
-            fail("Should throw exception");
-        } catch (Exception e) {
-            // expected
-        }
+        assertThrows(Exception.class, () -> template.sendBody("direct:start", 
"Hello World"),
+                "Should throw exception");
+
         template.sendBody("direct:start2", "Bye World");
 
         assertMockEndpointsSatisfied();
@@ -242,12 +239,12 @@ public class RoutesConfigurationBuilderIdOrPatternTest 
extends ContextTestSuppor
                 
routeConfiguration("foo").onException(IllegalArgumentException.class).handled(true).to("mock:foo");
             }
         };
-        try {
-            context.addRoutesConfigurations(rcb);
-            fail("Should throw exception");
-        } catch (IllegalArgumentException e) {
-            assertEquals("Route configuration already exists with id: foo", 
e.getMessage());
-        }
+
+        IllegalArgumentException e = 
assertThrows(IllegalArgumentException.class,
+                () -> context.addRoutesConfigurations(rcb),
+                "Should throw exception");
+
+        assertEquals("Route configuration already exists with id: foo", 
e.getMessage());
     }
 
 }
diff --git 
a/core/camel-core/src/test/java/org/apache/camel/model/RoutesConfigurationErrorHandlerTest.java
 
b/core/camel-core/src/test/java/org/apache/camel/model/RoutesConfigurationErrorHandlerTest.java
index 192a0a5e5d0..85178e4b5a5 100644
--- 
a/core/camel-core/src/test/java/org/apache/camel/model/RoutesConfigurationErrorHandlerTest.java
+++ 
b/core/camel-core/src/test/java/org/apache/camel/model/RoutesConfigurationErrorHandlerTest.java
@@ -21,7 +21,7 @@ import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.builder.RouteConfigurationBuilder;
 import org.junit.jupiter.api.Test;
 
-import static org.assertj.core.api.Fail.fail;
+import static org.junit.jupiter.api.Assertions.assertThrows;
 
 public class RoutesConfigurationErrorHandlerTest extends ContextTestSupport {
 
@@ -115,12 +115,9 @@ public class RoutesConfigurationErrorHandlerTest extends 
ContextTestSupport {
 
         getMockEndpoint("mock:error").expectedBodiesReceived("Bye World");
 
-        try {
-            template.sendBody("direct:start", "Hello World");
-            fail("Should throw exception");
-        } catch (Exception e) {
-            // expected
-        }
+        assertThrows(Exception.class, () -> template.sendBody("direct:start", 
"Hello World"),
+                "Should throw exception");
+
         template.sendBody("direct:start2", "Bye World");
 
         assertMockEndpointsSatisfied();
diff --git 
a/core/camel-core/src/test/java/org/apache/camel/model/StartingRoutesErrorReportedTest.java
 
b/core/camel-core/src/test/java/org/apache/camel/model/StartingRoutesErrorReportedTest.java
index e1c024fd77b..a08563b33b8 100644
--- 
a/core/camel-core/src/test/java/org/apache/camel/model/StartingRoutesErrorReportedTest.java
+++ 
b/core/camel-core/src/test/java/org/apache/camel/model/StartingRoutesErrorReportedTest.java
@@ -20,14 +20,14 @@ import org.apache.camel.ContextTestSupport;
 import org.apache.camel.builder.RouteBuilder;
 import org.junit.jupiter.api.Test;
 
+import static org.junit.jupiter.api.Assertions.assertThrows;
 import static org.junit.jupiter.api.Assertions.assertTrue;
-import static org.junit.jupiter.api.Assertions.fail;
 
 public class StartingRoutesErrorReportedTest extends ContextTestSupport {
 
     @Test
     public void testInvalidFrom() {
-        try {
+        Exception e = assertThrows(Exception.class, () -> {
             context.addRoutes(new RouteBuilder() {
                 @Override
                 public void configure() {
@@ -35,16 +35,15 @@ public class StartingRoutesErrorReportedTest extends 
ContextTestSupport {
                 }
             });
             context.start();
-            fail();
-        } catch (Exception e) {
-            assertTrue(e.getMessage().startsWith(
-                    "Failed to create route route1: 
Route(route1)[From[direct:start?foo=bar] -> [To[mock:result]... because of"));
-        }
+        });
+
+        assertTrue(e.getMessage().startsWith(
+                "Failed to create route route1: 
Route(route1)[From[direct:start?foo=bar] -> [To[mock:result]... because of"));
     }
 
     @Test
     public void testInvalidTo() {
-        try {
+        Exception e = assertThrows(Exception.class, () -> {
             context.addRoutes(new RouteBuilder() {
                 @Override
                 public void configure() {
@@ -52,16 +51,15 @@ public class StartingRoutesErrorReportedTest extends 
ContextTestSupport {
                 }
             });
             context.start();
-            fail();
-        } catch (Exception e) {
-            assertTrue(
-                    e.getMessage().startsWith("Failed to create route route2 
at: >>> To[direct:result?foo=bar] <<< in route:"));
-        }
+        });
+
+        assertTrue(
+                e.getMessage().startsWith("Failed to create route route2 at: 
>>> To[direct:result?foo=bar] <<< in route:"));
     }
 
     @Test
     public void testMaskPassword() {
-        try {
+        Exception e = assertThrows(Exception.class, () -> {
             context.addRoutes(new RouteBuilder() {
                 @Override
                 public void configure() {
@@ -69,16 +67,15 @@ public class StartingRoutesErrorReportedTest extends 
ContextTestSupport {
                 }
             });
             context.start();
-            fail();
-        } catch (Exception e) {
-            assertTrue(
-                    e.getMessage().startsWith("Failed to create route route2 
at: >>> To[direct:result?foo=bar] <<< in route:"));
-        }
+        });
+
+        assertTrue(
+                e.getMessage().startsWith("Failed to create route route2 at: 
>>> To[direct:result?foo=bar] <<< in route:"));
     }
 
     @Test
     public void testInvalidBean() {
-        try {
+        Exception e = assertThrows(Exception.class, () -> {
             context.addRoutes(new RouteBuilder() {
                 @Override
                 public void configure() {
@@ -86,15 +83,14 @@ public class StartingRoutesErrorReportedTest extends 
ContextTestSupport {
                 }
             });
             context.start();
-            fail("Should have thrown exception");
-        } catch (Exception e) {
-            assertTrue(e.getMessage().startsWith("Failed to create route 
route3 at: >>> Bean[ref:] <<< in route:"));
-        }
+        }, "Should have thrown exception");
+
+        assertTrue(e.getMessage().startsWith("Failed to create route route3 
at: >>> Bean[ref:] <<< in route:"));
     }
 
     @Test
     public void testUnavailableDataFormatOnClasspath() {
-        try {
+        Exception e = assertThrows(Exception.class, () -> {
             context.addRoutes(new RouteBuilder() {
                 @Override
                 public void configure() {
@@ -102,11 +98,10 @@ public class StartingRoutesErrorReportedTest extends 
ContextTestSupport {
                 }
             });
             context.start();
-            fail("Should have thrown exception");
-        } catch (Exception e) {
-            assertTrue(e.getMessage().contains(
-                    "Ensure that the data format is valid and the associated 
Camel component is present on the classpath"));
-        }
+        }, "Should have thrown exception");
+
+        assertTrue(e.getMessage().contains(
+                "Ensure that the data format is valid and the associated Camel 
component is present on the classpath"));
     }
 
     @Override

Reply via email to