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 719a6e70d704c3b8215cdec24ad00508cb69b519
Author: Otavio R. Piske <[email protected]>
AuthorDate: Sat Jan 24 10:45:11 2026 +0100

    CAMEL-21196: modernize exception-based assertions in camel-netty
---
 .../netty/NettyInOutWithForcedNoResponseTest.java  | 12 +++---
 .../component/netty/NettyRequestTimeoutTest.java   | 45 ++++++++++------------
 .../component/netty/NettySuspendResumeTest.java    | 11 ++----
 .../component/netty/ObjectSerializationTest.java   | 11 ++----
 4 files changed, 33 insertions(+), 46 deletions(-)

diff --git 
a/components/camel-netty/src/test/java/org/apache/camel/component/netty/NettyInOutWithForcedNoResponseTest.java
 
b/components/camel-netty/src/test/java/org/apache/camel/component/netty/NettyInOutWithForcedNoResponseTest.java
index 44590106b40f..dc70167c9caa 100644
--- 
a/components/camel-netty/src/test/java/org/apache/camel/component/netty/NettyInOutWithForcedNoResponseTest.java
+++ 
b/components/camel-netty/src/test/java/org/apache/camel/component/netty/NettyInOutWithForcedNoResponseTest.java
@@ -21,8 +21,8 @@ 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.assertThrows;
 import static org.junit.jupiter.api.Assertions.assertTrue;
-import static org.junit.jupiter.api.Assertions.fail;
 
 public class NettyInOutWithForcedNoResponseTest extends BaseNettyTest {
 
@@ -34,12 +34,10 @@ public class NettyInOutWithForcedNoResponseTest extends 
BaseNettyTest {
 
     @Test
     public void testNoResponse() {
-        try {
-            template.requestBody("netty:tcp://localhost:{{port}}", "London");
-            fail("Should throw an exception");
-        } catch (RuntimeCamelException e) {
-            assertTrue(e.getCause().getMessage().startsWith("No response"));
-        }
+        RuntimeCamelException e = assertThrows(RuntimeCamelException.class,
+                () -> template.requestBody("netty:tcp://localhost:{{port}}", 
"London"),
+                "Should throw an exception");
+        assertTrue(e.getCause().getMessage().startsWith("No response"));
     }
 
     @Override
diff --git 
a/components/camel-netty/src/test/java/org/apache/camel/component/netty/NettyRequestTimeoutTest.java
 
b/components/camel-netty/src/test/java/org/apache/camel/component/netty/NettyRequestTimeoutTest.java
index 794ece76f237..901ec1506714 100644
--- 
a/components/camel-netty/src/test/java/org/apache/camel/component/netty/NettyRequestTimeoutTest.java
+++ 
b/components/camel-netty/src/test/java/org/apache/camel/component/netty/NettyRequestTimeoutTest.java
@@ -28,7 +28,6 @@ import static 
org.apache.camel.test.junit5.TestSupport.assertIsInstanceOf;
 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.fail;
 
 public class NettyRequestTimeoutTest extends BaseNettyTest {
 
@@ -41,14 +40,13 @@ public class NettyRequestTimeoutTest extends BaseNettyTest {
 
     @Test
     public void testRequestTimeout() {
-        try {
-            
template.requestBody("netty:tcp://localhost:{{port}}?textline=true&sync=true&requestTimeout=100",
 "Hello Camel",
-                    String.class);
-            fail("Should have thrown exception");
-        } catch (CamelExecutionException e) {
-            ReadTimeoutException cause = 
assertIsInstanceOf(ReadTimeoutException.class, e.getCause());
-            assertNotNull(cause);
-        }
+        CamelExecutionException e = assertThrows(CamelExecutionException.class,
+                () -> 
template.requestBody("netty:tcp://localhost:{{port}}?textline=true&sync=true&requestTimeout=100",
+                        "Hello Camel",
+                        String.class),
+                "Should have thrown exception");
+        ReadTimeoutException cause = 
assertIsInstanceOf(ReadTimeoutException.class, e.getCause());
+        assertNotNull(cause);
     }
 
     @Test
@@ -67,26 +65,23 @@ public class NettyRequestTimeoutTest extends BaseNettyTest {
 
     @Test
     public void testRequestTimeoutViaHeader() {
-        try {
-            
template.requestBodyAndHeader("netty:tcp://localhost:{{port}}?textline=true&sync=true",
 "Hello Camel",
-                    NettyConstants.NETTY_REQUEST_TIMEOUT, 100, String.class);
-            fail("Should have thrown exception");
-        } catch (CamelExecutionException e) {
-            ReadTimeoutException cause = 
assertIsInstanceOf(ReadTimeoutException.class, e.getCause());
-            assertNotNull(cause);
-        }
+        CamelExecutionException e = assertThrows(CamelExecutionException.class,
+                () -> 
template.requestBodyAndHeader("netty:tcp://localhost:{{port}}?textline=true&sync=true",
 "Hello Camel",
+                        NettyConstants.NETTY_REQUEST_TIMEOUT, 100, 
String.class),
+                "Should have thrown exception");
+        ReadTimeoutException cause = 
assertIsInstanceOf(ReadTimeoutException.class, e.getCause());
+        assertNotNull(cause);
     }
 
     @Test
     public void testRequestTimeoutAndOk() {
-        try {
-            
template.requestBody("netty:tcp://localhost:{{port}}?textline=true&sync=true&requestTimeout=100",
 "Hello Camel",
-                    String.class);
-            fail("Should have thrown exception");
-        } catch (CamelExecutionException e) {
-            ReadTimeoutException cause = 
assertIsInstanceOf(ReadTimeoutException.class, e.getCause());
-            assertNotNull(cause);
-        }
+        CamelExecutionException e = assertThrows(CamelExecutionException.class,
+                () -> 
template.requestBody("netty:tcp://localhost:{{port}}?textline=true&sync=true&requestTimeout=100",
+                        "Hello Camel",
+                        String.class),
+                "Should have thrown exception");
+        ReadTimeoutException cause = 
assertIsInstanceOf(ReadTimeoutException.class, e.getCause());
+        assertNotNull(cause);
 
         // now we try again but this time the is no delay on server and thus 
faster
         String out = 
template.requestBody("netty:tcp://localhost:{{port}}?textline=true&sync=true&requestTimeout=100",
diff --git 
a/components/camel-netty/src/test/java/org/apache/camel/component/netty/NettySuspendResumeTest.java
 
b/components/camel-netty/src/test/java/org/apache/camel/component/netty/NettySuspendResumeTest.java
index 7650801d5746..af905bece81a 100644
--- 
a/components/camel-netty/src/test/java/org/apache/camel/component/netty/NettySuspendResumeTest.java
+++ 
b/components/camel-netty/src/test/java/org/apache/camel/component/netty/NettySuspendResumeTest.java
@@ -21,7 +21,7 @@ import org.apache.camel.component.mock.MockEndpoint;
 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;
 
 public class NettySuspendResumeTest extends BaseNettyTest {
 
@@ -34,12 +34,9 @@ public class NettySuspendResumeTest extends BaseNettyTest {
 
         context.getRouteController().suspendRoute("foo");
 
-        try {
-            
template.requestBody("netty:tcp://localhost:{{port}}?sync=true&disconnect=true",
 "World", String.class);
-            fail("Should not allow connecting as its suspended");
-        } catch (Exception e) {
-            // expected
-        }
+        assertThrows(Exception.class,
+                () -> 
template.requestBody("netty:tcp://localhost:{{port}}?sync=true&disconnect=true",
 "World", String.class),
+                "Should not allow connecting as its suspended");
 
         context.getRouteController().resumeRoute("foo");
 
diff --git 
a/components/camel-netty/src/test/java/org/apache/camel/component/netty/ObjectSerializationTest.java
 
b/components/camel-netty/src/test/java/org/apache/camel/component/netty/ObjectSerializationTest.java
index 1a251bd7b12c..636991037f6f 100644
--- 
a/components/camel-netty/src/test/java/org/apache/camel/component/netty/ObjectSerializationTest.java
+++ 
b/components/camel-netty/src/test/java/org/apache/camel/component/netty/ObjectSerializationTest.java
@@ -33,7 +33,7 @@ import org.junit.jupiter.api.BeforeAll;
 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;
 
 /**
  * Object Serialization is not allowed by default. However it can be enabled 
by adding specific encoders/decoders.
@@ -50,12 +50,9 @@ public class ObjectSerializationTest extends BaseNettyTest {
     @Test
     public void testObjectSerializationFailureByDefault() {
         Date date = new Date();
-        try {
-            Object o = 
template.requestBody("netty:tcp://localhost:{{port}}?sync=true&encoders=#encoder",
 date, Date.class);
-            fail("Should have thrown exception");
-        } catch (CamelExecutionException e) {
-            // expected
-        }
+        assertThrows(CamelExecutionException.class,
+                () -> 
template.requestBody("netty:tcp://localhost:{{port}}?sync=true&encoders=#encoder",
 date, Date.class),
+                "Should have thrown exception");
     }
 
     @Test

Reply via email to