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

    CAMEL-21196: modernize exception-based assertions in camel-jq
---
 .../camel/component/hl7/HL7ValidateTest.java       | 32 ++++++++++------------
 .../camel/language/jq/JqLanguageValidateTest.java  | 10 +++----
 2 files changed, 18 insertions(+), 24 deletions(-)

diff --git 
a/components/camel-hl7/src/test/java/org/apache/camel/component/hl7/HL7ValidateTest.java
 
b/components/camel-hl7/src/test/java/org/apache/camel/component/hl7/HL7ValidateTest.java
index a9e4a28e8dff..56f5495dc59d 100644
--- 
a/components/camel-hl7/src/test/java/org/apache/camel/component/hl7/HL7ValidateTest.java
+++ 
b/components/camel-hl7/src/test/java/org/apache/camel/component/hl7/HL7ValidateTest.java
@@ -40,8 +40,8 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import static org.apache.camel.test.junit5.TestSupport.assertIsInstanceOf;
+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 HL7ValidateTest extends CamelTestSupport {
 
@@ -54,15 +54,13 @@ public class HL7ValidateTest extends CamelTestSupport {
         mock.expectedMessageCount(0);
 
         String body = createHL7AsString();
-        try {
+        CamelExecutionException e = 
assertThrows(CamelExecutionException.class, () -> {
             template.sendBody("direct:unmarshalFailed", body);
-            fail("Should have thrown exception");
-        } catch (CamelExecutionException e) {
-            assertIsInstanceOf(HL7Exception.class, e.getCause());
-            assertIsInstanceOf(DataTypeException.class, e.getCause());
-            
assertTrue(e.getCause().getMessage().startsWith("ca.uhn.hl7v2.validation.ValidationException:
 Validation failed:"),
-                    "Should be a validation error message");
-        }
+        });
+        assertIsInstanceOf(HL7Exception.class, e.getCause());
+        assertIsInstanceOf(DataTypeException.class, e.getCause());
+        
assertTrue(e.getCause().getMessage().startsWith("ca.uhn.hl7v2.validation.ValidationException:
 Validation failed:"),
+                "Should be a validation error message");
 
         MockEndpoint.assertIsSatisfied(context);
     }
@@ -95,16 +93,14 @@ public class HL7ValidateTest extends CamelTestSupport {
         mock.expectedMessageCount(0);
 
         Message message = createADT01Message();
-        try {
+        CamelExecutionException e = 
assertThrows(CamelExecutionException.class, () -> {
             template.sendBody("direct:start1", message);
-            fail("Should have thrown exception");
-        } catch (CamelExecutionException e) {
-            assertIsInstanceOf(HL7Exception.class, e.getCause());
-            assertIsInstanceOf(ValidationException.class, 
e.getCause().getCause());
-            LOG.error("Validation failed", e.getCause().getCause());
-            
assertTrue(e.getCause().getCause().getMessage().startsWith("Validation 
failed:"),
-                    "Should be a validation error message");
-        }
+        });
+        assertIsInstanceOf(HL7Exception.class, e.getCause());
+        assertIsInstanceOf(ValidationException.class, e.getCause().getCause());
+        LOG.error("Validation failed", e.getCause().getCause());
+        assertTrue(e.getCause().getCause().getMessage().startsWith("Validation 
failed:"),
+                "Should be a validation error message");
 
         MockEndpoint.assertIsSatisfied(context);
     }
diff --git 
a/components/camel-jq/src/test/java/org/apache/camel/language/jq/JqLanguageValidateTest.java
 
b/components/camel-jq/src/test/java/org/apache/camel/language/jq/JqLanguageValidateTest.java
index 84e5ca2e4875..95611d603132 100644
--- 
a/components/camel-jq/src/test/java/org/apache/camel/language/jq/JqLanguageValidateTest.java
+++ 
b/components/camel-jq/src/test/java/org/apache/camel/language/jq/JqLanguageValidateTest.java
@@ -20,7 +20,7 @@ import net.thisptr.jackson.jq.exception.JsonQueryException;
 import org.junit.jupiter.api.Assertions;
 import org.junit.jupiter.api.Test;
 
-import static org.junit.jupiter.api.Assertions.fail;
+import static org.junit.jupiter.api.Assertions.assertThrows;
 
 public class JqLanguageValidateTest {
 
@@ -29,12 +29,10 @@ public class JqLanguageValidateTest {
         JqLanguage lan = new JqLanguage();
         lan.init();
         Assertions.assertTrue(lan.validateExpression(". + [{\"array\": 
body()}]"));
-        try {
+        JsonQueryException e = assertThrows(JsonQueryException.class, () -> {
             Assertions.assertFalse(lan.validateExpression(". ^^+ [{\"array\": 
body()}]"));
-            fail();
-        } catch (JsonQueryException e) {
-            Assertions.assertTrue(e.getMessage().startsWith("Cannot compile 
query"));
-        }
+        });
+        Assertions.assertTrue(e.getMessage().startsWith("Cannot compile 
query"));
     }
 
 }

Reply via email to