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 6f55a3eebad4f8bb03e12df847c257c53900fff5
Author: Otavio Rodolfo Piske <[email protected]>
AuthorDate: Sat Jan 24 19:46:26 2026 +0000

    CAMEL-21196: modernize exception-based assertions in camel-jira
    
    Replace try-catch-fail patterns with assertThrows in test classes to use
    modern JUnit 5 exception testing approach, improving code clarity and 
consistency.
---
 .../jira/producer/AddIssueLinkProducerTest.java    | 35 ++++++++--------------
 .../jira/producer/AddWorkLogProducerTest.java      | 35 ++++++++--------------
 .../jira/producer/FetchCommentsProducerTest.java   | 13 ++++----
 .../jira/producer/FetchIssueProducerTest.java      | 13 ++++----
 4 files changed, 36 insertions(+), 60 deletions(-)

diff --git 
a/components/camel-jira/src/test/java/org/apache/camel/component/jira/producer/AddIssueLinkProducerTest.java
 
b/components/camel-jira/src/test/java/org/apache/camel/component/jira/producer/AddIssueLinkProducerTest.java
index 30c63c72b542..6b39b8f0606e 100644
--- 
a/components/camel-jira/src/test/java/org/apache/camel/component/jira/producer/AddIssueLinkProducerTest.java
+++ 
b/components/camel-jira/src/test/java/org/apache/camel/component/jira/producer/AddIssueLinkProducerTest.java
@@ -55,7 +55,7 @@ import static 
org.apache.camel.component.jira.Utils.createIssueWithLinks;
 import static org.apache.camel.component.jira.Utils.newIssueLink;
 import static org.apache.camel.test.junit5.TestSupport.assertIsInstanceOf;
 import static org.apache.camel.test.junit5.TestSupport.assertStringContains;
-import static org.junit.jupiter.api.Assertions.fail;
+import static org.junit.jupiter.api.Assertions.assertThrows;
 import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.Mockito.lenient;
 import static org.mockito.Mockito.never;
@@ -175,13 +175,10 @@ public class AddIssueLinkProducerTest extends 
CamelTestSupport {
         headers.put(CHILD_ISSUE_KEY, childIssue.getKey());
         headers.put(LINK_TYPE, linkType);
 
-        try {
-            template.sendBodyAndHeaders(comment, headers);
-            fail("Should have thrown an exception");
-        } catch (CamelExecutionException e) {
-            IllegalArgumentException cause = 
assertIsInstanceOf(IllegalArgumentException.class, e.getCause());
-            assertStringContains(cause.getMessage(), PARENT_ISSUE_KEY);
-        }
+        CamelExecutionException e = assertThrows(CamelExecutionException.class,
+                () -> template.sendBodyAndHeaders(comment, headers));
+        IllegalArgumentException cause = 
assertIsInstanceOf(IllegalArgumentException.class, e.getCause());
+        assertStringContains(cause.getMessage(), PARENT_ISSUE_KEY);
 
         mockResult.expectedMessageCount(0);
         mockResult.assertIsSatisfied();
@@ -197,13 +194,10 @@ public class AddIssueLinkProducerTest extends 
CamelTestSupport {
         headers.put(PARENT_ISSUE_KEY, parentIssue.getKey());
         headers.put(LINK_TYPE, linkType);
 
-        try {
-            template.sendBodyAndHeaders(comment, headers);
-            fail("Should have thrown an exception");
-        } catch (CamelExecutionException e) {
-            IllegalArgumentException cause = 
assertIsInstanceOf(IllegalArgumentException.class, e.getCause());
-            assertStringContains(cause.getMessage(), CHILD_ISSUE_KEY);
-        }
+        CamelExecutionException e = assertThrows(CamelExecutionException.class,
+                () -> template.sendBodyAndHeaders(comment, headers));
+        IllegalArgumentException cause = 
assertIsInstanceOf(IllegalArgumentException.class, e.getCause());
+        assertStringContains(cause.getMessage(), CHILD_ISSUE_KEY);
 
         mockResult.expectedMessageCount(0);
         mockResult.assertIsSatisfied();
@@ -218,13 +212,10 @@ public class AddIssueLinkProducerTest extends 
CamelTestSupport {
         headers.put(PARENT_ISSUE_KEY, parentIssue.getKey());
         headers.put(CHILD_ISSUE_KEY, childIssue.getKey());
 
-        try {
-            template.sendBodyAndHeaders(comment, headers);
-            fail("Should have thrown an exception");
-        } catch (CamelExecutionException e) {
-            IllegalArgumentException cause = 
assertIsInstanceOf(IllegalArgumentException.class, e.getCause());
-            assertStringContains(cause.getMessage(), LINK_TYPE);
-        }
+        CamelExecutionException e = assertThrows(CamelExecutionException.class,
+                () -> template.sendBodyAndHeaders(comment, headers));
+        IllegalArgumentException cause = 
assertIsInstanceOf(IllegalArgumentException.class, e.getCause());
+        assertStringContains(cause.getMessage(), LINK_TYPE);
 
         mockResult.expectedMessageCount(0);
         mockResult.assertIsSatisfied();
diff --git 
a/components/camel-jira/src/test/java/org/apache/camel/component/jira/producer/AddWorkLogProducerTest.java
 
b/components/camel-jira/src/test/java/org/apache/camel/component/jira/producer/AddWorkLogProducerTest.java
index 1e069bfdffa9..b227add2a373 100644
--- 
a/components/camel-jira/src/test/java/org/apache/camel/component/jira/producer/AddWorkLogProducerTest.java
+++ 
b/components/camel-jira/src/test/java/org/apache/camel/component/jira/producer/AddWorkLogProducerTest.java
@@ -56,7 +56,7 @@ import static 
org.apache.camel.component.jira.Utils.createIssueWithWorkLogs;
 import static org.apache.camel.component.jira.Utils.newWorkLog;
 import static org.apache.camel.test.junit5.TestSupport.assertIsInstanceOf;
 import static org.apache.camel.test.junit5.TestSupport.assertStringContains;
-import static org.junit.jupiter.api.Assertions.fail;
+import static org.junit.jupiter.api.Assertions.assertThrows;
 import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.ArgumentMatchers.eq;
 import static org.mockito.Mockito.lenient;
@@ -150,13 +150,10 @@ public class AddWorkLogProducerTest extends 
CamelTestSupport {
         headers.put(MINUTES_SPENT, minutesSpent);
         String comment = "A new test comment " + new Date();
 
-        try {
-            template.sendBodyAndHeaders(comment, headers);
-            fail("Should have thrown an exception");
-        } catch (CamelExecutionException e) {
-            IllegalArgumentException cause = 
assertIsInstanceOf(IllegalArgumentException.class, e.getCause());
-            assertStringContains(cause.getMessage(), ISSUE_KEY);
-        }
+        CamelExecutionException e = assertThrows(CamelExecutionException.class,
+                () -> template.sendBodyAndHeaders(comment, headers));
+        IllegalArgumentException cause = 
assertIsInstanceOf(IllegalArgumentException.class, e.getCause());
+        assertStringContains(cause.getMessage(), ISSUE_KEY);
 
         mockResult.expectedMessageCount(0);
         mockResult.assertIsSatisfied();
@@ -171,13 +168,10 @@ public class AddWorkLogProducerTest extends 
CamelTestSupport {
         headers.put(ISSUE_KEY, backendIssue.getKey());
         String comment = "A new test comment " + new Date();
 
-        try {
-            template.sendBodyAndHeaders(comment, headers);
-            fail("Should have thrown an exception");
-        } catch (CamelExecutionException e) {
-            IllegalArgumentException cause = 
assertIsInstanceOf(IllegalArgumentException.class, e.getCause());
-            assertStringContains(cause.getMessage(), MINUTES_SPENT);
-        }
+        CamelExecutionException e = assertThrows(CamelExecutionException.class,
+                () -> template.sendBodyAndHeaders(comment, headers));
+        IllegalArgumentException cause = 
assertIsInstanceOf(IllegalArgumentException.class, e.getCause());
+        assertStringContains(cause.getMessage(), MINUTES_SPENT);
 
         mockResult.expectedMessageCount(0);
         mockResult.assertIsSatisfied();
@@ -193,13 +187,10 @@ public class AddWorkLogProducerTest extends 
CamelTestSupport {
         headers.put(ISSUE_KEY, backendIssue.getKey());
         headers.put(MINUTES_SPENT, minutesSpent);
 
-        try {
-            template.sendBodyAndHeaders(null, headers);
-            fail("Should have thrown an exception");
-        } catch (CamelExecutionException e) {
-            IllegalArgumentException cause = 
assertIsInstanceOf(IllegalArgumentException.class, e.getCause());
-            assertStringContains(cause.getMessage(), "Missing exchange body");
-        }
+        CamelExecutionException e = assertThrows(CamelExecutionException.class,
+                () -> template.sendBodyAndHeaders(null, headers));
+        IllegalArgumentException cause = 
assertIsInstanceOf(IllegalArgumentException.class, e.getCause());
+        assertStringContains(cause.getMessage(), "Missing exchange body");
 
         mockResult.expectedMessageCount(0);
         mockResult.assertIsSatisfied();
diff --git 
a/components/camel-jira/src/test/java/org/apache/camel/component/jira/producer/FetchCommentsProducerTest.java
 
b/components/camel-jira/src/test/java/org/apache/camel/component/jira/producer/FetchCommentsProducerTest.java
index 4345092ee316..6d35dee8e8c6 100644
--- 
a/components/camel-jira/src/test/java/org/apache/camel/component/jira/producer/FetchCommentsProducerTest.java
+++ 
b/components/camel-jira/src/test/java/org/apache/camel/component/jira/producer/FetchCommentsProducerTest.java
@@ -42,7 +42,7 @@ import static 
org.apache.camel.component.jira.JiraConstants.JIRA_REST_CLIENT_FAC
 import static 
org.apache.camel.component.jira.JiraTestConstants.JIRA_CREDENTIALS;
 import static org.apache.camel.test.junit5.TestSupport.assertIsInstanceOf;
 import static org.apache.camel.test.junit5.TestSupport.assertStringContains;
-import static org.junit.jupiter.api.Assertions.fail;
+import static org.junit.jupiter.api.Assertions.assertThrows;
 import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.Mockito.lenient;
 import static org.mockito.Mockito.never;
@@ -117,13 +117,10 @@ public class FetchCommentsProducerTest extends 
CamelTestSupport {
 
     @Test
     public void testFetchCommentsMissingIssueKey() throws InterruptedException 
{
-        try {
-            template.sendBody(null);
-            fail("Should have thrown an exception");
-        } catch (CamelExecutionException e) {
-            IllegalArgumentException cause = 
assertIsInstanceOf(IllegalArgumentException.class, e.getCause());
-            assertStringContains(cause.getMessage(), ISSUE_KEY);
-        }
+        CamelExecutionException e = assertThrows(CamelExecutionException.class,
+                () -> template.sendBody(null));
+        IllegalArgumentException cause = 
assertIsInstanceOf(IllegalArgumentException.class, e.getCause());
+        assertStringContains(cause.getMessage(), ISSUE_KEY);
 
         mockResult.expectedMessageCount(0);
         mockResult.assertIsSatisfied();
diff --git 
a/components/camel-jira/src/test/java/org/apache/camel/component/jira/producer/FetchIssueProducerTest.java
 
b/components/camel-jira/src/test/java/org/apache/camel/component/jira/producer/FetchIssueProducerTest.java
index 109519d09f02..836c2d7b3915 100644
--- 
a/components/camel-jira/src/test/java/org/apache/camel/component/jira/producer/FetchIssueProducerTest.java
+++ 
b/components/camel-jira/src/test/java/org/apache/camel/component/jira/producer/FetchIssueProducerTest.java
@@ -42,7 +42,7 @@ import static 
org.apache.camel.component.jira.JiraConstants.JIRA_REST_CLIENT_FAC
 import static 
org.apache.camel.component.jira.JiraTestConstants.JIRA_CREDENTIALS;
 import static org.apache.camel.test.junit5.TestSupport.assertIsInstanceOf;
 import static org.apache.camel.test.junit5.TestSupport.assertStringContains;
-import static org.junit.jupiter.api.Assertions.fail;
+import static org.junit.jupiter.api.Assertions.assertThrows;
 import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.Mockito.lenient;
 import static org.mockito.Mockito.never;
@@ -116,13 +116,10 @@ public class FetchIssueProducerTest extends 
CamelTestSupport {
 
     @Test
     public void testFetchIssueMissingIssueKey() throws InterruptedException {
-        try {
-            template.sendBody(null);
-            fail("Should have thrown an exception");
-        } catch (CamelExecutionException e) {
-            IllegalArgumentException cause = 
assertIsInstanceOf(IllegalArgumentException.class, e.getCause());
-            assertStringContains(cause.getMessage(), ISSUE_KEY);
-        }
+        CamelExecutionException e = assertThrows(CamelExecutionException.class,
+                () -> template.sendBody(null));
+        IllegalArgumentException cause = 
assertIsInstanceOf(IllegalArgumentException.class, e.getCause());
+        assertStringContains(cause.getMessage(), ISSUE_KEY);
 
         mockResult.expectedMessageCount(0);
         mockResult.assertIsSatisfied();

Reply via email to