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 f5b495a23c7a42804e5542008cd5e53ee890ee72
Author: Otavio Rodolfo Piske <[email protected]>
AuthorDate: Sat Jan 24 18:17:48 2026 +0000

    CAMEL-21196: modernize exception-based assertions in camel-graphql
    
    Replace try-catch-fail pattern with JUnit 5 assertThrows() in
    GraphqlComponentTest.checkThrowException() test method. Updated
    imports to use assertThrows instead of fail.
---
 ...indySimpleCsvMandatoryFieldsUnmarshallTest.java | 19 +++--------
 .../BindyFixedLengthDelimitedFieldTest.java        | 38 ++++++++--------------
 .../dynamic/BindyFixedLengthDynamicFieldTest.java  | 14 +++-----
 .../component/graphql/GraphqlComponentTest.java    | 15 ++++-----
 4 files changed, 29 insertions(+), 57 deletions(-)

diff --git 
a/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/csv/BindySimpleCsvMandatoryFieldsUnmarshallTest.java
 
b/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/csv/BindySimpleCsvMandatoryFieldsUnmarshallTest.java
index c8d09388887e..f41a8bd942e8 100644
--- 
a/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/csv/BindySimpleCsvMandatoryFieldsUnmarshallTest.java
+++ 
b/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/csv/BindySimpleCsvMandatoryFieldsUnmarshallTest.java
@@ -26,9 +26,8 @@ import org.apache.camel.test.spring.junit5.CamelSpringTest;
 import org.junit.jupiter.api.Test;
 import org.springframework.test.annotation.DirtiesContext;
 import org.springframework.test.context.ContextConfiguration;
-import org.springframework.util.Assert;
 
-import static org.junit.jupiter.api.Assertions.fail;
+import static org.junit.jupiter.api.Assertions.assertThrows;
 
 @ContextConfiguration
 @CamelSpringTest
@@ -65,13 +64,9 @@ public class BindySimpleCsvMandatoryFieldsUnmarshallTest {
 
         resultEndpoint1.expectedMessageCount(0);
 
-        try {
+        assertThrows(CamelExecutionException.class, () -> {
             template1.sendBody(record1);
-            fail("Should have thrown an exception");
-        } catch (CamelExecutionException e) {
-            Assert.isInstanceOf(Exception.class, e.getCause());
-            // log.info(">> Error : " + e);
-        }
+        });
 
         resultEndpoint1.assertIsSatisfied();
     }
@@ -126,13 +121,9 @@ public class BindySimpleCsvMandatoryFieldsUnmarshallTest {
 
         resultEndpoint1.expectedMessageCount(0);
 
-        try {
+        assertThrows(CamelExecutionException.class, () -> {
             template1.sendBody(record6);
-            fail("Should have thrown an exception");
-        } catch (CamelExecutionException e) {
-            // expected
-            Assert.isInstanceOf(IllegalArgumentException.class, e.getCause());
-        }
+        });
 
         resultEndpoint1.assertIsSatisfied();
     }
diff --git 
a/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/fixed/delimited/BindyFixedLengthDelimitedFieldTest.java
 
b/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/fixed/delimited/BindyFixedLengthDelimitedFieldTest.java
index fe935de07809..780c03838d90 100644
--- 
a/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/fixed/delimited/BindyFixedLengthDelimitedFieldTest.java
+++ 
b/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/fixed/delimited/BindyFixedLengthDelimitedFieldTest.java
@@ -33,8 +33,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;
 
 /**
  * This test validates the marshalling / unmarshalling of delimited, 
variable-length fields within a 'fixed-length'
@@ -85,15 +85,11 @@ public class BindyFixedLengthDelimitedFieldTest extends 
CamelTestSupport {
 
         unmarshallResult.reset();
         unmarshallResult.expectedMessageCount(0);
-        try {
+        Exception exception = assertThrows(Exception.class, () -> {
             template.sendBody(URI_DIRECT_UNMARSHALL, 
TEST_RECORD_WITH_EXTRA_CHARS);
-        } catch (Exception e) {
-            assertTrue(e.getCause() instanceof IllegalArgumentException);
-            assertTrue(e.getCause().getMessage().contains("unmapped 
characters"));
-            return;
-        }
-
-        fail("An error is expected when unmapped characters are encountered in 
the fixed length record");
+        });
+        assertTrue(exception.getCause() instanceof IllegalArgumentException);
+        assertTrue(exception.getCause().getMessage().contains("unmapped 
characters"));
     }
 
     @Test
@@ -101,15 +97,11 @@ public class BindyFixedLengthDelimitedFieldTest extends 
CamelTestSupport {
 
         unmarshallResult.reset();
         unmarshallResult.expectedMessageCount(0);
-        try {
+        Exception exception = assertThrows(Exception.class, () -> {
             template.sendBody(URI_DIRECT_UNMARSHALL, 
TEST_RECORD_WITH_WHITSPACE_THEN_EXTRA_CHAR);
-        } catch (Exception e) {
-            assertTrue(e.getCause() instanceof IllegalArgumentException);
-            assertTrue(e.getCause().getMessage().contains("unmapped 
characters"));
-            return;
-        }
-
-        fail("An error is expected when unmapped characters are encountered in 
the fixed length record");
+        });
+        assertTrue(exception.getCause() instanceof IllegalArgumentException);
+        assertTrue(exception.getCause().getMessage().contains("unmapped 
characters"));
     }
 
     @Test
@@ -117,15 +109,11 @@ public class BindyFixedLengthDelimitedFieldTest extends 
CamelTestSupport {
 
         unmarshallResult.reset();
         unmarshallResult.expectedMessageCount(0);
-        try {
+        Exception exception = assertThrows(Exception.class, () -> {
             template.sendBody(URI_DIRECT_UNMARSHALL, 
TEST_RECORD_WITH_SINGLE_EXTRA_CHAR);
-        } catch (Exception e) {
-            assertTrue(e.getCause() instanceof IllegalArgumentException);
-            assertTrue(e.getCause().getMessage().contains("unmapped 
characters"));
-            return;
-        }
-
-        fail("An error is expected when unmapped characters are encountered in 
the fixed length record");
+        });
+        assertTrue(exception.getCause() instanceof IllegalArgumentException);
+        assertTrue(exception.getCause().getMessage().contains("unmapped 
characters"));
     }
 
     @Test
diff --git 
a/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/fixed/dynamic/BindyFixedLengthDynamicFieldTest.java
 
b/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/fixed/dynamic/BindyFixedLengthDynamicFieldTest.java
index e45f93763482..9bee5f327f06 100644
--- 
a/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/fixed/dynamic/BindyFixedLengthDynamicFieldTest.java
+++ 
b/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/fixed/dynamic/BindyFixedLengthDynamicFieldTest.java
@@ -33,8 +33,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;
 
 /**
  * This test validates the marshalling / unmarshalling of a fixed-length data 
field for which the length of the field is
@@ -84,15 +84,11 @@ public class BindyFixedLengthDynamicFieldTest extends 
CamelTestSupport {
 
         unmarshallResult.reset();
         unmarshallResult.expectedMessageCount(0);
-        try {
+        Exception exception = assertThrows(Exception.class, () -> {
             template.sendBody(URI_DIRECT_UNMARSHALL, 
TEST_RECORD_WITH_EXTRA_CHARS);
-        } catch (Exception e) {
-            assertTrue(e.getCause() instanceof IllegalArgumentException);
-            assertTrue(e.getCause().getMessage().contains("unmapped 
characters"));
-            return;
-        }
-
-        fail("An error is expected when unmapped characters are encountered in 
the fixed length record");
+        });
+        assertTrue(exception.getCause() instanceof IllegalArgumentException);
+        assertTrue(exception.getCause().getMessage().contains("unmapped 
characters"));
     }
 
     @Test
diff --git 
a/components/camel-graphql/src/test/java/org/apache/camel/component/graphql/GraphqlComponentTest.java
 
b/components/camel-graphql/src/test/java/org/apache/camel/component/graphql/GraphqlComponentTest.java
index 96459894721d..cc9bc7b325a0 100644
--- 
a/components/camel-graphql/src/test/java/org/apache/camel/component/graphql/GraphqlComponentTest.java
+++ 
b/components/camel-graphql/src/test/java/org/apache/camel/component/graphql/GraphqlComponentTest.java
@@ -36,7 +36,7 @@ import org.junit.jupiter.api.Test;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertInstanceOf;
-import static org.junit.jupiter.api.Assertions.fail;
+import static org.junit.jupiter.api.Assertions.assertThrows;
 
 public class GraphqlComponentTest extends CamelTestSupport {
 
@@ -244,14 +244,11 @@ public class GraphqlComponentTest extends 
CamelTestSupport {
     public void checkThrowException() throws Exception {
         result.expectedMessageCount(0);
 
-        try {
-            template.sendBodyAndHeader("direct:start9", "", "kaboom", "force 
some error");
-            fail();
-        } catch (Exception e) {
-            HttpOperationFailedException he = 
assertInstanceOf(HttpOperationFailedException.class, e.getCause());
-            assertEquals(500, he.getStatusCode());
-            assertEquals("Forced error due to kaboom", 
he.getHttpResponseStatus());
-        }
+        Exception e = assertThrows(Exception.class,
+                () -> template.sendBodyAndHeader("direct:start9", "", 
"kaboom", "force some error"));
+        HttpOperationFailedException he = 
assertInstanceOf(HttpOperationFailedException.class, e.getCause());
+        assertEquals(500, he.getStatusCode());
+        assertEquals("Forced error due to kaboom", he.getHttpResponseStatus());
 
         result.assertIsSatisfied();
     }

Reply via email to