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 5a4350f455043addc09ca26969dbe234a370a885
Author: Otavio Rodolfo Piske <[email protected]>
AuthorDate: Sat Jan 24 19:49:13 2026 +0000

    CAMEL-21196: modernize exception-based assertions in camel-thrift
    
    Replace try-catch-fail patterns with assertThrows in test classes to use
    modern JUnit 5 exception testing approach, improving code clarity and 
consistency.
---
 .../thrift/ThriftProducerSecurityTest.java          | 13 +++++--------
 .../component/thrift/ThriftProducerSyncTest.java    | 13 +++++--------
 .../thrift/ThriftMarshalAndUnmarshalSpringTest.java | 21 +++++++++------------
 .../thrift/ThriftMarshalAndUnmarshalTest.java       | 21 +++++++++------------
 4 files changed, 28 insertions(+), 40 deletions(-)

diff --git 
a/components/camel-thrift/src/test/java/org/apache/camel/component/thrift/ThriftProducerSecurityTest.java
 
b/components/camel-thrift/src/test/java/org/apache/camel/component/thrift/ThriftProducerSecurityTest.java
index c0da4a6b2afc..8c7999c06fba 100644
--- 
a/components/camel-thrift/src/test/java/org/apache/camel/component/thrift/ThriftProducerSecurityTest.java
+++ 
b/components/camel-thrift/src/test/java/org/apache/camel/component/thrift/ThriftProducerSecurityTest.java
@@ -49,8 +49,8 @@ import org.slf4j.LoggerFactory;
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertNotNull;
 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 ThriftProducerSecurityTest extends CamelTestSupport {
     private static final Logger LOG = 
LoggerFactory.getLogger(ThriftProducerSecurityTest.class);
@@ -144,13 +144,10 @@ public class ThriftProducerSecurityTest extends 
CamelTestSupport {
         requestBody.add(1);
         requestBody.add(new Work(THRIFT_TEST_NUM1, 0, Operation.DIVIDE));
 
-        try {
-            template.requestBody("direct:thrift-secured-calculate", 
requestBody);
-            fail("Expect the exception here");
-        } catch (Exception ex) {
-            assertTrue(ex instanceof CamelExecutionException, "Expect 
CamelExecutionException");
-            assertTrue(ex.getCause() instanceof InvalidOperation, "Get an 
InvalidOperation exception");
-        }
+        Exception ex = assertThrows(Exception.class,
+                () -> template.requestBody("direct:thrift-secured-calculate", 
requestBody));
+        assertTrue(ex instanceof CamelExecutionException, "Expect 
CamelExecutionException");
+        assertTrue(ex.getCause() instanceof InvalidOperation, "Get an 
InvalidOperation exception");
     }
 
     @Test
diff --git 
a/components/camel-thrift/src/test/java/org/apache/camel/component/thrift/ThriftProducerSyncTest.java
 
b/components/camel-thrift/src/test/java/org/apache/camel/component/thrift/ThriftProducerSyncTest.java
index de826db56017..f05e5727b667 100644
--- 
a/components/camel-thrift/src/test/java/org/apache/camel/component/thrift/ThriftProducerSyncTest.java
+++ 
b/components/camel-thrift/src/test/java/org/apache/camel/component/thrift/ThriftProducerSyncTest.java
@@ -34,8 +34,8 @@ import org.slf4j.LoggerFactory;
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertNotNull;
 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 ThriftProducerSyncTest extends ThriftProducerBaseTest {
     private static final Logger LOG = 
LoggerFactory.getLogger(ThriftProducerSyncTest.class);
@@ -84,13 +84,10 @@ public class ThriftProducerSyncTest extends 
ThriftProducerBaseTest {
         requestBody.add(1);
         requestBody.add(new Work(THRIFT_TEST_NUM1, 0, Operation.DIVIDE));
 
-        try {
-            template.requestBody("direct:thrift-calculate", requestBody);
-            fail("Expect the exception here");
-        } catch (Exception ex) {
-            assertTrue(ex instanceof CamelExecutionException, "Expect 
CamelExecutionException");
-            assertTrue(ex.getCause() instanceof InvalidOperation, "Get an 
InvalidOperation exception");
-        }
+        Exception ex = assertThrows(Exception.class,
+                () -> template.requestBody("direct:thrift-calculate", 
requestBody));
+        assertTrue(ex instanceof CamelExecutionException, "Expect 
CamelExecutionException");
+        assertTrue(ex.getCause() instanceof InvalidOperation, "Get an 
InvalidOperation exception");
     }
 
     @Test
diff --git 
a/components/camel-thrift/src/test/java/org/apache/camel/dataformat/thrift/ThriftMarshalAndUnmarshalSpringTest.java
 
b/components/camel-thrift/src/test/java/org/apache/camel/dataformat/thrift/ThriftMarshalAndUnmarshalSpringTest.java
index c8f7ddd0d2d7..cf8b6ca02c78 100644
--- 
a/components/camel-thrift/src/test/java/org/apache/camel/dataformat/thrift/ThriftMarshalAndUnmarshalSpringTest.java
+++ 
b/components/camel-thrift/src/test/java/org/apache/camel/dataformat/thrift/ThriftMarshalAndUnmarshalSpringTest.java
@@ -27,8 +27,8 @@ import org.junit.jupiter.api.Test;
 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 ThriftMarshalAndUnmarshalSpringTest extends 
CamelSpringTestSupport {
     private static final String WORK_TEST_COMMENT = "This is a test thrift 
data";
@@ -58,17 +58,14 @@ public class ThriftMarshalAndUnmarshalSpringTest extends 
CamelSpringTestSupport
 
     @Test
     public void testMarshalAndUnmarshalWithDSL3() {
-        try {
-            context.addRoutes(new RouteBuilder() {
-                @Override
-                public void configure() {
-                    from("direct:unmarshalC").unmarshal().thrift(new 
CamelException("wrong instance")).to("mock:reverse");
-                }
-            });
-            fail("Expect the exception here");
-        } catch (Exception ex) {
-            assertTrue(ex instanceof FailedToCreateRouteException, "Expect 
FailedToCreateRouteException");
-        }
+        Exception ex = assertThrows(Exception.class,
+                () -> context.addRoutes(new RouteBuilder() {
+                    @Override
+                    public void configure() {
+                        from("direct:unmarshalC").unmarshal().thrift(new 
CamelException("wrong instance")).to("mock:reverse");
+                    }
+                }));
+        assertTrue(ex instanceof FailedToCreateRouteException, "Expect 
FailedToCreateRouteException");
     }
 
     private void marshalAndUnmarshal(String inURI, String outURI) throws 
Exception {
diff --git 
a/components/camel-thrift/src/test/java/org/apache/camel/dataformat/thrift/ThriftMarshalAndUnmarshalTest.java
 
b/components/camel-thrift/src/test/java/org/apache/camel/dataformat/thrift/ThriftMarshalAndUnmarshalTest.java
index 33da0d854b50..ce96c9daebd3 100644
--- 
a/components/camel-thrift/src/test/java/org/apache/camel/dataformat/thrift/ThriftMarshalAndUnmarshalTest.java
+++ 
b/components/camel-thrift/src/test/java/org/apache/camel/dataformat/thrift/ThriftMarshalAndUnmarshalTest.java
@@ -26,8 +26,8 @@ import org.apache.camel.test.junit5.CamelTestSupport;
 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 ThriftMarshalAndUnmarshalTest extends CamelTestSupport {
     private static final String WORK_TEST_COMMENT = "This is a test thrift 
data";
@@ -52,17 +52,14 @@ public class ThriftMarshalAndUnmarshalTest extends 
CamelTestSupport {
 
     @Test
     public void testMarshalAndUnmarshalWithDSL3() {
-        try {
-            context.addRoutes(new RouteBuilder() {
-                @Override
-                public void configure() {
-                    from("direct:unmarshalC").unmarshal().thrift(new 
CamelException("wrong instance")).to("mock:reverse");
-                }
-            });
-            fail("Expect the exception here");
-        } catch (Exception ex) {
-            assertTrue(ex instanceof FailedToCreateRouteException, "Expect 
FailedToCreateRouteException");
-        }
+        Exception ex = assertThrows(Exception.class,
+                () -> context.addRoutes(new RouteBuilder() {
+                    @Override
+                    public void configure() {
+                        from("direct:unmarshalC").unmarshal().thrift(new 
CamelException("wrong instance")).to("mock:reverse");
+                    }
+                }));
+        assertTrue(ex instanceof FailedToCreateRouteException, "Expect 
FailedToCreateRouteException");
     }
 
     private void marshalAndUnmarshal(String inURI, String outURI) throws 
Exception {

Reply via email to