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 13063a50b4e3d8e816d6ba96c26bc2d7e1855dd5
Author: Otavio R. Piske <[email protected]>
AuthorDate: Sat Jan 24 10:56:26 2026 +0100

    CAMEL-21196: modernize exception-based assertions in camel-netty-http
---
 .../netty/http/NettyHttp500ErrorTest.java          | 16 ++++++-------
 ...ettyHttp500ErrorThrowExceptionOnServerTest.java | 22 ++++++++---------
 ...tpBasicAuthCustomSecurityAuthenticatorTest.java | 14 +++++------
 ...ttyHttpProducerThrowExceptionOnFailureTest.java | 24 ++++++++-----------
 .../http/NettyHttpRedirectNoLocationTest.java      | 20 +++++++---------
 .../netty/http/NettyHttpRedirectTest.java          | 20 +++++++---------
 .../netty/http/NettyHttpRequestTimeoutTest.java    | 16 ++++++-------
 .../netty/http/NettyHttpSuspendResume503Test.java  | 14 +++++------
 .../netty/http/NettyHttpSuspendResumeTest.java     | 12 ++++------
 .../netty/http/NettyHttpTransferExceptionTest.java | 16 ++++++-------
 ...woRoutesValidateBootstrapConfigurationTest.java | 12 ++++------
 .../netty/http/SpringNettyHttpBasicAuthTest.java   | 28 ++++++++++------------
 .../rest/RestNettyHttpBindingModeJsonTest.java     | 11 ++++-----
 .../http/rest/RestNettyHttpBindingModeXmlTest.java | 11 ++++-----
 .../http/rest/RestNettyMethodNotAllowedTest.java   | 26 ++++++++++----------
 15 files changed, 113 insertions(+), 149 deletions(-)

diff --git 
a/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttp500ErrorTest.java
 
b/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttp500ErrorTest.java
index 617b25d4e85b..94d774ca18f3 100644
--- 
a/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttp500ErrorTest.java
+++ 
b/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttp500ErrorTest.java
@@ -25,7 +25,7 @@ import org.junit.jupiter.api.Test;
 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.fail;
+import static org.junit.jupiter.api.Assertions.assertThrows;
 
 public class NettyHttp500ErrorTest extends BaseNettyTestSupport {
 
@@ -33,14 +33,12 @@ public class NettyHttp500ErrorTest extends 
BaseNettyTestSupport {
     public void testHttp500Error() throws Exception {
         getMockEndpoint("mock:input").expectedBodiesReceived("Hello World");
 
-        try {
-            template.requestBody("netty-http:http://localhost:{{port}}/foo";, 
"Hello World", String.class);
-            fail("Should have failed");
-        } catch (CamelExecutionException e) {
-            NettyHttpOperationFailedException cause = 
assertIsInstanceOf(NettyHttpOperationFailedException.class, e.getCause());
-            assertEquals(500, cause.getStatusCode());
-            assertEquals("Camel cannot do this", cause.getContentAsString());
-        }
+        CamelExecutionException e = assertThrows(CamelExecutionException.class,
+                () -> 
template.requestBody("netty-http:http://localhost:{{port}}/foo";, "Hello World", 
String.class),
+                "Should have failed");
+        NettyHttpOperationFailedException cause = 
assertIsInstanceOf(NettyHttpOperationFailedException.class, e.getCause());
+        assertEquals(500, cause.getStatusCode());
+        assertEquals("Camel cannot do this", cause.getContentAsString());
 
         MockEndpoint.assertIsSatisfied(context);
     }
diff --git 
a/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttp500ErrorThrowExceptionOnServerTest.java
 
b/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttp500ErrorThrowExceptionOnServerTest.java
index 4b0687fb777d..940658cf9c1f 100644
--- 
a/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttp500ErrorThrowExceptionOnServerTest.java
+++ 
b/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttp500ErrorThrowExceptionOnServerTest.java
@@ -24,8 +24,8 @@ import org.junit.jupiter.api.Test;
 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.assertTrue;
-import static org.junit.jupiter.api.Assertions.fail;
 
 public class NettyHttp500ErrorThrowExceptionOnServerTest extends 
BaseNettyTestSupport {
 
@@ -33,17 +33,15 @@ public class NettyHttp500ErrorThrowExceptionOnServerTest 
extends BaseNettyTestSu
     public void testHttp500Error() throws Exception {
         getMockEndpoint("mock:input").expectedBodiesReceived("Hello World");
 
-        try {
-            template.requestBody("netty-http:http://localhost:{{port}}/foo";, 
"Hello World", String.class);
-            fail("Should have failed");
-        } catch (CamelExecutionException e) {
-            NettyHttpOperationFailedException cause = 
assertIsInstanceOf(NettyHttpOperationFailedException.class, e.getCause());
-            assertEquals(500, cause.getStatusCode());
-            String trace = cause.getContentAsString();
-            assertNotNull(trace);
-            assertTrue(trace.startsWith("java.lang.IllegalArgumentException: 
Camel cannot do this"));
-            assertEquals("http://localhost:"; + getPort() + "/foo", 
cause.getUri());
-        }
+        CamelExecutionException e = assertThrows(CamelExecutionException.class,
+                () -> 
template.requestBody("netty-http:http://localhost:{{port}}/foo";, "Hello World", 
String.class),
+                "Should have failed");
+        NettyHttpOperationFailedException cause = 
assertIsInstanceOf(NettyHttpOperationFailedException.class, e.getCause());
+        assertEquals(500, cause.getStatusCode());
+        String trace = cause.getContentAsString();
+        assertNotNull(trace);
+        assertTrue(trace.startsWith("java.lang.IllegalArgumentException: Camel 
cannot do this"));
+        assertEquals("http://localhost:"; + getPort() + "/foo", cause.getUri());
 
         MockEndpoint.assertIsSatisfied(context);
     }
diff --git 
a/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttpBasicAuthCustomSecurityAuthenticatorTest.java
 
b/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttpBasicAuthCustomSecurityAuthenticatorTest.java
index 2d8da2a033cf..098a1c31e265 100644
--- 
a/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttpBasicAuthCustomSecurityAuthenticatorTest.java
+++ 
b/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttpBasicAuthCustomSecurityAuthenticatorTest.java
@@ -30,7 +30,7 @@ import org.junit.jupiter.api.Test;
 import static org.apache.camel.test.junit5.TestSupport.assertIsInstanceOf;
 import static org.awaitility.Awaitility.await;
 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 NettyHttpBasicAuthCustomSecurityAuthenticatorTest extends 
BaseNettyTestSupport {
 
@@ -39,13 +39,11 @@ public class 
NettyHttpBasicAuthCustomSecurityAuthenticatorTest extends BaseNetty
 
     @Test
     public void testBasicAuth() throws Exception {
-        try {
-            template.requestBody("netty-http:http://localhost:{{port}}/foo";, 
"Hello World", String.class);
-            fail("Should send back 401");
-        } catch (CamelExecutionException e) {
-            NettyHttpOperationFailedException cause = 
assertIsInstanceOf(NettyHttpOperationFailedException.class, e.getCause());
-            assertEquals(401, cause.getStatusCode());
-        }
+        CamelExecutionException e = assertThrows(CamelExecutionException.class,
+                () -> 
template.requestBody("netty-http:http://localhost:{{port}}/foo";, "Hello World", 
String.class),
+                "Should send back 401");
+        NettyHttpOperationFailedException cause = 
assertIsInstanceOf(NettyHttpOperationFailedException.class, e.getCause());
+        assertEquals(401, cause.getStatusCode());
 
         // wait a little bit before next as the connection was closed when
         // denied
diff --git 
a/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttpProducerThrowExceptionOnFailureTest.java
 
b/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttpProducerThrowExceptionOnFailureTest.java
index 3106b4c047e7..ed904dc9d955 100644
--- 
a/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttpProducerThrowExceptionOnFailureTest.java
+++ 
b/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttpProducerThrowExceptionOnFailureTest.java
@@ -22,34 +22,30 @@ import org.junit.jupiter.api.Test;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
 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 NettyHttpProducerThrowExceptionOnFailureTest extends 
BaseNettyTestSupport {
     private static final Logger LOG = 
LoggerFactory.getLogger(NettyHttpProducerThrowExceptionOnFailureTest.class);
 
     @Test
     public void testFailWithoutException() {
-        try {
+        assertDoesNotThrow(() -> {
             String out = 
template().requestBody("netty-http:http://localhost:{{port}}/fail?throwExceptionOnFailure=false";,
 null,
                     String.class);
             assertEquals("Fail", out);
-        } catch (Throwable t) {
-            LOG.error("Unexpected exception: {}", t.getMessage(), t);
-            fail("Should not throw an exception");
-        }
+        }, "Should not throw an exception");
     }
 
     @Test
     public void testFailWithException() {
-        try {
-            
template().requestBody("netty-http:http://localhost:{{port}}/fail?throwExceptionOnFailure=true";,
 null,
-                    String.class);
-            fail("Should throw an exception");
-        } catch (Throwable t) {
-            NettyHttpOperationFailedException cause = 
(NettyHttpOperationFailedException) t.getCause();
-            assertEquals(404, cause.getStatusCode());
-        }
+        Throwable t = assertThrows(Throwable.class,
+                () -> 
template().requestBody("netty-http:http://localhost:{{port}}/fail?throwExceptionOnFailure=true";,
 null,
+                        String.class),
+                "Should throw an exception");
+        NettyHttpOperationFailedException cause = 
(NettyHttpOperationFailedException) t.getCause();
+        assertEquals(404, cause.getStatusCode());
     }
 
     @Override
diff --git 
a/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttpRedirectNoLocationTest.java
 
b/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttpRedirectNoLocationTest.java
index b72175bff215..0d308cc09cb7 100644
--- 
a/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttpRedirectNoLocationTest.java
+++ 
b/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttpRedirectNoLocationTest.java
@@ -27,8 +27,8 @@ import static 
org.apache.camel.test.junit5.TestSupport.assertIsInstanceOf;
 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.assertThrows;
 import static org.junit.jupiter.api.Assertions.assertTrue;
-import static org.junit.jupiter.api.Assertions.fail;
 
 public class NettyHttpRedirectNoLocationTest extends BaseNettyTestSupport {
 
@@ -37,16 +37,14 @@ public class NettyHttpRedirectNoLocationTest extends 
BaseNettyTestSupport {
 
     @Test
     public void testHttpRedirectNoLocation() {
-        try {
-            template.requestBody("netty-http:http://localhost:"; + nextPort + 
"/test", "Hello World", String.class);
-            fail("Should have thrown an exception");
-        } catch (RuntimeCamelException e) {
-            NettyHttpOperationFailedException cause = 
assertIsInstanceOf(NettyHttpOperationFailedException.class, e.getCause());
-            assertEquals(302, cause.getStatusCode());
-            assertTrue(cause.isRedirectError());
-            assertFalse(cause.hasRedirectLocation());
-            assertNull(cause.getRedirectLocation());
-        }
+        RuntimeCamelException e = assertThrows(RuntimeCamelException.class,
+                () -> template.requestBody("netty-http:http://localhost:"; + 
nextPort + "/test", "Hello World", String.class),
+                "Should have thrown an exception");
+        NettyHttpOperationFailedException cause = 
assertIsInstanceOf(NettyHttpOperationFailedException.class, e.getCause());
+        assertEquals(302, cause.getStatusCode());
+        assertTrue(cause.isRedirectError());
+        assertFalse(cause.hasRedirectLocation());
+        assertNull(cause.getRedirectLocation());
     }
 
     @Override
diff --git 
a/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttpRedirectTest.java
 
b/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttpRedirectTest.java
index 9b807f6142a2..3b5f246dc62f 100644
--- 
a/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttpRedirectTest.java
+++ 
b/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttpRedirectTest.java
@@ -23,23 +23,21 @@ import org.junit.jupiter.api.Test;
 
 import static org.apache.camel.test.junit5.TestSupport.assertIsInstanceOf;
 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 NettyHttpRedirectTest extends BaseNettyTestSupport {
 
     @Test
     public void testHttpRedirect() {
-        try {
-            template.requestBody("netty-http:http://localhost:{{port}}/test";, 
"Hello World", String.class);
-            fail("Should have thrown an exception");
-        } catch (RuntimeCamelException e) {
-            NettyHttpOperationFailedException cause = 
assertIsInstanceOf(NettyHttpOperationFailedException.class, e.getCause());
-            assertEquals(301, cause.getStatusCode());
-            assertTrue(cause.isRedirectError());
-            assertTrue(cause.hasRedirectLocation());
-            assertEquals("http://localhost:"; + getPort() + "/newtest", 
cause.getRedirectLocation());
-        }
+        RuntimeCamelException e = assertThrows(RuntimeCamelException.class,
+                () -> 
template.requestBody("netty-http:http://localhost:{{port}}/test";, "Hello 
World", String.class),
+                "Should have thrown an exception");
+        NettyHttpOperationFailedException cause = 
assertIsInstanceOf(NettyHttpOperationFailedException.class, e.getCause());
+        assertEquals(301, cause.getStatusCode());
+        assertTrue(cause.isRedirectError());
+        assertTrue(cause.hasRedirectLocation());
+        assertEquals("http://localhost:"; + getPort() + "/newtest", 
cause.getRedirectLocation());
     }
 
     @Override
diff --git 
a/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttpRequestTimeoutTest.java
 
b/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttpRequestTimeoutTest.java
index faeef4bb6347..27b9028263c3 100644
--- 
a/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttpRequestTimeoutTest.java
+++ 
b/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttpRequestTimeoutTest.java
@@ -25,20 +25,18 @@ import org.junit.jupiter.api.Test;
 
 import static org.apache.camel.test.junit5.TestSupport.assertIsInstanceOf;
 import static org.junit.jupiter.api.Assertions.assertNotNull;
-import static org.junit.jupiter.api.Assertions.fail;
+import static org.junit.jupiter.api.Assertions.assertThrows;
 
 public class NettyHttpRequestTimeoutTest extends BaseNettyTestSupport {
 
     @Test
     public void testRequestTimeout() {
-        try {
-            
template.requestBody("netty-http:http://localhost:{{port}}/timeout?requestTimeout=1000";,
 "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-http:http://localhost:{{port}}/timeout?requestTimeout=1000";,
 "Hello Camel",
+                        String.class),
+                "Should have thrown exception");
+        ReadTimeoutException cause = 
assertIsInstanceOf(ReadTimeoutException.class, e.getCause());
+        assertNotNull(cause);
     }
 
     @Override
diff --git 
a/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttpSuspendResume503Test.java
 
b/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttpSuspendResume503Test.java
index d716e43eb5bd..0c66e3a9ac3f 100644
--- 
a/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttpSuspendResume503Test.java
+++ 
b/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttpSuspendResume503Test.java
@@ -27,7 +27,7 @@ import static 
org.apache.camel.test.junit5.TestSupport.assertIsInstanceOf;
 import static org.awaitility.Awaitility.await;
 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.WINDOWS)
 public class NettyHttpSuspendResume503Test extends BaseNettyTestSupport {
@@ -48,13 +48,11 @@ public class NettyHttpSuspendResume503Test extends 
BaseNettyTestSupport {
         // suspend
         consumer.suspend();
 
-        try {
-            template.requestBody(serverUri, "Moon", String.class);
-            fail("Should throw exception");
-        } catch (Exception e) {
-            NettyHttpOperationFailedException cause = 
assertIsInstanceOf(NettyHttpOperationFailedException.class, e.getCause());
-            assertEquals(503, cause.getStatusCode());
-        }
+        Exception e = assertThrows(Exception.class,
+                () -> template.requestBody(serverUri, "Moon", String.class),
+                "Should throw exception");
+        NettyHttpOperationFailedException cause = 
assertIsInstanceOf(NettyHttpOperationFailedException.class, e.getCause());
+        assertEquals(503, cause.getStatusCode());
 
         // resume
         consumer.resume();
diff --git 
a/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttpSuspendResumeTest.java
 
b/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttpSuspendResumeTest.java
index 6f25a0540dff..6718c7a3c00a 100644
--- 
a/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttpSuspendResumeTest.java
+++ 
b/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttpSuspendResumeTest.java
@@ -26,8 +26,8 @@ import org.junit.jupiter.api.condition.OS;
 import static org.awaitility.Awaitility.await;
 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;
 
 @DisabledOnOs(OS.WINDOWS)
 public class NettyHttpSuspendResumeTest extends BaseNettyTestSupport {
@@ -49,12 +49,10 @@ public class NettyHttpSuspendResumeTest extends 
BaseNettyTestSupport {
         // suspend
         consumer.suspend();
 
-        try {
-            template.requestBody(serverUri, "Moon", String.class);
-            fail("Should throw exception");
-        } catch (Exception e) {
-            assertTrue(e.getCause().getMessage().startsWith("Cannot connect to 
localhost"));
-        }
+        Exception e = assertThrows(Exception.class,
+                () -> template.requestBody(serverUri, "Moon", String.class),
+                "Should throw exception");
+        assertTrue(e.getCause().getMessage().startsWith("Cannot connect to 
localhost"));
 
         // resume
         consumer.resume();
diff --git 
a/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttpTransferExceptionTest.java
 
b/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttpTransferExceptionTest.java
index 57495b0ef47f..91be061ba2b0 100644
--- 
a/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttpTransferExceptionTest.java
+++ 
b/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttpTransferExceptionTest.java
@@ -23,7 +23,7 @@ import org.junit.jupiter.api.Test;
 
 import static org.apache.camel.test.junit5.TestSupport.assertIsInstanceOf;
 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 NettyHttpTransferExceptionTest extends BaseNettyTestSupport {
 
@@ -31,14 +31,12 @@ public class NettyHttpTransferExceptionTest extends 
BaseNettyTestSupport {
     public void testHttpTransferException() throws Exception {
         getMockEndpoint("mock:input").expectedBodiesReceived("Hello World");
 
-        try {
-            
template.requestBody("netty-http:http://localhost:{{port}}/foo?transferException=true";,
 "Hello World",
-                    String.class);
-            fail("Should have failed");
-        } catch (CamelExecutionException e) {
-            IllegalArgumentException cause = 
assertIsInstanceOf(IllegalArgumentException.class, e.getCause());
-            assertEquals("Camel cannot do this", cause.getMessage());
-        }
+        CamelExecutionException e = assertThrows(CamelExecutionException.class,
+                () -> 
template.requestBody("netty-http:http://localhost:{{port}}/foo?transferException=true";,
 "Hello World",
+                        String.class),
+                "Should have failed");
+        IllegalArgumentException cause = 
assertIsInstanceOf(IllegalArgumentException.class, e.getCause());
+        assertEquals("Camel cannot do this", cause.getMessage());
 
         MockEndpoint.assertIsSatisfied(context);
     }
diff --git 
a/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttpTwoRoutesValidateBootstrapConfigurationTest.java
 
b/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttpTwoRoutesValidateBootstrapConfigurationTest.java
index d1f32dd6a0a0..11b1fd5b4b70 100644
--- 
a/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttpTwoRoutesValidateBootstrapConfigurationTest.java
+++ 
b/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttpTwoRoutesValidateBootstrapConfigurationTest.java
@@ -19,8 +19,8 @@ package org.apache.camel.component.netty.http;
 import org.apache.camel.builder.RouteBuilder;
 import org.junit.jupiter.api.Test;
 
+import static org.junit.jupiter.api.Assertions.assertThrows;
 import static org.junit.jupiter.api.Assertions.assertTrue;
-import static org.junit.jupiter.api.Assertions.fail;
 
 public class NettyHttpTwoRoutesValidateBootstrapConfigurationTest extends 
BaseNettyTestSupport {
 
@@ -44,12 +44,10 @@ public class 
NettyHttpTwoRoutesValidateBootstrapConfigurationTest extends BaseNe
                         .transform().constant("Bye Camel");
             }
         });
-        try {
-            context.start();
-            fail("Should have thrown exception");
-        } catch (IllegalArgumentException e) {
-            assertTrue(e.getMessage().startsWith("Bootstrap configuration must 
be identical when adding additional consumer"));
-        }
+        IllegalArgumentException e = 
assertThrows(IllegalArgumentException.class,
+                () -> context.start(),
+                "Should have thrown exception");
+        assertTrue(e.getMessage().startsWith("Bootstrap configuration must be 
identical when adding additional consumer"));
     }
 
 }
diff --git 
a/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/SpringNettyHttpBasicAuthTest.java
 
b/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/SpringNettyHttpBasicAuthTest.java
index 48a0fd9e5a08..84023eef77da 100644
--- 
a/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/SpringNettyHttpBasicAuthTest.java
+++ 
b/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/SpringNettyHttpBasicAuthTest.java
@@ -30,7 +30,7 @@ import org.junit.jupiter.api.Test;
 import org.springframework.test.context.ContextConfiguration;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.fail;
+import static org.junit.jupiter.api.Assertions.assertThrows;
 
 @CamelSpringTest
 @ContextConfiguration(locations = { 
"/org/apache/camel/component/netty/http/SpringNettyHttpBasicAuthTest.xml" })
@@ -86,13 +86,11 @@ public class SpringNettyHttpBasicAuthTest {
 
         mockEndpoint.assertIsSatisfied();
 
-        try {
-            template.requestBody("netty-http:http://localhost:"; + port + 
"/foo", "Hello Foo", String.class);
-            fail("Should send back 401");
-        } catch (CamelExecutionException e) {
-            NettyHttpOperationFailedException cause = 
(NettyHttpOperationFailedException) e.getCause();
-            assertEquals(401, cause.getStatusCode());
-        }
+        CamelExecutionException e = assertThrows(CamelExecutionException.class,
+                () -> template.requestBody("netty-http:http://localhost:"; + 
port + "/foo", "Hello Foo", String.class),
+                "Should send back 401");
+        NettyHttpOperationFailedException cause = 
(NettyHttpOperationFailedException) e.getCause();
+        assertEquals(401, cause.getStatusCode());
 
     }
 
@@ -110,14 +108,12 @@ public class SpringNettyHttpBasicAuthTest {
         assertEquals("Bye /foo", out);
 
         // accessing admin is restricted for guest user
-        try {
-            template.requestBodyAndHeader("netty-http:http://localhost:"; + 
port + "/foo/admin/users", "Hello Admin",
-                    "Authorization", auth, String.class);
-            fail("Should send back 401");
-        } catch (CamelExecutionException e) {
-            NettyHttpOperationFailedException cause = 
(NettyHttpOperationFailedException) e.getCause();
-            assertEquals(401, cause.getStatusCode());
-        }
+        CamelExecutionException e = assertThrows(CamelExecutionException.class,
+                () -> 
template.requestBodyAndHeader("netty-http:http://localhost:"; + port + 
"/foo/admin/users", "Hello Admin",
+                        "Authorization", auth, String.class),
+                "Should send back 401");
+        NettyHttpOperationFailedException cause = 
(NettyHttpOperationFailedException) e.getCause();
+        assertEquals(401, cause.getStatusCode());
     }
 
 }
diff --git 
a/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/rest/RestNettyHttpBindingModeJsonTest.java
 
b/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/rest/RestNettyHttpBindingModeJsonTest.java
index 489def62e8c2..92a4dadf1271 100644
--- 
a/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/rest/RestNettyHttpBindingModeJsonTest.java
+++ 
b/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/rest/RestNettyHttpBindingModeJsonTest.java
@@ -24,7 +24,7 @@ import org.junit.jupiter.api.Test;
 
 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;
 
 public class RestNettyHttpBindingModeJsonTest extends BaseNettyTestSupport {
 
@@ -52,12 +52,9 @@ public class RestNettyHttpBindingModeJsonTest extends 
BaseNettyTestSupport {
 
         // we bind to json, but send in xml, which is not possible
         String body = "<user name=\"Donald Duck\" id=\"123\"></user>";
-        try {
-            template.sendBody("netty-http:http://localhost:"; + getPort() + 
"/users/new", body);
-            fail("Should have thrown exception");
-        } catch (Exception e) {
-            // expected
-        }
+        assertThrows(Exception.class,
+                () -> template.sendBody("netty-http:http://localhost:"; + 
getPort() + "/users/new", body),
+                "Should have thrown exception");
 
         MockEndpoint.assertIsSatisfied(context);
     }
diff --git 
a/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/rest/RestNettyHttpBindingModeXmlTest.java
 
b/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/rest/RestNettyHttpBindingModeXmlTest.java
index 103ff6219a4f..3c5dded1979d 100644
--- 
a/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/rest/RestNettyHttpBindingModeXmlTest.java
+++ 
b/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/rest/RestNettyHttpBindingModeXmlTest.java
@@ -24,7 +24,7 @@ import org.junit.jupiter.api.Test;
 
 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;
 
 public class RestNettyHttpBindingModeXmlTest extends BaseNettyTestSupport {
 
@@ -52,12 +52,9 @@ public class RestNettyHttpBindingModeXmlTest extends 
BaseNettyTestSupport {
 
         // we bind to xml, but send in json, which is not possible
         String body = "{\"id\": 123, \"name\": \"Donald Duck\"}";
-        try {
-            template.sendBody("netty-http:http://localhost:"; + getPort() + 
"/users/new", body);
-            fail("Should have thrown exception");
-        } catch (Exception e) {
-            // expected
-        }
+        assertThrows(Exception.class,
+                () -> template.sendBody("netty-http:http://localhost:"; + 
getPort() + "/users/new", body),
+                "Should have thrown exception");
 
         MockEndpoint.assertIsSatisfied(context);
     }
diff --git 
a/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/rest/RestNettyMethodNotAllowedTest.java
 
b/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/rest/RestNettyMethodNotAllowedTest.java
index 62b374291f38..34cc043c07a5 100644
--- 
a/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/rest/RestNettyMethodNotAllowedTest.java
+++ 
b/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/rest/RestNettyMethodNotAllowedTest.java
@@ -23,29 +23,27 @@ import 
org.apache.camel.http.base.HttpOperationFailedException;
 import org.junit.jupiter.api.Test;
 
 import static org.apache.camel.test.junit5.TestSupport.assertIsInstanceOf;
+import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
 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 RestNettyMethodNotAllowedTest extends BaseNettyTestSupport {
     @Test
     public void testMethodNotAllowed() {
-        try {
-            template.sendBody("http://localhost:"; + getPort() + 
"/users/123/basic", "body");
-            fail("Shall not pass!");
-        } catch (Exception e) {
-            HttpOperationFailedException hofe = 
assertIsInstanceOf(HttpOperationFailedException.class, e.getCause());
-            assertEquals(405, hofe.getStatusCode());
-        }
+        Exception e = assertThrows(Exception.class,
+                () -> template.sendBody("http://localhost:"; + getPort() + 
"/users/123/basic", "body"),
+                "Shall not pass!");
+        HttpOperationFailedException hofe = 
assertIsInstanceOf(HttpOperationFailedException.class, e.getCause());
+        assertEquals(405, hofe.getStatusCode());
     }
 
     @Test
     public void testMethodAllowed() {
-        try {
-            template.sendBodyAndHeader("http://localhost:"; + getPort() + 
"/users/123/basic", "body", Exchange.HTTP_METHOD,
-                    "GET");
-        } catch (Exception e) {
-            fail("Shall pass with GET http method!");
-        }
+        assertDoesNotThrow(
+                () -> template.sendBodyAndHeader("http://localhost:"; + 
getPort() + "/users/123/basic", "body",
+                        Exchange.HTTP_METHOD,
+                        "GET"),
+                "Shall pass with GET http method!");
     }
 
     @Override

Reply via email to