You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by or...@apache.org on 2026/01/25 05:32:25 UTC
(camel) 02/04: CAMEL-21196: modernize exception-based assertions in camel-management
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 8c0623f9c509af635e98a47e408769d6f2dc0f9b
Author: Otavio Rodolfo Piske <an...@gmail.com>
AuthorDate: Sat Jan 24 17:10:56 2026 +0000
CAMEL-21196: modernize exception-based assertions in camel-management
---
.../JmxInstrumentationUsingPlatformMBSTest.java | 10 +++------
.../JmxNotificationEventNotifierTest.java | 11 +++------
.../camel/management/LoggingEventNotifierTest.java | 11 +++------
.../ManagedBrowsableEndpointAsJSonTest.java | 12 +++++-----
.../ManagedBrowsableEndpointAsXmlTest.java | 15 +++++--------
.../camel/management/ManagedDuplicateIdTest.java | 26 ++++++++--------------
.../ManagedRouteUpdateRouteFromXmlTest.java | 14 +++++-------
.../ManagedRouteWithOnExceptionTest.java | 16 +++----------
.../camel/management/ManagedStartupFailedTest.java | 9 ++------
.../ManagedTypeConverterRegistryTest.java | 9 ++------
.../camel/management/PublishEventNotifierTest.java | 11 +++------
.../PublishEventNotifierToRouteTest.java | 11 +++------
.../TwoManagedCamelContextClashTest.java | 10 +++------
.../apache/camel/processor/NoErrorHandlerTest.java | 16 +++----------
14 files changed, 54 insertions(+), 127 deletions(-)
diff --git a/core/camel-management/src/test/java/org/apache/camel/management/JmxInstrumentationUsingPlatformMBSTest.java b/core/camel-management/src/test/java/org/apache/camel/management/JmxInstrumentationUsingPlatformMBSTest.java
index 815c29d760ab..fbaf242b9c8a 100644
--- a/core/camel-management/src/test/java/org/apache/camel/management/JmxInstrumentationUsingPlatformMBSTest.java
+++ b/core/camel-management/src/test/java/org/apache/camel/management/JmxInstrumentationUsingPlatformMBSTest.java
@@ -33,7 +33,7 @@ import org.junit.jupiter.api.condition.OS;
import org.junit.jupiter.api.parallel.ResourceLock;
import org.junit.jupiter.api.parallel.Resources;
-import static org.junit.jupiter.api.Assertions.fail;
+import static org.junit.jupiter.api.Assertions.assertThrows;
/**
* This test verifies the system property to un-select platform mbean server.
@@ -59,12 +59,8 @@ public class JmxInstrumentationUsingPlatformMBSTest extends JmxInstrumentationUs
@Override
@Test
public void testMBeanServerType() throws Exception {
- try {
- mbsc.getMBeanInfo(new ObjectName("java.lang:type=OperatingSystem"));
- fail(); // should not get here
- } catch (InstanceNotFoundException e) {
- // expected
- }
+ assertThrows(InstanceNotFoundException.class,
+ () -> mbsc.getMBeanInfo(new ObjectName("java.lang:type=OperatingSystem")));
}
@Override
diff --git a/core/camel-management/src/test/java/org/apache/camel/management/JmxNotificationEventNotifierTest.java b/core/camel-management/src/test/java/org/apache/camel/management/JmxNotificationEventNotifierTest.java
index 3e46a7bbb050..1785833dc61b 100644
--- a/core/camel-management/src/test/java/org/apache/camel/management/JmxNotificationEventNotifierTest.java
+++ b/core/camel-management/src/test/java/org/apache/camel/management/JmxNotificationEventNotifierTest.java
@@ -30,7 +30,7 @@ import org.junit.jupiter.api.condition.OS;
import static org.apache.camel.management.DefaultManagementObjectNameStrategy.TYPE_EVENT_NOTIFIER;
import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.fail;
+import static org.junit.jupiter.api.Assertions.assertThrows;
@DisabledOnOs(OS.AIX)
public class JmxNotificationEventNotifierTest extends ManagementTestSupport {
@@ -94,13 +94,8 @@ public class JmxNotificationEventNotifierTest extends ManagementTestSupport {
}
}, null);
- try {
- template.sendBody("direct:fail", "Hello World");
- fail("Should have thrown an exception");
- } catch (Exception e) {
- // expected
- assertIsInstanceOf(IllegalArgumentException.class, e.getCause());
- }
+ Exception e = assertThrows(Exception.class, () -> template.sendBody("direct:fail", "Hello World"));
+ assertIsInstanceOf(IllegalArgumentException.class, e.getCause());
assertEquals(4, listener.getEventCounter(), "Get a wrong number of events");
diff --git a/core/camel-management/src/test/java/org/apache/camel/management/LoggingEventNotifierTest.java b/core/camel-management/src/test/java/org/apache/camel/management/LoggingEventNotifierTest.java
index 8c728796acd1..61153ce538b0 100644
--- a/core/camel-management/src/test/java/org/apache/camel/management/LoggingEventNotifierTest.java
+++ b/core/camel-management/src/test/java/org/apache/camel/management/LoggingEventNotifierTest.java
@@ -24,7 +24,7 @@ import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.DisabledOnOs;
import org.junit.jupiter.api.condition.OS;
-import static org.junit.jupiter.api.Assertions.fail;
+import static org.junit.jupiter.api.Assertions.assertThrows;
@DisabledOnOs(OS.AIX)
public class LoggingEventNotifierTest extends ContextTestSupport {
@@ -61,13 +61,8 @@ public class LoggingEventNotifierTest extends ContextTestSupport {
@Test
public void testExchangeFailed() {
- try {
- template.sendBody("direct:fail", "Hello World");
- fail("Should have thrown an exception");
- } catch (Exception e) {
- // expected
- assertIsInstanceOf(IllegalArgumentException.class, e.getCause());
- }
+ Exception e = assertThrows(Exception.class, () -> template.sendBody("direct:fail", "Hello World"));
+ assertIsInstanceOf(IllegalArgumentException.class, e.getCause());
context.stop();
}
diff --git a/core/camel-management/src/test/java/org/apache/camel/management/ManagedBrowsableEndpointAsJSonTest.java b/core/camel-management/src/test/java/org/apache/camel/management/ManagedBrowsableEndpointAsJSonTest.java
index 4e084df780cf..a14aa5017225 100644
--- a/core/camel-management/src/test/java/org/apache/camel/management/ManagedBrowsableEndpointAsJSonTest.java
+++ b/core/camel-management/src/test/java/org/apache/camel/management/ManagedBrowsableEndpointAsJSonTest.java
@@ -31,8 +31,8 @@ import static org.apache.camel.management.DefaultManagementObjectNameStrategy.TY
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
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;
@DisabledOnOs(OS.AIX)
public class ManagedBrowsableEndpointAsJSonTest extends ManagementTestSupport {
@@ -184,14 +184,12 @@ public class ManagedBrowsableEndpointAsJSonTest extends ManagementTestSupport {
ObjectName name = getCamelObjectName(TYPE_ENDPOINT, "mock://result");
- try {
+ Exception e = assertThrows(Exception.class, () -> {
mbeanServer.invoke(name, "browseRangeMessagesAsJSon", new Object[] { 3, 1, false },
new String[] { "java.lang.Integer", "java.lang.Integer", "java.lang.Boolean" });
- fail("Should have thrown exception");
- } catch (Exception e) {
- assertIsInstanceOf(IllegalArgumentException.class, e.getCause());
- assertEquals("From index cannot be larger than to index, was: 3 > 1", e.getCause().getMessage());
- }
+ });
+ assertIsInstanceOf(IllegalArgumentException.class, e.getCause());
+ assertEquals("From index cannot be larger than to index, was: 3 > 1", e.getCause().getMessage());
}
@Override
diff --git a/core/camel-management/src/test/java/org/apache/camel/management/ManagedBrowsableEndpointAsXmlTest.java b/core/camel-management/src/test/java/org/apache/camel/management/ManagedBrowsableEndpointAsXmlTest.java
index a1abb737f4bf..332de6d3ebeb 100644
--- a/core/camel-management/src/test/java/org/apache/camel/management/ManagedBrowsableEndpointAsXmlTest.java
+++ b/core/camel-management/src/test/java/org/apache/camel/management/ManagedBrowsableEndpointAsXmlTest.java
@@ -32,7 +32,7 @@ import org.junit.jupiter.api.condition.OS;
import static org.apache.camel.management.DefaultManagementObjectNameStrategy.TYPE_ENDPOINT;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
-import static org.junit.jupiter.api.Assertions.fail;
+import static org.junit.jupiter.api.Assertions.assertThrows;
@DisabledOnOs(OS.AIX)
public class ManagedBrowsableEndpointAsXmlTest extends ManagementTestSupport {
@@ -297,14 +297,11 @@ public class ManagedBrowsableEndpointAsXmlTest extends ManagementTestSupport {
ObjectName name = getCamelObjectName(TYPE_ENDPOINT, "mock://result");
- try {
- mbeanServer.invoke(name, "browseRangeMessagesAsXml", new Object[] { 3, 1, false },
- new String[] { "java.lang.Integer", "java.lang.Integer", "java.lang.Boolean" });
- fail("Should have thrown exception");
- } catch (Exception e) {
- assertIsInstanceOf(IllegalArgumentException.class, e.getCause());
- assertEquals("From index cannot be larger than to index, was: 3 > 1", e.getCause().getMessage());
- }
+ Exception e = assertThrows(Exception.class, () -> mbeanServer.invoke(name, "browseRangeMessagesAsXml",
+ new Object[] { 3, 1, false },
+ new String[] { "java.lang.Integer", "java.lang.Integer", "java.lang.Boolean" }));
+ assertIsInstanceOf(IllegalArgumentException.class, e.getCause());
+ assertEquals("From index cannot be larger than to index, was: 3 > 1", e.getCause().getMessage());
}
@Override
diff --git a/core/camel-management/src/test/java/org/apache/camel/management/ManagedDuplicateIdTest.java b/core/camel-management/src/test/java/org/apache/camel/management/ManagedDuplicateIdTest.java
index f5b4a8477249..ccf164b2e691 100644
--- a/core/camel-management/src/test/java/org/apache/camel/management/ManagedDuplicateIdTest.java
+++ b/core/camel-management/src/test/java/org/apache/camel/management/ManagedDuplicateIdTest.java
@@ -22,7 +22,7 @@ import org.junit.jupiter.api.condition.DisabledOnOs;
import org.junit.jupiter.api.condition.OS;
import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.fail;
+import static org.junit.jupiter.api.Assertions.assertThrows;
@DisabledOnOs(OS.AIX)
public class ManagedDuplicateIdTest extends ManagementTestSupport {
@@ -47,14 +47,10 @@ public class ManagedDuplicateIdTest extends ManagementTestSupport {
.to("mock:bar");
}
});
- try {
- context.start();
- fail("Should fail");
- } catch (Exception e) {
- assertEquals(
- "Failed to start route: foo because: Duplicate id detected: clash. Please correct ids to be unique among all your routes.",
- e.getMessage());
- }
+ Exception e = assertThrows(Exception.class, () -> context.start());
+ assertEquals(
+ "Failed to start route: foo because: Duplicate id detected: clash. Please correct ids to be unique among all your routes.",
+ e.getMessage());
}
@Test
@@ -71,14 +67,10 @@ public class ManagedDuplicateIdTest extends ManagementTestSupport {
.to("mock:foo");
}
});
- try {
- context.start();
- fail("Should fail");
- } catch (Exception e) {
- assertEquals(
- "Failed to start route: foo because: Duplicate id detected: clash. Please correct ids to be unique among all your routes.",
- e.getMessage());
- }
+ Exception e = assertThrows(Exception.class, () -> context.start());
+ assertEquals(
+ "Failed to start route: foo because: Duplicate id detected: clash. Please correct ids to be unique among all your routes.",
+ e.getMessage());
}
@Override
diff --git a/core/camel-management/src/test/java/org/apache/camel/management/ManagedRouteUpdateRouteFromXmlTest.java b/core/camel-management/src/test/java/org/apache/camel/management/ManagedRouteUpdateRouteFromXmlTest.java
index 81362f641c45..3998bd25217e 100644
--- a/core/camel-management/src/test/java/org/apache/camel/management/ManagedRouteUpdateRouteFromXmlTest.java
+++ b/core/camel-management/src/test/java/org/apache/camel/management/ManagedRouteUpdateRouteFromXmlTest.java
@@ -29,7 +29,7 @@ import org.junit.jupiter.api.condition.DisabledOnOs;
import org.junit.jupiter.api.condition.OS;
import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.fail;
+import static org.junit.jupiter.api.Assertions.assertThrows;
@DisabledOnOs(OS.AIX)
public class ManagedRouteUpdateRouteFromXmlTest extends ManagementTestSupport {
@@ -132,14 +132,12 @@ public class ManagedRouteUpdateRouteFromXmlTest extends ManagementTestSupport {
+ " <to uri=\"mock:changed\"/>"
+ "</route>";
- try {
+ Exception e = assertThrows(Exception.class, () -> {
mbeanServer.invoke(on, "updateRouteFromXml", new Object[] { xml }, new String[] { "java.lang.String" });
- fail("Should have thrown exception");
- } catch (Exception e) {
- assertIsInstanceOf(IllegalArgumentException.class, e.getCause());
- assertEquals("Cannot update route from XML as routeIds does not match. routeId: myRoute, routeId from XML: foo",
- e.getCause().getMessage());
- }
+ });
+ assertIsInstanceOf(IllegalArgumentException.class, e.getCause());
+ assertEquals("Cannot update route from XML as routeIds does not match. routeId: myRoute, routeId from XML: foo",
+ e.getCause().getMessage());
}
static ObjectName getRouteObjectName(MBeanServer mbeanServer) throws Exception {
diff --git a/core/camel-management/src/test/java/org/apache/camel/management/ManagedRouteWithOnExceptionTest.java b/core/camel-management/src/test/java/org/apache/camel/management/ManagedRouteWithOnExceptionTest.java
index 2e87970abb06..f5e133e4b755 100644
--- a/core/camel-management/src/test/java/org/apache/camel/management/ManagedRouteWithOnExceptionTest.java
+++ b/core/camel-management/src/test/java/org/apache/camel/management/ManagedRouteWithOnExceptionTest.java
@@ -22,7 +22,7 @@ import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.DisabledOnOs;
import org.junit.jupiter.api.condition.OS;
-import static org.junit.jupiter.api.Assertions.fail;
+import static org.junit.jupiter.api.Assertions.assertThrows;
@DisabledOnOs(OS.AIX)
public class ManagedRouteWithOnExceptionTest extends ManagementTestSupport {
@@ -42,12 +42,7 @@ public class ManagedRouteWithOnExceptionTest extends ManagementTestSupport {
getMockEndpoint("mock:error").expectedMessageCount(1);
getMockEndpoint("mock:result").expectedMessageCount(0);
- try {
- template.sendBody("direct:start", "Kaboom");
- fail("Should have thrown an exception");
- } catch (CamelExecutionException e) {
- // expected
- }
+ assertThrows(CamelExecutionException.class, () -> template.sendBody("direct:start", "Kaboom"));
assertMockEndpointsSatisfied();
}
@@ -58,12 +53,7 @@ public class ManagedRouteWithOnExceptionTest extends ManagementTestSupport {
getMockEndpoint("mock:result").expectedMessageCount(1);
template.sendBody("direct:start", "Hello World");
- try {
- template.sendBody("direct:start", "Kaboom");
- fail("Should have thrown an exception");
- } catch (CamelExecutionException e) {
- // expected
- }
+ assertThrows(CamelExecutionException.class, () -> template.sendBody("direct:start", "Kaboom"));
assertMockEndpointsSatisfied();
}
diff --git a/core/camel-management/src/test/java/org/apache/camel/management/ManagedStartupFailedTest.java b/core/camel-management/src/test/java/org/apache/camel/management/ManagedStartupFailedTest.java
index 396752387fb0..4a9969ac6fe1 100644
--- a/core/camel-management/src/test/java/org/apache/camel/management/ManagedStartupFailedTest.java
+++ b/core/camel-management/src/test/java/org/apache/camel/management/ManagedStartupFailedTest.java
@@ -31,7 +31,7 @@ import org.junit.jupiter.api.condition.OS;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNull;
-import static org.junit.jupiter.api.Assertions.fail;
+import static org.junit.jupiter.api.Assertions.assertThrows;
@DisabledOnOs(OS.AIX)
public class ManagedStartupFailedTest extends ManagementTestSupport {
@@ -77,12 +77,7 @@ public class ManagedStartupFailedTest extends ManagementTestSupport {
}
});
- try {
- context.start();
- fail("Startup failure expected");
- } catch (Exception ex) {
- // expected
- }
+ assertThrows(Exception.class, () -> context.start());
MBeanServer server = getMBeanServer();
assertNull(server);
diff --git a/core/camel-management/src/test/java/org/apache/camel/management/ManagedTypeConverterRegistryTest.java b/core/camel-management/src/test/java/org/apache/camel/management/ManagedTypeConverterRegistryTest.java
index 979cb676be00..8358e5c0bba7 100644
--- a/core/camel-management/src/test/java/org/apache/camel/management/ManagedTypeConverterRegistryTest.java
+++ b/core/camel-management/src/test/java/org/apache/camel/management/ManagedTypeConverterRegistryTest.java
@@ -32,8 +32,8 @@ import static org.apache.camel.management.DefaultManagementObjectNameStrategy.TY
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
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;
@DisabledOnOs(OS.AIX)
public class ManagedTypeConverterRegistryTest extends ManagementTestSupport {
@@ -85,12 +85,7 @@ public class ManagedTypeConverterRegistryTest extends ManagementTestSupport {
// reset
mbeanServer.invoke(name, "resetTypeConversionCounters", null, null);
- try {
- template.sendBody("direct:start", "foo");
- fail("Should have thrown exception");
- } catch (Exception e) {
- // expected
- }
+ assertThrows(Exception.class, () -> template.sendBody("direct:start", "foo"));
// should now have a failed
failed = (Long) mbeanServer.getAttribute(name, "FailedCounter");
diff --git a/core/camel-management/src/test/java/org/apache/camel/management/PublishEventNotifierTest.java b/core/camel-management/src/test/java/org/apache/camel/management/PublishEventNotifierTest.java
index 7d070d373569..7ebf38381cab 100644
--- a/core/camel-management/src/test/java/org/apache/camel/management/PublishEventNotifierTest.java
+++ b/core/camel-management/src/test/java/org/apache/camel/management/PublishEventNotifierTest.java
@@ -24,7 +24,7 @@ import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.DisabledOnOs;
import org.junit.jupiter.api.condition.OS;
-import static org.junit.jupiter.api.Assertions.fail;
+import static org.junit.jupiter.api.Assertions.assertThrows;
@DisabledOnOs(OS.AIX)
public class PublishEventNotifierTest extends ContextTestSupport {
@@ -61,13 +61,8 @@ public class PublishEventNotifierTest extends ContextTestSupport {
public void testExchangeFailed() throws Exception {
getMockEndpoint("mock:event").expectedMessageCount(5);
- try {
- template.sendBody("direct:fail", "Hello World");
- fail("Should have thrown an exception");
- } catch (Exception e) {
- // expected
- assertIsInstanceOf(IllegalArgumentException.class, e.getCause());
- }
+ Exception e = assertThrows(Exception.class, () -> template.sendBody("direct:fail", "Hello World"));
+ assertIsInstanceOf(IllegalArgumentException.class, e.getCause());
assertMockEndpointsSatisfied();
}
diff --git a/core/camel-management/src/test/java/org/apache/camel/management/PublishEventNotifierToRouteTest.java b/core/camel-management/src/test/java/org/apache/camel/management/PublishEventNotifierToRouteTest.java
index 954eaf36aee7..11d4f5cdb791 100644
--- a/core/camel-management/src/test/java/org/apache/camel/management/PublishEventNotifierToRouteTest.java
+++ b/core/camel-management/src/test/java/org/apache/camel/management/PublishEventNotifierToRouteTest.java
@@ -24,7 +24,7 @@ import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.DisabledOnOs;
import org.junit.jupiter.api.condition.OS;
-import static org.junit.jupiter.api.Assertions.fail;
+import static org.junit.jupiter.api.Assertions.assertThrows;
@DisabledOnOs(OS.AIX)
public class PublishEventNotifierToRouteTest extends ContextTestSupport {
@@ -61,13 +61,8 @@ public class PublishEventNotifierToRouteTest extends ContextTestSupport {
public void testExchangeFailed() throws Exception {
getMockEndpoint("mock:event").expectedMinimumMessageCount(4);
- try {
- template.sendBody("direct:fail", "Hello World");
- fail("Should have thrown an exception");
- } catch (Exception e) {
- // expected
- assertIsInstanceOf(IllegalArgumentException.class, e.getCause());
- }
+ Exception e = assertThrows(Exception.class, () -> template.sendBody("direct:fail", "Hello World"));
+ assertIsInstanceOf(IllegalArgumentException.class, e.getCause());
assertMockEndpointsSatisfied();
}
diff --git a/core/camel-management/src/test/java/org/apache/camel/management/TwoManagedCamelContextClashTest.java b/core/camel-management/src/test/java/org/apache/camel/management/TwoManagedCamelContextClashTest.java
index 551f1515070b..8f7449d0dac6 100644
--- a/core/camel-management/src/test/java/org/apache/camel/management/TwoManagedCamelContextClashTest.java
+++ b/core/camel-management/src/test/java/org/apache/camel/management/TwoManagedCamelContextClashTest.java
@@ -28,8 +28,8 @@ import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.DisabledOnOs;
import org.junit.jupiter.api.condition.OS;
+import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
-import static org.junit.jupiter.api.Assertions.fail;
@DisabledOnOs(OS.AIX)
public class TwoManagedCamelContextClashTest extends TestSupport {
@@ -101,12 +101,8 @@ public class TwoManagedCamelContextClashTest extends TestSupport {
assertTrue(mbeanServer.isRegistered(on), "Should be registered");
// we use fixed names, so we will get a clash
- try {
- camel2.start();
- fail("Should have thrown an exception");
- } catch (Exception e) {
- assertTrue(e.getCause().getMessage().contains("is already registered"));
- }
+ Exception e = assertThrows(Exception.class, () -> camel2.start());
+ assertTrue(e.getCause().getMessage().contains("is already registered"));
}
private static ObjectName getContextObjectName(CamelContext context) throws MalformedObjectNameException {
diff --git a/core/camel-management/src/test/java/org/apache/camel/processor/NoErrorHandlerTest.java b/core/camel-management/src/test/java/org/apache/camel/processor/NoErrorHandlerTest.java
index 883418742d63..cc69bc659be1 100644
--- a/core/camel-management/src/test/java/org/apache/camel/processor/NoErrorHandlerTest.java
+++ b/core/camel-management/src/test/java/org/apache/camel/processor/NoErrorHandlerTest.java
@@ -22,7 +22,7 @@ import org.apache.camel.component.mock.MockEndpoint;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
-import static org.junit.jupiter.api.Assertions.fail;
+import static org.junit.jupiter.api.Assertions.assertThrows;
public class NoErrorHandlerTest extends ContextTestSupport {
@@ -54,18 +54,8 @@ public class NoErrorHandlerTest extends ContextTestSupport {
MockEndpoint mock = getMockEndpoint("mock:result");
mock.expectedBodiesReceived("Goodday World");
- try {
- template.sendBody("direct:start", "Hello World");
- fail("Should have thrown an exception");
- } catch (Exception e) {
- // expected
- }
- try {
- template.sendBody("direct:start", "Bye World");
- fail("Should have thrown an exception");
- } catch (Exception e) {
- // expected
- }
+ assertThrows(Exception.class, () -> template.sendBody("direct:start", "Hello World"));
+ assertThrows(Exception.class, () -> template.sendBody("direct:start", "Bye World"));
template.sendBody("direct:start", "Goodday World");
assertMockEndpointsSatisfied();