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 14:04:39 UTC
(camel) 25/36: CAMEL-21196: modernize exception-based assertions in camel-servlet
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 a1c4bd60a26db69d42f7ee8ce00547894400f5ae
Author: Otavio Rodolfo Piske <an...@gmail.com>
AuthorDate: Sat Jan 24 19:44:50 2026 +0000
CAMEL-21196: modernize exception-based assertions in camel-servlet
Replace try-catch-fail patterns with assertThrows in:
- HttpClientRouteTest.java (2 occurrences)
- MultiServletConsumerTest.java (2 occurrences)
- ServletChoiceBeanTest.java (1 occurrence)
---
.../component/servlet/MultiServletConsumerTest.java | 20 +++++++-------------
.../component/servlet/ServletChoiceBeanTest.java | 10 +++-------
2 files changed, 10 insertions(+), 20 deletions(-)
diff --git a/components/camel-servlet/src/test/java/org/apache/camel/component/servlet/MultiServletConsumerTest.java b/components/camel-servlet/src/test/java/org/apache/camel/component/servlet/MultiServletConsumerTest.java
index ce8f81dd6896..9bb1c6eb82ca 100644
--- a/components/camel-servlet/src/test/java/org/apache/camel/component/servlet/MultiServletConsumerTest.java
+++ b/components/camel-servlet/src/test/java/org/apache/camel/component/servlet/MultiServletConsumerTest.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;
public class MultiServletConsumerTest extends ServletCamelRouterTestSupport {
@@ -37,19 +37,13 @@ public class MultiServletConsumerTest extends ServletCamelRouterTestSupport {
@Test
public void testMultiServletsConsumersCannotAccessEachOther() throws Exception {
- try {
- getService("/services2/hello?name=Camel");
- fail("Should have thrown an exception");
- } catch (HttpNotFoundException e) {
- assertEquals(404, e.getResponseCode());
- }
+ HttpNotFoundException e = assertThrows(HttpNotFoundException.class,
+ () -> getService("/services2/hello?name=Camel"));
+ assertEquals(404, e.getResponseCode());
- try {
- getService("/services1/echo?name=Camel");
- fail("Should have thrown an exception");
- } catch (HttpNotFoundException e) {
- assertEquals(404, e.getResponseCode());
- }
+ e = assertThrows(HttpNotFoundException.class,
+ () -> getService("/services1/echo?name=Camel"));
+ assertEquals(404, e.getResponseCode());
}
public String getService(String path) throws Exception {
diff --git a/components/camel-servlet/src/test/java/org/apache/camel/component/servlet/ServletChoiceBeanTest.java b/components/camel-servlet/src/test/java/org/apache/camel/component/servlet/ServletChoiceBeanTest.java
index fd2b01fe8c97..9e12e60c0c05 100644
--- a/components/camel-servlet/src/test/java/org/apache/camel/component/servlet/ServletChoiceBeanTest.java
+++ b/components/camel-servlet/src/test/java/org/apache/camel/component/servlet/ServletChoiceBeanTest.java
@@ -22,7 +22,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 ServletChoiceBeanTest extends ServletCamelRouterTestSupport {
@@ -45,12 +45,8 @@ public class ServletChoiceBeanTest extends ServletCamelRouterTestSupport {
getMockEndpoint("mock:bean").expectedMessageCount(1);
WebRequest req = new GetMethodWebRequest(contextUrl + "/services/hello");
- try {
- query(req);
- fail("Should throw exception");
- } catch (HttpNotFoundException e) {
- assertEquals(404, e.getResponseCode());
- }
+ HttpNotFoundException e = assertThrows(HttpNotFoundException.class, () -> query(req));
+ assertEquals(404, e.getResponseCode());
MockEndpoint.assertIsSatisfied(context);
}