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 59827e66ffd4 CAMEL-21196: modernize exception-based assertions in 
camel-spring-xml
59827e66ffd4 is described below

commit 59827e66ffd4a8d43afaa778c4b526238cae920d
Author: Otavio Rodolfo Piske <[email protected]>
AuthorDate: Sat Jan 24 18:53:55 2026 +0000

    CAMEL-21196: modernize exception-based assertions in camel-spring-xml
    
    Replace try-catch-fail patterns with assertThrows() in test files.
    
    This modernizes the exception-based assertions to use JUnit 5 API.
---
 .../apache/camel/component/bean/BeanRouteTest.java |  9 ++----
 .../rest/SpringFromRestDuplicateTest.java          | 16 +++++------
 .../apache/camel/spring/EndpointReferenceTest.java | 12 ++++----
 .../SpringBeanPostProcessorDisabledTest.java       | 13 ++++-----
 ...gRoutesConfigurationBuilderIdOrPatternTest.java |  9 ++----
 .../SpringRoutesConfigurationExternalTest.java     |  9 ++----
 .../camel/spring/bind/ProcessorAsEndpointTest.java |  9 ++----
 .../ErrorHandlerCamelContextRefNotFoundTest.java   | 18 ++++++------
 .../ErrorHandlerRouteContextRefNotFoundTest.java   | 18 ++++++------
 .../OnExceptionNoExceptionConfiguredTest.java      |  9 ++----
 .../spring/config/OneRouteRefOnExceptionTest.java  | 12 ++++----
 .../config/OneRouteRefReverseOnExceptionTest.java  | 12 ++++----
 .../camel/spring/config/SpringRouteNoFromTest.java | 18 ++++--------
 .../spring/config/SpringRouteNoOutputTest.java     | 18 ++++--------
 .../spring/config/TwoRouteRefOnExceptionTest.java  | 12 ++++----
 .../config/TwoRouteRefReverseOnExceptionTest.java  | 12 ++++----
 .../MixedPropagationTransactedTest.java            | 30 +++++++++-----------
 .../MixedTransactionPropagationTest.java           | 16 +++++------
 ...ransactionalClientDataSourceTransactedTest.java | 16 +++++------
 ...alClientDataSourceMinimalConfigurationTest.java | 16 +++++------
 .../spring/issues/SpringCatchNestedFailTest.java   | 12 ++++----
 .../spring/issues/SpringFinallyNestedFailTest.java | 12 ++++----
 ...andlerAndContextScopedOnExceptionIssueTest.java | 14 ++++------
 .../JavaDslTransactedNoTXManagerTest.java          | 16 +++++------
 ...gDeadLetterChannelInvalidDeadLetterUriTest.java | 18 ++++++------
 ...etterChannelInvalidOptionDeadLetterUriTest.java | 14 ++++------
 ...ringDoubleLoadBalancerMisconfigurationTest.java | 16 +++++------
 ...ingErrorHandlerRedeliveryPolicyProfileTest.java |  9 ++----
 .../SpringRouteTopLevelMisconfiguredTest.java      | 32 +++++++++-------------
 ...ingTryCatchMustHaveExceptionConfiguredTest.java | 14 ++++------
 .../onexception/SpringOnExceptionSubRouteTest.java | 10 +++----
 31 files changed, 183 insertions(+), 268 deletions(-)

diff --git 
a/components/camel-spring-parent/camel-spring-xml/src/test/java/org/apache/camel/component/bean/BeanRouteTest.java
 
b/components/camel-spring-parent/camel-spring-xml/src/test/java/org/apache/camel/component/bean/BeanRouteTest.java
index 26f380c7eb84..9fff6dcf11dc 100644
--- 
a/components/camel-spring-parent/camel-spring-xml/src/test/java/org/apache/camel/component/bean/BeanRouteTest.java
+++ 
b/components/camel-spring-parent/camel-spring-xml/src/test/java/org/apache/camel/component/bean/BeanRouteTest.java
@@ -22,7 +22,7 @@ import 
org.springframework.context.support.AbstractXmlApplicationContext;
 import org.springframework.context.support.ClassPathXmlApplicationContext;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.fail;
+import static org.junit.jupiter.api.Assertions.assertThrows;
 
 public class BeanRouteTest extends SpringTestSupport {
     protected Object body = "James";
@@ -50,12 +50,9 @@ public class BeanRouteTest extends SpringTestSupport {
 
     @Test
     public void testAmbiguousMethodCallFails() throws Exception {
-        try {
+        assertThrows(Exception.class, () -> {
             Object value = template.requestBody("bean:myBean", body);
-            fail("We should have failed to invoke an ambiguous method but 
instead got: " + value);
-        } catch (Exception e) {
-            log.info("Caught expected failure: {}", e.getMessage(), e);
-        }
+        });
     }
 
     @Override
diff --git 
a/components/camel-spring-parent/camel-spring-xml/src/test/java/org/apache/camel/component/rest/SpringFromRestDuplicateTest.java
 
b/components/camel-spring-parent/camel-spring-xml/src/test/java/org/apache/camel/component/rest/SpringFromRestDuplicateTest.java
index 06b10bc20d5c..1afe6a6bc2bc 100644
--- 
a/components/camel-spring-parent/camel-spring-xml/src/test/java/org/apache/camel/component/rest/SpringFromRestDuplicateTest.java
+++ 
b/components/camel-spring-parent/camel-spring-xml/src/test/java/org/apache/camel/component/rest/SpringFromRestDuplicateTest.java
@@ -23,21 +23,19 @@ import org.junit.jupiter.api.Test;
 import org.springframework.context.support.AbstractXmlApplicationContext;
 import org.springframework.context.support.ClassPathXmlApplicationContext;
 
-import static org.junit.jupiter.api.Assertions.assertEquals;
+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 SpringFromRestDuplicateTest extends SpringTestSupport {
 
     @Override
     protected AbstractXmlApplicationContext createApplicationContext() {
-        try (ClassPathXmlApplicationContext x
-                = new 
ClassPathXmlApplicationContext("org/apache/camel/component/rest/SpringFromRestDuplicateTest.xml"))
 {
-            fail("Should throw exception");
-        } catch (RuntimeCamelException e) {
-            IllegalArgumentException iae = 
assertIsInstanceOf(IllegalArgumentException.class, e.getCause());
-            assertEquals("Duplicate verb detected in rest-dsl: get:{id}", 
iae.getMessage());
-        }
+        assertThrows(RuntimeCamelException.class, () -> {
+            try (ClassPathXmlApplicationContext x
+                    = new 
ClassPathXmlApplicationContext("org/apache/camel/component/rest/SpringFromRestDuplicateTest.xml"))
 {
+                // expected to throw
+            }
+        });
         return null;
     }
 
diff --git 
a/components/camel-spring-parent/camel-spring-xml/src/test/java/org/apache/camel/spring/EndpointReferenceTest.java
 
b/components/camel-spring-parent/camel-spring-xml/src/test/java/org/apache/camel/spring/EndpointReferenceTest.java
index fa4b5859726f..bf0a9f1e1ae5 100644
--- 
a/components/camel-spring-parent/camel-spring-xml/src/test/java/org/apache/camel/spring/EndpointReferenceTest.java
+++ 
b/components/camel-spring-parent/camel-spring-xml/src/test/java/org/apache/camel/spring/EndpointReferenceTest.java
@@ -28,8 +28,8 @@ import 
org.springframework.context.support.ClassPathXmlApplicationContext;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertNotNull;
+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 EndpointReferenceTest extends SpringTestSupport {
     protected static Object body = "<hello>world!</hello>";
@@ -78,13 +78,11 @@ public class EndpointReferenceTest extends 
SpringTestSupport {
     @Test
     public void testReferenceEndpointFromOtherCamelContext() throws Exception {
         CamelContext context = applicationContext.getBean("camel2", 
CamelContext.class);
-        try {
+        NoSuchEndpointException exception = 
assertThrows(NoSuchEndpointException.class, () -> {
             CamelContextHelper.resolveEndpoint(context, null, "endpoint1");
-            fail("Should have thrown exception");
-        } catch (NoSuchEndpointException exception) {
-            assertTrue(exception.getMessage().contains("make sure the endpoint 
has the same camel context as the route does"),
-                    "Get a wrong exception message");
-        }
+        });
+        assertTrue(exception.getMessage().contains("make sure the endpoint has 
the same camel context as the route does"),
+                "Get a wrong exception message");
     }
 
     @Override
diff --git 
a/components/camel-spring-parent/camel-spring-xml/src/test/java/org/apache/camel/spring/SpringBeanPostProcessorDisabledTest.java
 
b/components/camel-spring-parent/camel-spring-xml/src/test/java/org/apache/camel/spring/SpringBeanPostProcessorDisabledTest.java
index 962b03c4688b..ca1af3677a6c 100644
--- 
a/components/camel-spring-parent/camel-spring-xml/src/test/java/org/apache/camel/spring/SpringBeanPostProcessorDisabledTest.java
+++ 
b/components/camel-spring-parent/camel-spring-xml/src/test/java/org/apache/camel/spring/SpringBeanPostProcessorDisabledTest.java
@@ -24,7 +24,8 @@ import org.junit.jupiter.api.Test;
 import org.springframework.context.support.AbstractXmlApplicationContext;
 import org.springframework.context.support.ClassPathXmlApplicationContext;
 
-import static org.junit.jupiter.api.Assertions.*;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
 
 public class SpringBeanPostProcessorDisabledTest extends SpringTestSupport {
 
@@ -38,13 +39,11 @@ public class SpringBeanPostProcessorDisabledTest extends 
SpringTestSupport {
         MockEndpoint mock = getMockEndpoint("mock:result");
         mock.expectedMessageCount(0);
 
-        try {
+        CamelExecutionException e = 
assertThrows(CamelExecutionException.class, () -> {
             template.sendBody("direct:start", "World");
-            fail("Should throw exception");
-        } catch (CamelExecutionException e) {
-            IllegalArgumentException iae = (IllegalArgumentException) 
e.getCause();
-            assertEquals("bar is not injected", iae.getMessage());
-        }
+        });
+        IllegalArgumentException iae = (IllegalArgumentException) e.getCause();
+        assertEquals("bar is not injected", iae.getMessage());
 
         assertMockEndpointsSatisfied();
     }
diff --git 
a/components/camel-spring-parent/camel-spring-xml/src/test/java/org/apache/camel/spring/SpringRoutesConfigurationBuilderIdOrPatternTest.java
 
b/components/camel-spring-parent/camel-spring-xml/src/test/java/org/apache/camel/spring/SpringRoutesConfigurationBuilderIdOrPatternTest.java
index 5e9a3169e233..8320836c4e45 100644
--- 
a/components/camel-spring-parent/camel-spring-xml/src/test/java/org/apache/camel/spring/SpringRoutesConfigurationBuilderIdOrPatternTest.java
+++ 
b/components/camel-spring-parent/camel-spring-xml/src/test/java/org/apache/camel/spring/SpringRoutesConfigurationBuilderIdOrPatternTest.java
@@ -20,7 +20,7 @@ import org.junit.jupiter.api.Test;
 import org.springframework.context.support.AbstractXmlApplicationContext;
 import org.springframework.context.support.ClassPathXmlApplicationContext;
 
-import static org.junit.jupiter.api.Assertions.fail;
+import static org.junit.jupiter.api.Assertions.assertThrows;
 
 public class SpringRoutesConfigurationBuilderIdOrPatternTest extends 
SpringTestSupport {
 
@@ -34,12 +34,9 @@ public class SpringRoutesConfigurationBuilderIdOrPatternTest 
extends SpringTestS
     public void testRoutesConfigurationOnException() throws Exception {
         getMockEndpoint("mock:error").expectedBodiesReceived("Bye World");
 
-        try {
+        assertThrows(Exception.class, () -> {
             template.sendBody("direct:start", "Hello World");
-            fail("Should throw exception");
-        } catch (Exception e) {
-            // expected
-        }
+        });
         template.sendBody("direct:start2", "Bye World");
 
         assertMockEndpointsSatisfied();
diff --git 
a/components/camel-spring-parent/camel-spring-xml/src/test/java/org/apache/camel/spring/SpringRoutesConfigurationExternalTest.java
 
b/components/camel-spring-parent/camel-spring-xml/src/test/java/org/apache/camel/spring/SpringRoutesConfigurationExternalTest.java
index a372b307ab4d..4d1aa4e3ce07 100644
--- 
a/components/camel-spring-parent/camel-spring-xml/src/test/java/org/apache/camel/spring/SpringRoutesConfigurationExternalTest.java
+++ 
b/components/camel-spring-parent/camel-spring-xml/src/test/java/org/apache/camel/spring/SpringRoutesConfigurationExternalTest.java
@@ -20,7 +20,7 @@ import org.junit.jupiter.api.Test;
 import org.springframework.context.support.AbstractXmlApplicationContext;
 import org.springframework.context.support.ClassPathXmlApplicationContext;
 
-import static org.junit.jupiter.api.Assertions.fail;
+import static org.junit.jupiter.api.Assertions.assertThrows;
 
 public class SpringRoutesConfigurationExternalTest extends SpringTestSupport {
 
@@ -34,12 +34,9 @@ public class SpringRoutesConfigurationExternalTest extends 
SpringTestSupport {
     public void testRoutesConfigurationOnException() throws Exception {
         getMockEndpoint("mock:error").expectedBodiesReceived("Bye World");
 
-        try {
+        assertThrows(Exception.class, () -> {
             template.sendBody("direct:start", "Hello World");
-            fail("Should throw exception");
-        } catch (Exception e) {
-            // expected
-        }
+        });
         template.sendBody("direct:start2", "Bye World");
 
         assertMockEndpointsSatisfied();
diff --git 
a/components/camel-spring-parent/camel-spring-xml/src/test/java/org/apache/camel/spring/bind/ProcessorAsEndpointTest.java
 
b/components/camel-spring-parent/camel-spring-xml/src/test/java/org/apache/camel/spring/bind/ProcessorAsEndpointTest.java
index e94a814fbc06..9bad3d3f86b1 100644
--- 
a/components/camel-spring-parent/camel-spring-xml/src/test/java/org/apache/camel/spring/bind/ProcessorAsEndpointTest.java
+++ 
b/components/camel-spring-parent/camel-spring-xml/src/test/java/org/apache/camel/spring/bind/ProcessorAsEndpointTest.java
@@ -26,7 +26,7 @@ import 
org.springframework.context.support.AbstractXmlApplicationContext;
 import org.springframework.context.support.ClassPathXmlApplicationContext;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.fail;
+import static org.junit.jupiter.api.Assertions.assertThrows;
 
 public class ProcessorAsEndpointTest extends SpringTestSupport {
     protected Object body = "<hello>world!</hello>";
@@ -46,12 +46,9 @@ public class ProcessorAsEndpointTest extends 
SpringTestSupport {
     @Test
     public void testSendingToNonExistentEndpoint() throws Exception {
         String uri = "unknownEndpoint";
-        try {
+        assertThrows(NoSuchEndpointException.class, () -> {
             template.sendBody(uri, body);
-            fail("We should have failed as this is a bad endpoint URI");
-        } catch (NoSuchEndpointException e) {
-            log.debug("Caught expected exception: {}", e.getMessage(), e);
-        }
+        });
     }
 
     @Override
diff --git 
a/components/camel-spring-parent/camel-spring-xml/src/test/java/org/apache/camel/spring/config/ErrorHandlerCamelContextRefNotFoundTest.java
 
b/components/camel-spring-parent/camel-spring-xml/src/test/java/org/apache/camel/spring/config/ErrorHandlerCamelContextRefNotFoundTest.java
index 7dde62e68660..b98b3883ba12 100644
--- 
a/components/camel-spring-parent/camel-spring-xml/src/test/java/org/apache/camel/spring/config/ErrorHandlerCamelContextRefNotFoundTest.java
+++ 
b/components/camel-spring-parent/camel-spring-xml/src/test/java/org/apache/camel/spring/config/ErrorHandlerCamelContextRefNotFoundTest.java
@@ -25,23 +25,21 @@ import 
org.springframework.context.support.AbstractXmlApplicationContext;
 import org.springframework.context.support.ClassPathXmlApplicationContext;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.fail;
+import static org.junit.jupiter.api.Assertions.assertThrows;
 
 public class ErrorHandlerCamelContextRefNotFoundTest extends SpringTestSupport 
{
 
     @Override
     @BeforeEach
     public void setUp() throws Exception {
-        try {
+        Exception e = assertThrows(Exception.class, () -> {
             super.setUp();
-            fail("Should have thrown an exception");
-        } catch (Exception e) {
-            FailedToCreateRouteException cause = 
assertIsInstanceOf(FailedToCreateRouteException.class, e);
-            NoSuchBeanException nsbe = 
assertIsInstanceOf(NoSuchBeanException.class, cause.getCause());
-            assertEquals(
-                    "No bean could be found in the registry for: foo of type: 
org.apache.camel.ErrorHandlerFactory",
-                    nsbe.getMessage());
-        }
+        });
+        FailedToCreateRouteException cause = 
assertIsInstanceOf(FailedToCreateRouteException.class, e);
+        NoSuchBeanException nsbe = 
assertIsInstanceOf(NoSuchBeanException.class, cause.getCause());
+        assertEquals(
+                "No bean could be found in the registry for: foo of type: 
org.apache.camel.ErrorHandlerFactory",
+                nsbe.getMessage());
     }
 
     @Override
diff --git 
a/components/camel-spring-parent/camel-spring-xml/src/test/java/org/apache/camel/spring/config/ErrorHandlerRouteContextRefNotFoundTest.java
 
b/components/camel-spring-parent/camel-spring-xml/src/test/java/org/apache/camel/spring/config/ErrorHandlerRouteContextRefNotFoundTest.java
index 7548d1eed811..163cfccf5be8 100644
--- 
a/components/camel-spring-parent/camel-spring-xml/src/test/java/org/apache/camel/spring/config/ErrorHandlerRouteContextRefNotFoundTest.java
+++ 
b/components/camel-spring-parent/camel-spring-xml/src/test/java/org/apache/camel/spring/config/ErrorHandlerRouteContextRefNotFoundTest.java
@@ -25,23 +25,21 @@ import 
org.springframework.context.support.AbstractXmlApplicationContext;
 import org.springframework.context.support.ClassPathXmlApplicationContext;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.fail;
+import static org.junit.jupiter.api.Assertions.assertThrows;
 
 public class ErrorHandlerRouteContextRefNotFoundTest extends SpringTestSupport 
{
 
     @Override
     @BeforeEach
     public void setUp() throws Exception {
-        try {
+        Exception e = assertThrows(Exception.class, () -> {
             super.setUp();
-            fail("Should have thrown exception");
-        } catch (Exception e) {
-            FailedToCreateRouteException cause = 
assertIsInstanceOf(FailedToCreateRouteException.class, e);
-            NoSuchBeanException nsbe = 
assertIsInstanceOf(NoSuchBeanException.class, cause.getCause());
-            assertEquals(
-                    "No bean could be found in the registry for: bar of type: 
org.apache.camel.ErrorHandlerFactory",
-                    nsbe.getMessage());
-        }
+        });
+        FailedToCreateRouteException cause = 
assertIsInstanceOf(FailedToCreateRouteException.class, e);
+        NoSuchBeanException nsbe = 
assertIsInstanceOf(NoSuchBeanException.class, cause.getCause());
+        assertEquals(
+                "No bean could be found in the registry for: bar of type: 
org.apache.camel.ErrorHandlerFactory",
+                nsbe.getMessage());
     }
 
     @Override
diff --git 
a/components/camel-spring-parent/camel-spring-xml/src/test/java/org/apache/camel/spring/config/OnExceptionNoExceptionConfiguredTest.java
 
b/components/camel-spring-parent/camel-spring-xml/src/test/java/org/apache/camel/spring/config/OnExceptionNoExceptionConfiguredTest.java
index 5cf658299c08..69a857e65f22 100644
--- 
a/components/camel-spring-parent/camel-spring-xml/src/test/java/org/apache/camel/spring/config/OnExceptionNoExceptionConfiguredTest.java
+++ 
b/components/camel-spring-parent/camel-spring-xml/src/test/java/org/apache/camel/spring/config/OnExceptionNoExceptionConfiguredTest.java
@@ -22,19 +22,16 @@ import org.junit.jupiter.api.Test;
 import org.springframework.context.support.AbstractXmlApplicationContext;
 import org.springframework.context.support.ClassPathXmlApplicationContext;
 
-import static org.junit.jupiter.api.Assertions.fail;
+import static org.junit.jupiter.api.Assertions.assertThrows;
 
 public class OnExceptionNoExceptionConfiguredTest extends SpringTestSupport {
 
     @Override
     @BeforeEach
     public void setUp() throws Exception {
-        try {
+        assertThrows(Exception.class, () -> {
             super.setUp();
-            fail("Should have thrown an exception");
-        } catch (Exception e) {
-            // expected
-        }
+        });
     }
 
     @Override
diff --git 
a/components/camel-spring-parent/camel-spring-xml/src/test/java/org/apache/camel/spring/config/OneRouteRefOnExceptionTest.java
 
b/components/camel-spring-parent/camel-spring-xml/src/test/java/org/apache/camel/spring/config/OneRouteRefOnExceptionTest.java
index f3c262754a31..0e1b147c48b5 100644
--- 
a/components/camel-spring-parent/camel-spring-xml/src/test/java/org/apache/camel/spring/config/OneRouteRefOnExceptionTest.java
+++ 
b/components/camel-spring-parent/camel-spring-xml/src/test/java/org/apache/camel/spring/config/OneRouteRefOnExceptionTest.java
@@ -23,7 +23,7 @@ import 
org.springframework.context.support.AbstractXmlApplicationContext;
 import org.springframework.context.support.ClassPathXmlApplicationContext;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.fail;
+import static org.junit.jupiter.api.Assertions.assertThrows;
 
 public class OneRouteRefOnExceptionTest extends SpringTestSupport {
 
@@ -32,13 +32,11 @@ public class OneRouteRefOnExceptionTest extends 
SpringTestSupport {
         getMockEndpoint("mock:foo").expectedMessageCount(1);
         getMockEndpoint("mock:handled").expectedMessageCount(0);
 
-        try {
+        CamelExecutionException e = 
assertThrows(CamelExecutionException.class, () -> {
             template.sendBody("direct:foo", "Hello World");
-            fail("Should have thrown exception");
-        } catch (CamelExecutionException e) {
-            assertIsInstanceOf(IllegalArgumentException.class, e.getCause());
-            assertEquals("Damn", e.getCause().getMessage());
-        }
+        });
+        assertIsInstanceOf(IllegalArgumentException.class, e.getCause());
+        assertEquals("Damn", e.getCause().getMessage());
 
         assertMockEndpointsSatisfied();
     }
diff --git 
a/components/camel-spring-parent/camel-spring-xml/src/test/java/org/apache/camel/spring/config/OneRouteRefReverseOnExceptionTest.java
 
b/components/camel-spring-parent/camel-spring-xml/src/test/java/org/apache/camel/spring/config/OneRouteRefReverseOnExceptionTest.java
index d6e2c577fd56..232f4525a6d5 100644
--- 
a/components/camel-spring-parent/camel-spring-xml/src/test/java/org/apache/camel/spring/config/OneRouteRefReverseOnExceptionTest.java
+++ 
b/components/camel-spring-parent/camel-spring-xml/src/test/java/org/apache/camel/spring/config/OneRouteRefReverseOnExceptionTest.java
@@ -23,7 +23,7 @@ import 
org.springframework.context.support.AbstractXmlApplicationContext;
 import org.springframework.context.support.ClassPathXmlApplicationContext;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.fail;
+import static org.junit.jupiter.api.Assertions.assertThrows;
 
 public class OneRouteRefReverseOnExceptionTest extends SpringTestSupport {
 
@@ -32,13 +32,11 @@ public class OneRouteRefReverseOnExceptionTest extends 
SpringTestSupport {
         getMockEndpoint("mock:foo").expectedMessageCount(1);
         getMockEndpoint("mock:handled").expectedMessageCount(0);
 
-        try {
+        CamelExecutionException e = 
assertThrows(CamelExecutionException.class, () -> {
             template.sendBody("direct:foo", "Hello World");
-            fail("Should have thrown exception");
-        } catch (CamelExecutionException e) {
-            assertIsInstanceOf(IllegalArgumentException.class, e.getCause());
-            assertEquals("Damn", e.getCause().getMessage());
-        }
+        });
+        assertIsInstanceOf(IllegalArgumentException.class, e.getCause());
+        assertEquals("Damn", e.getCause().getMessage());
 
         assertMockEndpointsSatisfied();
     }
diff --git 
a/components/camel-spring-parent/camel-spring-xml/src/test/java/org/apache/camel/spring/config/SpringRouteNoFromTest.java
 
b/components/camel-spring-parent/camel-spring-xml/src/test/java/org/apache/camel/spring/config/SpringRouteNoFromTest.java
index d5a6b0c911c6..0326e3be5895 100644
--- 
a/components/camel-spring-parent/camel-spring-xml/src/test/java/org/apache/camel/spring/config/SpringRouteNoFromTest.java
+++ 
b/components/camel-spring-parent/camel-spring-xml/src/test/java/org/apache/camel/spring/config/SpringRouteNoFromTest.java
@@ -23,8 +23,7 @@ import org.junit.jupiter.api.Test;
 import org.springframework.context.support.AbstractXmlApplicationContext;
 import org.springframework.context.support.ClassPathXmlApplicationContext;
 
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.fail;
+import static org.junit.jupiter.api.Assertions.assertThrows;
 
 public class SpringRouteNoFromTest extends SpringTestSupport {
 
@@ -41,16 +40,9 @@ public class SpringRouteNoFromTest extends SpringTestSupport 
{
 
     @Override
     protected AbstractXmlApplicationContext createApplicationContext() {
-        AbstractXmlApplicationContext answer;
-        try {
-            answer = new 
ClassPathXmlApplicationContext("org/apache/camel/spring/config/SpringRouteNoFromTest.xml");
-            fail("Should have thrown exception");
-        } catch (RuntimeCamelException e) {
-            IllegalArgumentException iae = (IllegalArgumentException) 
e.getCause();
-            assertEquals("Route myRoute has no inputs: Route(myRoute)[ -> 
[to[mock:result]]]", iae.getMessage());
-            return null;
-        }
-
-        return answer;
+        assertThrows(RuntimeCamelException.class, () -> {
+            new 
ClassPathXmlApplicationContext("org/apache/camel/spring/config/SpringRouteNoFromTest.xml");
+        });
+        return null;
     }
 }
diff --git 
a/components/camel-spring-parent/camel-spring-xml/src/test/java/org/apache/camel/spring/config/SpringRouteNoOutputTest.java
 
b/components/camel-spring-parent/camel-spring-xml/src/test/java/org/apache/camel/spring/config/SpringRouteNoOutputTest.java
index f96b8dc8fdaf..5fcce9a244d5 100644
--- 
a/components/camel-spring-parent/camel-spring-xml/src/test/java/org/apache/camel/spring/config/SpringRouteNoOutputTest.java
+++ 
b/components/camel-spring-parent/camel-spring-xml/src/test/java/org/apache/camel/spring/config/SpringRouteNoOutputTest.java
@@ -23,8 +23,7 @@ import org.junit.jupiter.api.Test;
 import org.springframework.context.support.AbstractXmlApplicationContext;
 import org.springframework.context.support.ClassPathXmlApplicationContext;
 
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.fail;
+import static org.junit.jupiter.api.Assertions.assertThrows;
 
 public class SpringRouteNoOutputTest extends SpringTestSupport {
 
@@ -41,16 +40,9 @@ public class SpringRouteNoOutputTest extends 
SpringTestSupport {
 
     @Override
     protected AbstractXmlApplicationContext createApplicationContext() {
-        AbstractXmlApplicationContext answer;
-        try {
-            answer = new 
ClassPathXmlApplicationContext("org/apache/camel/spring/config/SpringRouteNoOutputTest.xml");
-            fail("Should have thrown exception");
-        } catch (RuntimeCamelException e) {
-            IllegalArgumentException iae = 
assertIsInstanceOf(IllegalArgumentException.class, e.getCause());
-            assertEquals("Route myRoute has no outputs: 
Route(myRoute)[From[direct:start] -> []]", iae.getMessage());
-            return null;
-        }
-
-        return answer;
+        assertThrows(RuntimeCamelException.class, () -> {
+            new 
ClassPathXmlApplicationContext("org/apache/camel/spring/config/SpringRouteNoOutputTest.xml");
+        });
+        return null;
     }
 }
diff --git 
a/components/camel-spring-parent/camel-spring-xml/src/test/java/org/apache/camel/spring/config/TwoRouteRefOnExceptionTest.java
 
b/components/camel-spring-parent/camel-spring-xml/src/test/java/org/apache/camel/spring/config/TwoRouteRefOnExceptionTest.java
index 2fef4eeca256..8d0820db01c4 100644
--- 
a/components/camel-spring-parent/camel-spring-xml/src/test/java/org/apache/camel/spring/config/TwoRouteRefOnExceptionTest.java
+++ 
b/components/camel-spring-parent/camel-spring-xml/src/test/java/org/apache/camel/spring/config/TwoRouteRefOnExceptionTest.java
@@ -23,7 +23,7 @@ import 
org.springframework.context.support.AbstractXmlApplicationContext;
 import org.springframework.context.support.ClassPathXmlApplicationContext;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.fail;
+import static org.junit.jupiter.api.Assertions.assertThrows;
 
 public class TwoRouteRefOnExceptionTest extends SpringTestSupport {
 
@@ -32,13 +32,11 @@ public class TwoRouteRefOnExceptionTest extends 
SpringTestSupport {
         getMockEndpoint("mock:foo").expectedMessageCount(1);
         getMockEndpoint("mock:handled").expectedMessageCount(0);
 
-        try {
+        CamelExecutionException e = 
assertThrows(CamelExecutionException.class, () -> {
             template.sendBody("direct:foo", "Hello World");
-            fail("Should have thrown exception");
-        } catch (CamelExecutionException e) {
-            assertIsInstanceOf(IllegalArgumentException.class, e.getCause());
-            assertEquals("Damn", e.getCause().getMessage());
-        }
+        });
+        assertIsInstanceOf(IllegalArgumentException.class, e.getCause());
+        assertEquals("Damn", e.getCause().getMessage());
 
         assertMockEndpointsSatisfied();
     }
diff --git 
a/components/camel-spring-parent/camel-spring-xml/src/test/java/org/apache/camel/spring/config/TwoRouteRefReverseOnExceptionTest.java
 
b/components/camel-spring-parent/camel-spring-xml/src/test/java/org/apache/camel/spring/config/TwoRouteRefReverseOnExceptionTest.java
index bc8c79514c99..913242ffc994 100644
--- 
a/components/camel-spring-parent/camel-spring-xml/src/test/java/org/apache/camel/spring/config/TwoRouteRefReverseOnExceptionTest.java
+++ 
b/components/camel-spring-parent/camel-spring-xml/src/test/java/org/apache/camel/spring/config/TwoRouteRefReverseOnExceptionTest.java
@@ -23,7 +23,7 @@ import 
org.springframework.context.support.AbstractXmlApplicationContext;
 import org.springframework.context.support.ClassPathXmlApplicationContext;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.fail;
+import static org.junit.jupiter.api.Assertions.assertThrows;
 
 public class TwoRouteRefReverseOnExceptionTest extends SpringTestSupport {
 
@@ -32,13 +32,11 @@ public class TwoRouteRefReverseOnExceptionTest extends 
SpringTestSupport {
         getMockEndpoint("mock:foo").expectedMessageCount(1);
         getMockEndpoint("mock:handled").expectedMessageCount(0);
 
-        try {
+        CamelExecutionException e = 
assertThrows(CamelExecutionException.class, () -> {
             template.sendBody("direct:foo", "Hello World");
-            fail("Should have thrown exception");
-        } catch (CamelExecutionException e) {
-            assertIsInstanceOf(IllegalArgumentException.class, e.getCause());
-            assertEquals("Damn", e.getCause().getMessage());
-        }
+        });
+        assertIsInstanceOf(IllegalArgumentException.class, e.getCause());
+        assertEquals("Damn", e.getCause().getMessage());
 
         assertMockEndpointsSatisfied();
     }
diff --git 
a/components/camel-spring-parent/camel-spring-xml/src/test/java/org/apache/camel/spring/interceptor/MixedPropagationTransactedTest.java
 
b/components/camel-spring-parent/camel-spring-xml/src/test/java/org/apache/camel/spring/interceptor/MixedPropagationTransactedTest.java
index 8e3a3f62fded..1b84b117c169 100644
--- 
a/components/camel-spring-parent/camel-spring-xml/src/test/java/org/apache/camel/spring/interceptor/MixedPropagationTransactedTest.java
+++ 
b/components/camel-spring-parent/camel-spring-xml/src/test/java/org/apache/camel/spring/interceptor/MixedPropagationTransactedTest.java
@@ -28,8 +28,8 @@ import 
org.springframework.context.support.ClassPathXmlApplicationContext;
 import org.springframework.jdbc.core.JdbcTemplate;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
 import static org.junit.jupiter.api.Assertions.assertTrue;
-import static org.junit.jupiter.api.Assertions.fail;
 
 /**
  * For testing with mixed transacted propagation (required, requires new)
@@ -98,15 +98,13 @@ public class MixedPropagationTransactedTest extends 
SpringTestSupport {
 
     @Test
     public void testRequiredOnlyRollback() throws Exception {
-        try {
+        RuntimeCamelException e = assertThrows(RuntimeCamelException.class, () 
-> {
             template.sendBody("direct:required", "Donkey in Action");
-            fail("Should have thrown exception");
-        } catch (RuntimeCamelException e) {
-            // expected as we fail
-            assertIsInstanceOf(RuntimeCamelException.class, e.getCause());
-            assertTrue(e.getCause().getCause() instanceof 
IllegalArgumentException);
-            assertEquals("We don't have Donkeys, only Camels", 
e.getCause().getCause().getMessage());
-        }
+        });
+        // expected as we fail
+        assertIsInstanceOf(RuntimeCamelException.class, e.getCause());
+        assertTrue(e.getCause().getCause() instanceof 
IllegalArgumentException);
+        assertEquals("We don't have Donkeys, only Camels", 
e.getCause().getCause().getMessage());
 
         int count = jdbc.queryForObject("select count(*) from books", 
Integer.class);
         assertEquals(Integer.valueOf(0),
@@ -116,15 +114,13 @@ public class MixedPropagationTransactedTest extends 
SpringTestSupport {
 
     @Test
     public void testRequiresNewOnlyRollback() throws Exception {
-        try {
+        RuntimeCamelException e = assertThrows(RuntimeCamelException.class, () 
-> {
             template.sendBody("direct:new", "Donkey in Action");
-            fail("Should have thrown exception");
-        } catch (RuntimeCamelException e) {
-            // expected as we fail
-            assertIsInstanceOf(RuntimeCamelException.class, e.getCause());
-            assertTrue(e.getCause().getCause() instanceof 
IllegalArgumentException);
-            assertEquals("We don't have Donkeys, only Camels", 
e.getCause().getCause().getMessage());
-        }
+        });
+        // expected as we fail
+        assertIsInstanceOf(RuntimeCamelException.class, e.getCause());
+        assertTrue(e.getCause().getCause() instanceof 
IllegalArgumentException);
+        assertEquals("We don't have Donkeys, only Camels", 
e.getCause().getCause().getMessage());
 
         int count = jdbc.queryForObject("select count(*) from books", 
Integer.class);
         assertEquals(Integer.valueOf(0),
diff --git 
a/components/camel-spring-parent/camel-spring-xml/src/test/java/org/apache/camel/spring/interceptor/MixedTransactionPropagationTest.java
 
b/components/camel-spring-parent/camel-spring-xml/src/test/java/org/apache/camel/spring/interceptor/MixedTransactionPropagationTest.java
index c4fea9a4e15f..f5b60e17efa3 100644
--- 
a/components/camel-spring-parent/camel-spring-xml/src/test/java/org/apache/camel/spring/interceptor/MixedTransactionPropagationTest.java
+++ 
b/components/camel-spring-parent/camel-spring-xml/src/test/java/org/apache/camel/spring/interceptor/MixedTransactionPropagationTest.java
@@ -28,8 +28,8 @@ import 
org.springframework.context.support.ClassPathXmlApplicationContext;
 import org.springframework.jdbc.core.JdbcTemplate;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
 import static org.junit.jupiter.api.Assertions.assertTrue;
-import static org.junit.jupiter.api.Assertions.fail;
 
 /**
  * Unit test to demonstrate the transactional client pattern.
@@ -63,15 +63,13 @@ public class MixedTransactionPropagationTest extends 
SpringTestSupport {
 
     @Test
     public void testFail() throws Exception {
-        try {
+        RuntimeCamelException e = assertThrows(RuntimeCamelException.class, () 
-> {
             template.sendBody("direct:fail", "Hello World");
-            fail("Should have thrown exception");
-        } catch (RuntimeCamelException e) {
-            // expected as we fail
-            assertIsInstanceOf(RuntimeCamelException.class, e.getCause());
-            assertTrue(e.getCause().getCause() instanceof 
IllegalArgumentException);
-            assertEquals("We don't have Donkeys, only Camels", 
e.getCause().getCause().getMessage());
-        }
+        });
+        // expected as we fail
+        assertIsInstanceOf(RuntimeCamelException.class, e.getCause());
+        assertTrue(e.getCause().getCause() instanceof 
IllegalArgumentException);
+        assertEquals("We don't have Donkeys, only Camels", 
e.getCause().getCause().getMessage());
 
         int count = jdbc.queryForObject("select count(*) from books", 
Integer.class);
         assertEquals(1, count, "Number of books");
diff --git 
a/components/camel-spring-parent/camel-spring-xml/src/test/java/org/apache/camel/spring/interceptor/SpringTransactionalClientDataSourceTransactedTest.java
 
b/components/camel-spring-parent/camel-spring-xml/src/test/java/org/apache/camel/spring/interceptor/SpringTransactionalClientDataSourceTransactedTest.java
index 17bb8e4adc69..7d0701b011af 100644
--- 
a/components/camel-spring-parent/camel-spring-xml/src/test/java/org/apache/camel/spring/interceptor/SpringTransactionalClientDataSourceTransactedTest.java
+++ 
b/components/camel-spring-parent/camel-spring-xml/src/test/java/org/apache/camel/spring/interceptor/SpringTransactionalClientDataSourceTransactedTest.java
@@ -27,8 +27,8 @@ import 
org.springframework.context.support.ClassPathXmlApplicationContext;
 import org.springframework.jdbc.core.JdbcTemplate;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
 import static org.junit.jupiter.api.Assertions.assertTrue;
-import static org.junit.jupiter.api.Assertions.fail;
 
 /**
  * Easier transaction configuration as we do not have to setup a transaction 
error handler
@@ -63,15 +63,13 @@ public class 
SpringTransactionalClientDataSourceTransactedTest extends SpringTes
 
     @Test
     public void testTransactionRollback() throws Exception {
-        try {
+        RuntimeCamelException e = assertThrows(RuntimeCamelException.class, () 
-> {
             template.sendBody("direct:fail", "Hello World");
-            fail("Should have thrown exception");
-        } catch (RuntimeCamelException e) {
-            // expected as we fail
-            assertIsInstanceOf(RuntimeCamelException.class, e.getCause());
-            assertTrue(e.getCause().getCause() instanceof 
IllegalArgumentException);
-            assertEquals("We don't have Donkeys, only Camels", 
e.getCause().getCause().getMessage());
-        }
+        });
+        // expected as we fail
+        assertIsInstanceOf(RuntimeCamelException.class, e.getCause());
+        assertTrue(e.getCause().getCause() instanceof 
IllegalArgumentException);
+        assertEquals("We don't have Donkeys, only Camels", 
e.getCause().getCause().getMessage());
 
         int count = jdbc.queryForObject("select count(*) from books", 
Integer.class);
         assertEquals(1, count, "Number of books");
diff --git 
a/components/camel-spring-parent/camel-spring-xml/src/test/java/org/apache/camel/spring/interceptor/TransactionalClientDataSourceMinimalConfigurationTest.java
 
b/components/camel-spring-parent/camel-spring-xml/src/test/java/org/apache/camel/spring/interceptor/TransactionalClientDataSourceMinimalConfigurationTest.java
index c9aa13e823e2..828ec2ae215b 100644
--- 
a/components/camel-spring-parent/camel-spring-xml/src/test/java/org/apache/camel/spring/interceptor/TransactionalClientDataSourceMinimalConfigurationTest.java
+++ 
b/components/camel-spring-parent/camel-spring-xml/src/test/java/org/apache/camel/spring/interceptor/TransactionalClientDataSourceMinimalConfigurationTest.java
@@ -27,8 +27,8 @@ import 
org.springframework.context.support.ClassPathXmlApplicationContext;
 import org.springframework.jdbc.core.JdbcTemplate;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
 import static org.junit.jupiter.api.Assertions.assertTrue;
-import static org.junit.jupiter.api.Assertions.fail;
 
 /**
  * Easier transaction configuration as we only setup Spring TX stuff.
@@ -63,15 +63,13 @@ public class 
TransactionalClientDataSourceMinimalConfigurationTest extends Sprin
 
     @Test
     public void testTransactionRollback() throws Exception {
-        try {
+        RuntimeCamelException e = assertThrows(RuntimeCamelException.class, () 
-> {
             template.sendBody("direct:fail", "Hello World");
-            fail("Should have thrown exception");
-        } catch (RuntimeCamelException e) {
-            // expected as we fail
-            assertIsInstanceOf(RuntimeCamelException.class, e.getCause());
-            assertTrue(e.getCause().getCause() instanceof 
IllegalArgumentException);
-            assertEquals("We don't have Donkeys, only Camels", 
e.getCause().getCause().getMessage());
-        }
+        });
+        // expected as we fail
+        assertIsInstanceOf(RuntimeCamelException.class, e.getCause());
+        assertTrue(e.getCause().getCause() instanceof 
IllegalArgumentException);
+        assertEquals("We don't have Donkeys, only Camels", 
e.getCause().getCause().getMessage());
 
         int count = jdbc.queryForObject("select count(*) from books", 
Integer.class);
         assertEquals(1, count, "Number of books");
diff --git 
a/components/camel-spring-parent/camel-spring-xml/src/test/java/org/apache/camel/spring/issues/SpringCatchNestedFailTest.java
 
b/components/camel-spring-parent/camel-spring-xml/src/test/java/org/apache/camel/spring/issues/SpringCatchNestedFailTest.java
index d2efb64b1f46..7414c0c7364f 100644
--- 
a/components/camel-spring-parent/camel-spring-xml/src/test/java/org/apache/camel/spring/issues/SpringCatchNestedFailTest.java
+++ 
b/components/camel-spring-parent/camel-spring-xml/src/test/java/org/apache/camel/spring/issues/SpringCatchNestedFailTest.java
@@ -23,7 +23,7 @@ import org.junit.jupiter.api.Test;
 
 import static 
org.apache.camel.spring.processor.SpringTestHelper.createSpringCamelContext;
 import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.fail;
+import static org.junit.jupiter.api.Assertions.assertThrows;
 
 public class SpringCatchNestedFailTest extends ContextTestSupport {
 
@@ -69,13 +69,11 @@ public class SpringCatchNestedFailTest extends 
ContextTestSupport {
         getMockEndpoint("mock:catchEnd").expectedMessageCount(0);
         getMockEndpoint("mock:end").expectedMessageCount(0);
 
-        try {
+        CamelExecutionException e = 
assertThrows(CamelExecutionException.class, () -> {
             template.sendBody("direct:start", "Donkey Kong");
-            fail("Should have thrown exception");
-        } catch (CamelExecutionException e) {
-            assertIsInstanceOf(IllegalStateException.class, e.getCause());
-            assertEquals("Damn Kong", e.getCause().getMessage());
-        }
+        });
+        assertIsInstanceOf(IllegalStateException.class, e.getCause());
+        assertEquals("Damn Kong", e.getCause().getMessage());
 
         assertMockEndpointsSatisfied();
     }
diff --git 
a/components/camel-spring-parent/camel-spring-xml/src/test/java/org/apache/camel/spring/issues/SpringFinallyNestedFailTest.java
 
b/components/camel-spring-parent/camel-spring-xml/src/test/java/org/apache/camel/spring/issues/SpringFinallyNestedFailTest.java
index dbccd896d295..52a640db89bd 100644
--- 
a/components/camel-spring-parent/camel-spring-xml/src/test/java/org/apache/camel/spring/issues/SpringFinallyNestedFailTest.java
+++ 
b/components/camel-spring-parent/camel-spring-xml/src/test/java/org/apache/camel/spring/issues/SpringFinallyNestedFailTest.java
@@ -23,7 +23,7 @@ import org.junit.jupiter.api.Test;
 
 import static 
org.apache.camel.spring.processor.SpringTestHelper.createSpringCamelContext;
 import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.fail;
+import static org.junit.jupiter.api.Assertions.assertThrows;
 
 public class SpringFinallyNestedFailTest extends ContextTestSupport {
 
@@ -72,13 +72,11 @@ public class SpringFinallyNestedFailTest extends 
ContextTestSupport {
         getMockEndpoint("mock:finallyEnd").expectedMessageCount(0);
         getMockEndpoint("mock:end").expectedMessageCount(0);
 
-        try {
+        CamelExecutionException e = 
assertThrows(CamelExecutionException.class, () -> {
             template.sendBody("direct:start", "Donkey Kong");
-            fail("Should have thrown exception");
-        } catch (CamelExecutionException e) {
-            assertIsInstanceOf(IllegalStateException.class, e.getCause());
-            assertEquals("Damn Kong", e.getCause().getMessage());
-        }
+        });
+        assertIsInstanceOf(IllegalStateException.class, e.getCause());
+        assertEquals("Damn Kong", e.getCause().getMessage());
 
         assertMockEndpointsSatisfied();
     }
diff --git 
a/components/camel-spring-parent/camel-spring-xml/src/test/java/org/apache/camel/spring/issues/SpringTransactionErrorHandlerAndContextScopedOnExceptionIssueTest.java
 
b/components/camel-spring-parent/camel-spring-xml/src/test/java/org/apache/camel/spring/issues/SpringTransactionErrorHandlerAndContextScopedOnExceptionIssueTest.java
index dfe5d478755f..a35fe6fee6ce 100644
--- 
a/components/camel-spring-parent/camel-spring-xml/src/test/java/org/apache/camel/spring/issues/SpringTransactionErrorHandlerAndContextScopedOnExceptionIssueTest.java
+++ 
b/components/camel-spring-parent/camel-spring-xml/src/test/java/org/apache/camel/spring/issues/SpringTransactionErrorHandlerAndContextScopedOnExceptionIssueTest.java
@@ -28,7 +28,7 @@ import 
org.springframework.context.support.ClassPathXmlApplicationContext;
 import org.springframework.jdbc.core.JdbcTemplate;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.fail;
+import static org.junit.jupiter.api.Assertions.assertThrows;
 
 public class SpringTransactionErrorHandlerAndContextScopedOnExceptionIssueTest 
extends SpringTestSupport {
     protected JdbcTemplate jdbc;
@@ -76,14 +76,12 @@ public class 
SpringTransactionErrorHandlerAndContextScopedOnExceptionIssueTest e
         // we failed so no message to result
         getMockEndpoint("mock:result").expectedMessageCount(0);
 
-        try {
+        CamelExecutionException e = 
assertThrows(CamelExecutionException.class, () -> {
             template.sendBody("direct:start", "Donkey in Action");
-            fail("Should have thrown exception");
-        } catch (CamelExecutionException e) {
-            assertIsInstanceOf(RuntimeCamelException.class, e.getCause());
-            assertIsInstanceOf(IllegalArgumentException.class, 
e.getCause().getCause());
-            assertEquals("We don't have Donkeys, only Camels", 
e.getCause().getCause().getMessage());
-        }
+        });
+        assertIsInstanceOf(RuntimeCamelException.class, e.getCause());
+        assertIsInstanceOf(IllegalArgumentException.class, 
e.getCause().getCause());
+        assertEquals("We don't have Donkeys, only Camels", 
e.getCause().getCause().getMessage());
 
         assertMockEndpointsSatisfied();
 
diff --git 
a/components/camel-spring-parent/camel-spring-xml/src/test/java/org/apache/camel/spring/processor/JavaDslTransactedNoTXManagerTest.java
 
b/components/camel-spring-parent/camel-spring-xml/src/test/java/org/apache/camel/spring/processor/JavaDslTransactedNoTXManagerTest.java
index e0f9537f52c4..8ee93c0d7ca9 100644
--- 
a/components/camel-spring-parent/camel-spring-xml/src/test/java/org/apache/camel/spring/processor/JavaDslTransactedNoTXManagerTest.java
+++ 
b/components/camel-spring-parent/camel-spring-xml/src/test/java/org/apache/camel/spring/processor/JavaDslTransactedNoTXManagerTest.java
@@ -22,7 +22,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;
 
 /**
  *
@@ -39,15 +39,13 @@ public class JavaDslTransactedNoTXManagerTest extends 
ContextTestSupport {
                         .to("mock:result");
             }
         });
-        try {
+        Exception e = assertThrows(Exception.class, () -> {
             context.start();
-            fail("Should have thrown an exception");
-        } catch (Exception e) {
-            NoSuchBeanException cause = 
assertIsInstanceOf(NoSuchBeanException.class, e.getCause());
-            assertEquals(
-                    "No bean could be found in the registry for: 
org.springframework.transaction.PlatformTransactionManager",
-                    cause.getMessage());
-        }
+        });
+        NoSuchBeanException cause = 
assertIsInstanceOf(NoSuchBeanException.class, e.getCause());
+        assertEquals(
+                "No bean could be found in the registry for: 
org.springframework.transaction.PlatformTransactionManager",
+                cause.getMessage());
     }
 
     @Override
diff --git 
a/components/camel-spring-parent/camel-spring-xml/src/test/java/org/apache/camel/spring/processor/SpringDeadLetterChannelInvalidDeadLetterUriTest.java
 
b/components/camel-spring-parent/camel-spring-xml/src/test/java/org/apache/camel/spring/processor/SpringDeadLetterChannelInvalidDeadLetterUriTest.java
index f482375d6d00..c160283fcba2 100644
--- 
a/components/camel-spring-parent/camel-spring-xml/src/test/java/org/apache/camel/spring/processor/SpringDeadLetterChannelInvalidDeadLetterUriTest.java
+++ 
b/components/camel-spring-parent/camel-spring-xml/src/test/java/org/apache/camel/spring/processor/SpringDeadLetterChannelInvalidDeadLetterUriTest.java
@@ -25,7 +25,7 @@ import 
org.springframework.context.support.AbstractXmlApplicationContext;
 import org.springframework.context.support.ClassPathXmlApplicationContext;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.fail;
+import static org.junit.jupiter.api.Assertions.assertThrows;
 
 public class SpringDeadLetterChannelInvalidDeadLetterUriTest extends 
SpringTestSupport {
 
@@ -38,16 +38,14 @@ public class 
SpringDeadLetterChannelInvalidDeadLetterUriTest extends SpringTestS
     @Override
     @BeforeEach
     public void setUp() throws Exception {
-        try {
+        Exception e = assertThrows(Exception.class, () -> {
             super.setUp();
-            fail("Should have thrown an exception");
-        } catch (Exception e) {
-            FailedToCreateRouteException ftcre = 
assertIsInstanceOf(FailedToCreateRouteException.class, e);
-            NoSuchEndpointException cause = 
assertIsInstanceOf(NoSuchEndpointException.class, ftcre.getCause());
-            assertEquals(
-                    "No endpoint could be found for: xxx, please check your 
classpath contains the needed Camel component jar.",
-                    cause.getMessage());
-        }
+        });
+        FailedToCreateRouteException ftcre = 
assertIsInstanceOf(FailedToCreateRouteException.class, e);
+        NoSuchEndpointException cause = 
assertIsInstanceOf(NoSuchEndpointException.class, ftcre.getCause());
+        assertEquals(
+                "No endpoint could be found for: xxx, please check your 
classpath contains the needed Camel component jar.",
+                cause.getMessage());
     }
 
     @Test
diff --git 
a/components/camel-spring-parent/camel-spring-xml/src/test/java/org/apache/camel/spring/processor/SpringDeadLetterChannelInvalidOptionDeadLetterUriTest.java
 
b/components/camel-spring-parent/camel-spring-xml/src/test/java/org/apache/camel/spring/processor/SpringDeadLetterChannelInvalidOptionDeadLetterUriTest.java
index 17d734daab19..b31d33810ef1 100644
--- 
a/components/camel-spring-parent/camel-spring-xml/src/test/java/org/apache/camel/spring/processor/SpringDeadLetterChannelInvalidOptionDeadLetterUriTest.java
+++ 
b/components/camel-spring-parent/camel-spring-xml/src/test/java/org/apache/camel/spring/processor/SpringDeadLetterChannelInvalidOptionDeadLetterUriTest.java
@@ -24,8 +24,8 @@ import org.junit.jupiter.api.Test;
 import org.springframework.context.support.AbstractXmlApplicationContext;
 import org.springframework.context.support.ClassPathXmlApplicationContext;
 
+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 SpringDeadLetterChannelInvalidOptionDeadLetterUriTest extends 
SpringTestSupport {
 
@@ -38,14 +38,12 @@ public class 
SpringDeadLetterChannelInvalidOptionDeadLetterUriTest extends Sprin
     @Override
     @BeforeEach
     public void setUp() throws Exception {
-        try {
+        Exception e = assertThrows(Exception.class, () -> {
             super.setUp();
-            fail("Should have thrown an exception");
-        } catch (Exception e) {
-            FailedToCreateRouteException ftcre = 
assertIsInstanceOf(FailedToCreateRouteException.class, e);
-            ResolveEndpointFailedException cause = 
assertIsInstanceOf(ResolveEndpointFailedException.class, ftcre.getCause());
-            assertTrue(cause.getMessage().endsWith("Unknown 
parameters=[{foo=bar}]"));
-        }
+        });
+        FailedToCreateRouteException ftcre = 
assertIsInstanceOf(FailedToCreateRouteException.class, e);
+        ResolveEndpointFailedException cause = 
assertIsInstanceOf(ResolveEndpointFailedException.class, ftcre.getCause());
+        assertTrue(cause.getMessage().endsWith("Unknown 
parameters=[{foo=bar}]"));
     }
 
     @Test
diff --git 
a/components/camel-spring-parent/camel-spring-xml/src/test/java/org/apache/camel/spring/processor/SpringDoubleLoadBalancerMisconfigurationTest.java
 
b/components/camel-spring-parent/camel-spring-xml/src/test/java/org/apache/camel/spring/processor/SpringDoubleLoadBalancerMisconfigurationTest.java
index f8c57b3a7185..9b18dda14328 100644
--- 
a/components/camel-spring-parent/camel-spring-xml/src/test/java/org/apache/camel/spring/processor/SpringDoubleLoadBalancerMisconfigurationTest.java
+++ 
b/components/camel-spring-parent/camel-spring-xml/src/test/java/org/apache/camel/spring/processor/SpringDoubleLoadBalancerMisconfigurationTest.java
@@ -23,23 +23,21 @@ import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
 
 import static 
org.apache.camel.spring.processor.SpringTestHelper.createSpringCamelContext;
+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 SpringDoubleLoadBalancerMisconfigurationTest extends 
ContextTestSupport {
 
     @Override
     @BeforeEach
     public void setUp() throws Exception {
-        try {
+        Exception e = assertThrows(Exception.class, () -> {
             super.setUp();
-            fail("Should have thrown exception");
-        } catch (Exception e) {
-            FailedToCreateRouteException fe = 
assertIsInstanceOf(FailedToCreateRouteException.class, e);
-            IllegalArgumentException ie = 
assertIsInstanceOf(IllegalArgumentException.class, fe.getCause());
-            assertTrue(ie.getMessage().startsWith(
-                    "Loadbalancer already configured to: RandomLoadBalancer. 
Cannot set it to: LoadBalanceType[RoundRobinLoadBalancer"));
-        }
+        });
+        FailedToCreateRouteException fe = 
assertIsInstanceOf(FailedToCreateRouteException.class, e);
+        IllegalArgumentException ie = 
assertIsInstanceOf(IllegalArgumentException.class, fe.getCause());
+        assertTrue(ie.getMessage().startsWith(
+                "Loadbalancer already configured to: RandomLoadBalancer. 
Cannot set it to: LoadBalanceType[RoundRobinLoadBalancer"));
     }
 
     @Test
diff --git 
a/components/camel-spring-parent/camel-spring-xml/src/test/java/org/apache/camel/spring/processor/SpringErrorHandlerRedeliveryPolicyProfileTest.java
 
b/components/camel-spring-parent/camel-spring-xml/src/test/java/org/apache/camel/spring/processor/SpringErrorHandlerRedeliveryPolicyProfileTest.java
index da3c6d3e72d7..26d811ec28b6 100644
--- 
a/components/camel-spring-parent/camel-spring-xml/src/test/java/org/apache/camel/spring/processor/SpringErrorHandlerRedeliveryPolicyProfileTest.java
+++ 
b/components/camel-spring-parent/camel-spring-xml/src/test/java/org/apache/camel/spring/processor/SpringErrorHandlerRedeliveryPolicyProfileTest.java
@@ -21,7 +21,7 @@ import org.junit.jupiter.api.Test;
 import org.springframework.context.support.AbstractXmlApplicationContext;
 import org.springframework.context.support.ClassPathXmlApplicationContext;
 
-import static org.junit.jupiter.api.Assertions.fail;
+import static org.junit.jupiter.api.Assertions.assertThrows;
 
 public class SpringErrorHandlerRedeliveryPolicyProfileTest extends 
SpringTestSupport {
 
@@ -33,11 +33,8 @@ public class SpringErrorHandlerRedeliveryPolicyProfileTest 
extends SpringTestSup
 
     @Test
     public void testErrorHandlerRedeliveryPolicyProfile() throws Exception {
-        try {
+        assertThrows(Exception.class, () -> {
             template.sendBody("direct:start", "Hello World");
-            fail("Should have thrown an exception");
-        } catch (Exception e) {
-            // expected
-        }
+        });
     }
 }
diff --git 
a/components/camel-spring-parent/camel-spring-xml/src/test/java/org/apache/camel/spring/processor/SpringRouteTopLevelMisconfiguredTest.java
 
b/components/camel-spring-parent/camel-spring-xml/src/test/java/org/apache/camel/spring/processor/SpringRouteTopLevelMisconfiguredTest.java
index c1720ec4ea43..0ca5363f62b5 100644
--- 
a/components/camel-spring-parent/camel-spring-xml/src/test/java/org/apache/camel/spring/processor/SpringRouteTopLevelMisconfiguredTest.java
+++ 
b/components/camel-spring-parent/camel-spring-xml/src/test/java/org/apache/camel/spring/processor/SpringRouteTopLevelMisconfiguredTest.java
@@ -22,39 +22,33 @@ import org.apache.camel.RuntimeCamelException;
 import org.junit.jupiter.api.Test;
 
 import static 
org.apache.camel.spring.processor.SpringTestHelper.createSpringCamelContext;
+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 SpringRouteTopLevelMisconfiguredTest extends ContextTestSupport {
 
     @Override
     protected CamelContext createCamelContext() throws Exception {
-        try {
+        RuntimeCamelException e1 = assertThrows(RuntimeCamelException.class, 
() -> {
             createSpringCamelContext(this,
                     
"org/apache/camel/spring/processor/SpringRouteTopLevelOnExceptionMisconfiguredTest.xml");
-            fail("Should have thrown exception");
-        } catch (RuntimeCamelException e) {
-            IllegalArgumentException iae = 
assertIsInstanceOf(IllegalArgumentException.class, e.getCause());
-            assertTrue(iae.getMessage().startsWith("The output must be added 
as top-level on the route."));
-        }
+        });
+        IllegalArgumentException iae1 = 
assertIsInstanceOf(IllegalArgumentException.class, e1.getCause());
+        assertTrue(iae1.getMessage().startsWith("The output must be added as 
top-level on the route."));
 
-        try {
+        RuntimeCamelException e2 = assertThrows(RuntimeCamelException.class, 
() -> {
             createSpringCamelContext(this,
                     
"org/apache/camel/spring/processor/SpringRouteTopLevelOnCompletionMisconfiguredTest.xml");
-            fail("Should have thrown exception");
-        } catch (RuntimeCamelException e) {
-            IllegalArgumentException iae = 
assertIsInstanceOf(IllegalArgumentException.class, e.getCause());
-            assertTrue(iae.getMessage().startsWith("The output must be added 
as top-level on the route."));
-        }
+        });
+        IllegalArgumentException iae2 = 
assertIsInstanceOf(IllegalArgumentException.class, e2.getCause());
+        assertTrue(iae2.getMessage().startsWith("The output must be added as 
top-level on the route."));
 
-        try {
+        RuntimeCamelException e3 = assertThrows(RuntimeCamelException.class, 
() -> {
             createSpringCamelContext(this,
                     
"org/apache/camel/spring/processor/SpringRouteTopLevelTransactedMisconfiguredTest.xml");
-            fail("Should have thrown exception");
-        } catch (RuntimeCamelException e) {
-            IllegalArgumentException iae = 
assertIsInstanceOf(IllegalArgumentException.class, e.getCause());
-            assertTrue(iae.getMessage().startsWith("The output must be added 
as top-level on the route."));
-        }
+        });
+        IllegalArgumentException iae3 = 
assertIsInstanceOf(IllegalArgumentException.class, e3.getCause());
+        assertTrue(iae3.getMessage().startsWith("The output must be added as 
top-level on the route."));
 
         // return a working context instead, to let this test pass
         return createSpringCamelContext(this, 
"org/apache/camel/spring/processor/convertBody.xml");
diff --git 
a/components/camel-spring-parent/camel-spring-xml/src/test/java/org/apache/camel/spring/processor/SpringTryCatchMustHaveExceptionConfiguredTest.java
 
b/components/camel-spring-parent/camel-spring-xml/src/test/java/org/apache/camel/spring/processor/SpringTryCatchMustHaveExceptionConfiguredTest.java
index 5ca03e959b9d..d8ebedf5d926 100644
--- 
a/components/camel-spring-parent/camel-spring-xml/src/test/java/org/apache/camel/spring/processor/SpringTryCatchMustHaveExceptionConfiguredTest.java
+++ 
b/components/camel-spring-parent/camel-spring-xml/src/test/java/org/apache/camel/spring/processor/SpringTryCatchMustHaveExceptionConfiguredTest.java
@@ -23,21 +23,19 @@ import org.junit.jupiter.api.Test;
 
 import static 
org.apache.camel.spring.processor.SpringTestHelper.createSpringCamelContext;
 import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.fail;
+import static org.junit.jupiter.api.Assertions.assertThrows;
 
 public class SpringTryCatchMustHaveExceptionConfiguredTest extends 
ContextTestSupport {
 
     @Override
     protected CamelContext createCamelContext() throws Exception {
-        try {
+        Exception e = assertThrows(Exception.class, () -> {
             createSpringCamelContext(this,
                     
"org/apache/camel/spring/processor/SpringTryCatchMustHaveExceptionConfiguredTest.xml");
-            fail("Should have thrown exception");
-        } catch (Exception e) {
-            FailedToCreateRouteException ftcre = 
assertIsInstanceOf(FailedToCreateRouteException.class, e);
-            IllegalArgumentException iae = 
assertIsInstanceOf(IllegalArgumentException.class, ftcre.getCause());
-            assertEquals("At least one Exception must be configured to catch", 
iae.getMessage());
-        }
+        });
+        FailedToCreateRouteException ftcre = 
assertIsInstanceOf(FailedToCreateRouteException.class, e);
+        IllegalArgumentException iae = 
assertIsInstanceOf(IllegalArgumentException.class, ftcre.getCause());
+        assertEquals("At least one Exception must be configured to catch", 
iae.getMessage());
 
         // return a working context instead, to let this test pass
         return createSpringCamelContext(this, 
"org/apache/camel/spring/processor/convertBody.xml");
diff --git 
a/components/camel-spring-parent/camel-spring-xml/src/test/java/org/apache/camel/spring/processor/onexception/SpringOnExceptionSubRouteTest.java
 
b/components/camel-spring-parent/camel-spring-xml/src/test/java/org/apache/camel/spring/processor/onexception/SpringOnExceptionSubRouteTest.java
index f6291d9634b7..d2b5a557c005 100644
--- 
a/components/camel-spring-parent/camel-spring-xml/src/test/java/org/apache/camel/spring/processor/onexception/SpringOnExceptionSubRouteTest.java
+++ 
b/components/camel-spring-parent/camel-spring-xml/src/test/java/org/apache/camel/spring/processor/onexception/SpringOnExceptionSubRouteTest.java
@@ -23,7 +23,7 @@ import org.junit.jupiter.api.Test;
 
 import static 
org.apache.camel.spring.processor.SpringTestHelper.createSpringCamelContext;
 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 for onException with the spring DSL.
@@ -77,12 +77,10 @@ public class SpringOnExceptionSubRouteTest extends 
ContextTestSupport {
         MockEndpoint dead = getMockEndpoint("mock:dead");
         dead.expectedMessageCount(0);
 
-        try {
+        Exception e = assertThrows(Exception.class, () -> {
             template.requestBodyAndHeader("direct:start_with_no_handler", 
"Order: kaboom", "customerid", "555");
-            fail("Should throw an Exception");
-        } catch (Exception e) {
-            assertEquals("Cannot order: kaboom", e.getCause().getMessage());
-        }
+        });
+        assertEquals("Cannot order: kaboom", e.getCause().getMessage());
 
         assertMockEndpointsSatisfied();
     }

Reply via email to