apupier commented on code in PR #21869:
URL: https://github.com/apache/camel/pull/21869#discussion_r2911438512


##########
components/camel-cxf/camel-cxf-soap/src/test/java/org/apache/camel/component/cxf/jaxws/CxfProducerTest.java:
##########
@@ -136,17 +137,28 @@ public void testInvokingSimpleServerWithParams() throws 
Exception {
     public void testInvokingAWrongServer() throws Exception {
         Exchange reply = sendSimpleMessage(getWrongEndpointUri());
         assertNotNull(reply.getException(), "We should get the exception 
here");
-        assertTrue(reply.getException().getCause() instanceof 
ConnectException);
+        assertHasCauseOfType(reply.getException(), IOException.class);
 
         //Test the data format PAYLOAD
         reply = sendSimpleMessageWithPayloadMessage(getWrongEndpointUri() + 
"&dataFormat=PAYLOAD");
         assertNotNull(reply.getException(), "We should get the exception 
here");
-        assertTrue(reply.getException().getCause() instanceof 
ConnectException);
+        assertHasCauseOfType(reply.getException(), IOException.class);
 
         //Test the data format MESSAGE
         reply = sendSimpleMessageWithRawMessage(getWrongEndpointUri() + 
"&dataFormat=RAW");
         assertNotNull(reply.getException(), "We should get the exception 
here");
-        assertTrue(reply.getException().getCause() instanceof 
ConnectException);
+        assertHasCauseOfType(reply.getException(), IOException.class);
+    }
+
+    private static void assertHasCauseOfType(Throwable throwable, Class<? 
extends Throwable> type) {
+        Throwable cause = throwable;
+        while (cause != null) {
+            if (type.isInstance(cause)) {
+                return;
+            }
+            cause = cause.getCause();
+        }
+        fail("Expected a cause of type " + type.getName() + " in exception 
chain of: " + throwable);
     }

Review Comment:
   wondering if we can use the AssertJ hasCauseInstanceOf 
https://github.com/assertj/assertj-examples/blob/b9c1a9095cb195c161d05b4de6ce8bfa5c0e53e0/assertions-examples/src/test/java/org/assertj/examples/ExceptionAssertionsExamples.java#L50



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to