This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/main by this push:
     new 2cfcbf881e0 CAMEL-19767: Light refactoring on test using 
AssertionError (#15613)
2cfcbf881e0 is described below

commit 2cfcbf881e052172719f175a583f0ce728f83cf8
Author: GaĆ«lle Fournier <[email protected]>
AuthorDate: Wed Sep 18 20:18:13 2024 +0200

    CAMEL-19767: Light refactoring on test using AssertionError (#15613)
---
 .../org/apache/camel/jsonpath/JsonStreamTest.java    | 16 ++++++----------
 .../apache/camel/component/mail/MailSorterTest.java  | 20 ++++----------------
 .../camel/support/jsse/SSLContextParametersTest.java | 11 +++++------
 3 files changed, 15 insertions(+), 32 deletions(-)

diff --git 
a/components/camel-jsonpath/src/test/java/org/apache/camel/jsonpath/JsonStreamTest.java
 
b/components/camel-jsonpath/src/test/java/org/apache/camel/jsonpath/JsonStreamTest.java
index da16e515125..ada06f17188 100644
--- 
a/components/camel-jsonpath/src/test/java/org/apache/camel/jsonpath/JsonStreamTest.java
+++ 
b/components/camel-jsonpath/src/test/java/org/apache/camel/jsonpath/JsonStreamTest.java
@@ -25,7 +25,7 @@ import org.junit.jupiter.api.Test;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertNotNull;
-import static org.junit.jupiter.api.Assertions.fail;
+import static org.junit.jupiter.api.Assertions.assertThrows;
 
 public class JsonStreamTest {
 
@@ -35,13 +35,10 @@ public class JsonStreamTest {
     }
 
     @Test
-    public void iSO88591() throws Exception {
-        try {
-            test("json_stream/jsonISO8859-1.txt", "ISO-8859-1");
-            fail("Error expected");
-        } catch (AssertionError e) {
-            assertEquals("expected: <ISO-8859-1> but was: <UTF-8>", 
e.getMessage());
-        }
+    public void iSO88591() {
+        AssertionError error = assertThrows(AssertionError.class, () -> 
test("json_stream/jsonISO8859-1.txt", "ISO-8859-1"),
+                "Error expected");
+        assertEquals("expected: <ISO-8859-1> but was: <UTF-8>", 
error.getMessage());
     }
 
     @Test
@@ -123,7 +120,6 @@ public class JsonStreamTest {
         byte[] buffer = new byte[2048];
         int len = js.read(buffer);
         js.close();
-        byte[] result = Arrays.copyOf(buffer, len);
-        return result;
+        return Arrays.copyOf(buffer, len);
     }
 }
diff --git 
a/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailSorterTest.java
 
b/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailSorterTest.java
index a325cb1cec4..d05d9f351ac 100644
--- 
a/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailSorterTest.java
+++ 
b/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailSorterTest.java
@@ -77,18 +77,14 @@ public class MailSorterTest extends CamelTestSupport {
     }
 
     @Test
-    public void testSortMessages() throws Exception {
+    public void testSortMessages() {
         Message[] expected = new Message[] { MESSAGES[0], MESSAGES[1], 
MESSAGES[2] };
 
         // Sort using all the terms. Message order should be the same no 
matter what term is used
         for (SortTerm term : POSSIBLE_TERMS) {
             Message[] actual = MESSAGES.clone();
             MailSorter.sortMessages(actual, new SortTerm[] { term });
-            try {
-                assertArrayEquals(actual, expected);
-            } catch (Exception ex) {
-                throw new Exception("Term: " + term.toString(), ex);
-            }
+            assertArrayEquals(actual, expected, "Term: " + term.toString());
         }
     }
 
@@ -100,11 +96,7 @@ public class MailSorterTest extends CamelTestSupport {
         for (SortTerm term : POSSIBLE_TERMS) {
             Message[] actual = MESSAGES.clone();
             MailSorter.sortMessages(actual, new SortTerm[] { SortTerm.REVERSE, 
term });
-            try {
-                assertArrayEquals(actual, expected);
-            } catch (AssertionError ex) {
-                throw new AssertionError("Term: " + term.toString(), ex);
-            }
+            assertArrayEquals(actual, expected, "Term: " + term.toString());
         }
     }
 
@@ -118,11 +110,7 @@ public class MailSorterTest extends CamelTestSupport {
             for (SortTerm term2 : POSSIBLE_TERMS) {
                 Message[] actual = MESSAGES.clone();
                 MailSorter.sortMessages(actual, new SortTerm[] { term1, 
SortTerm.REVERSE, term2 });
-                try {
-                    assertArrayEquals(actual, expected);
-                } catch (AssertionError ex) {
-                    throw new AssertionError(String.format("Terms: %s, %s", 
term1.toString(), term2.toString()), ex);
-                }
+                assertArrayEquals(actual, expected, String.format("Terms: %s, 
%s", term1.toString(), term2.toString()));
             }
 
         }
diff --git 
a/core/camel-core/src/test/java/org/apache/camel/support/jsse/SSLContextParametersTest.java
 
b/core/camel-core/src/test/java/org/apache/camel/support/jsse/SSLContextParametersTest.java
index cdbe21a823c..0df49fd146f 100644
--- 
a/core/camel-core/src/test/java/org/apache/camel/support/jsse/SSLContextParametersTest.java
+++ 
b/core/camel-core/src/test/java/org/apache/camel/support/jsse/SSLContextParametersTest.java
@@ -51,12 +51,11 @@ public class SSLContextParametersTest extends 
AbstractJsseParametersTest {
                 List.of(Pattern.compile("SSL.*")));
         assertEquals(2, result.size());
         assertStartsWith(result, "TLS");
-        try {
-            assertStartsWith((String[]) null, "TLS");
-            fail("We should got an exception here!");
-        } catch (AssertionError ex) {
-            assertTrue(ex.getMessage().contains("The values should not be 
null"), "Get a wrong message");
-        }
+
+        AssertionError error
+                = assertThrows(AssertionError.class, () -> 
assertStartsWith((String[]) null, "TLS"),
+                        "We should got an exception here!");
+        assertTrue(error.getMessage().contains("The values should not be 
null"), "Get a wrong message");
     }
 
     @Test

Reply via email to