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

    CAMEL-21196: modernize exception-based assertions in camel-sql
    
    Replace try-catch-fail patterns with assertThrows where applicable and 
convert
    fail() calls to throw new AssertionError() in test classes to use modern
    JUnit 5 exception testing approach, improving code clarity and consistency.
---
 .../sql/SqlProducerNamedParameterNotExistTest.java   | 20 +++++++-------------
 .../org/apache/camel/component/sql/SqlRouteTest.java |  3 +--
 .../sql/stored/ProducerBatchInvalidTest.java         | 19 ++++++++-----------
 .../jdbc/JdbcRemoveConfirmOrderAggregateTest.java    |  4 +---
 4 files changed, 17 insertions(+), 29 deletions(-)

diff --git 
a/components/camel-sql/src/test/java/org/apache/camel/component/sql/SqlProducerNamedParameterNotExistTest.java
 
b/components/camel-sql/src/test/java/org/apache/camel/component/sql/SqlProducerNamedParameterNotExistTest.java
index 21be0fcd2f7b..679eb8521559 100644
--- 
a/components/camel-sql/src/test/java/org/apache/camel/component/sql/SqlProducerNamedParameterNotExistTest.java
+++ 
b/components/camel-sql/src/test/java/org/apache/camel/component/sql/SqlProducerNamedParameterNotExistTest.java
@@ -26,8 +26,8 @@ import 
org.springframework.jdbc.datasource.embedded.EmbeddedDatabase;
 import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder;
 import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType;
 
+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 SqlProducerNamedParameterNotExistTest extends CamelTestSupport {
 
@@ -56,22 +56,16 @@ public class SqlProducerNamedParameterNotExistTest extends 
CamelTestSupport {
         Map<String, Object> map = new HashMap<>();
         map.put("foo", "ASF");
 
-        try {
-            template.sendBody("direct:start", map);
-            fail("Should have thrown exception");
-        } catch (Exception e) {
-            assertTrue(e.getCause().getMessage().startsWith("Cannot find key 
[lic]"));
-        }
+        Exception e = assertThrows(Exception.class,
+                () -> template.sendBody("direct:start", map));
+        assertTrue(e.getCause().getMessage().startsWith("Cannot find key 
[lic]"));
     }
 
     @Test
     public void testNamedParameterNotExistFromHeader() {
-        try {
-            template.sendBodyAndHeader("direct:start", "This is a dummy body", 
"foo", "ASF");
-            fail("Should have thrown exception");
-        } catch (Exception e) {
-            assertTrue(e.getCause().getMessage().startsWith("Cannot find key 
[lic]"));
-        }
+        Exception e = assertThrows(Exception.class,
+                () -> template.sendBodyAndHeader("direct:start", "This is a 
dummy body", "foo", "ASF"));
+        assertTrue(e.getCause().getMessage().startsWith("Cannot find key 
[lic]"));
     }
 
     @Override
diff --git 
a/components/camel-sql/src/test/java/org/apache/camel/component/sql/SqlRouteTest.java
 
b/components/camel-sql/src/test/java/org/apache/camel/component/sql/SqlRouteTest.java
index d66304e20433..a730e460d72a 100644
--- 
a/components/camel-sql/src/test/java/org/apache/camel/component/sql/SqlRouteTest.java
+++ 
b/components/camel-sql/src/test/java/org/apache/camel/component/sql/SqlRouteTest.java
@@ -42,7 +42,6 @@ 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 SqlRouteTest extends CamelTestSupport {
 
@@ -176,7 +175,7 @@ public class SqlRouteTest extends CamelTestSupport {
             String projectName = jdbcTemplate.queryForObject("select project 
from projects where id = 10", String.class);
             assertEquals("test", projectName);
         } catch (EmptyResultDataAccessException e) {
-            fail("no row inserted");
+            throw new AssertionError("no row inserted", e);
         }
 
         Integer actualUpdateCount = 
mock.getExchanges().get(0).getIn().getHeader(SqlConstants.SQL_UPDATE_COUNT, 
Integer.class);
diff --git 
a/components/camel-sql/src/test/java/org/apache/camel/component/sql/stored/ProducerBatchInvalidTest.java
 
b/components/camel-sql/src/test/java/org/apache/camel/component/sql/stored/ProducerBatchInvalidTest.java
index f08810513972..6e5cd3e6be66 100644
--- 
a/components/camel-sql/src/test/java/org/apache/camel/component/sql/stored/ProducerBatchInvalidTest.java
+++ 
b/components/camel-sql/src/test/java/org/apache/camel/component/sql/stored/ProducerBatchInvalidTest.java
@@ -29,7 +29,7 @@ import 
org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType;
 
 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 ProducerBatchInvalidTest extends CamelTestSupport {
 
@@ -69,16 +69,13 @@ public class ProducerBatchInvalidTest extends 
CamelTestSupport {
                 from("direct:query").to("sql-stored:BATCHFN(INTEGER 
:#num)?batch=true&batch=true").to("mock:query");
             }
         });
-        try {
-            context.start();
-            fail("Should throw exception");
-        } catch (FailedToCreateRouteException e) {
-            ResolveEndpointFailedException refe = 
assertIsInstanceOf(ResolveEndpointFailedException.class, e.getCause());
-            PropertyBindingException pbe = 
assertIsInstanceOf(PropertyBindingException.class, refe.getCause());
-            assertEquals("batch", pbe.getPropertyName());
-            assertIsInstanceOf(TypeConversionException.class, pbe.getCause());
-            assertEquals("[true, true]", pbe.getValue().toString());
-        }
+        FailedToCreateRouteException e = 
assertThrows(FailedToCreateRouteException.class,
+                () -> context.start());
+        ResolveEndpointFailedException refe = 
assertIsInstanceOf(ResolveEndpointFailedException.class, e.getCause());
+        PropertyBindingException pbe = 
assertIsInstanceOf(PropertyBindingException.class, refe.getCause());
+        assertEquals("batch", pbe.getPropertyName());
+        assertIsInstanceOf(TypeConversionException.class, pbe.getCause());
+        assertEquals("[true, true]", pbe.getValue().toString());
     }
 
 }
diff --git 
a/components/camel-sql/src/test/java/org/apache/camel/processor/aggregate/jdbc/JdbcRemoveConfirmOrderAggregateTest.java
 
b/components/camel-sql/src/test/java/org/apache/camel/processor/aggregate/jdbc/JdbcRemoveConfirmOrderAggregateTest.java
index e3cca38a39e3..01a18da2517b 100644
--- 
a/components/camel-sql/src/test/java/org/apache/camel/processor/aggregate/jdbc/JdbcRemoveConfirmOrderAggregateTest.java
+++ 
b/components/camel-sql/src/test/java/org/apache/camel/processor/aggregate/jdbc/JdbcRemoveConfirmOrderAggregateTest.java
@@ -35,7 +35,6 @@ import 
org.springframework.jdbc.datasource.DataSourceTransactionManager;
 import org.springframework.transaction.support.DefaultTransactionStatus;
 
 import static org.awaitility.Awaitility.await;
-import static org.junit.jupiter.api.Assertions.fail;
 
 public class JdbcRemoveConfirmOrderAggregateTest extends 
AbstractJdbcAggregationTestSupport {
 
@@ -111,8 +110,7 @@ public class JdbcRemoveConfirmOrderAggregateTest extends 
AbstractJdbcAggregation
                     .executeQuery("SELECT * FROM aggregationRepo1_completed");
             return !rs.next();
         } catch (SQLException e) {
-            fail(e);
-            return false;
+            throw new AssertionError(e);
         }
 
     }

Reply via email to