gnodet commented on code in PR #21869:
URL: https://github.com/apache/camel/pull/21869#discussion_r2912273890
##########
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:
Good suggestion! Replaced with `assertInstanceOf(IOException.class,
reply.getException().getCause())` from JUnit 5 (AssertJ is not available in
this module). See 409b7e3.
--
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]