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 9c36cc4258739e93183d717d23d9abbd0f1c49af Author: Otavio R. Piske <[email protected]> AuthorDate: Sat Jan 24 11:03:10 2026 +0100 CAMEL-21196: modernize exception-based assertions in camel-soap --- .../soap/name/ServiceInterfaceStrategyTest.java | 38 ++++++++-------------- .../converter/soap/name/TypeNameStrategyTest.java | 10 ++---- .../camel/dataformat/soap/SoapCxfClientTest.java | 14 ++++---- .../camel/dataformat/soap/SoapCxfServerTest.java | 14 ++++---- .../camel/dataformat/soap/SoapUnMarshalTest.java | 14 ++++---- .../dataformat/soap12/Soap12UnMarshalTest.java | 14 ++++---- 6 files changed, 41 insertions(+), 63 deletions(-) diff --git a/components/camel-soap/src/test/java/org/apache/camel/converter/soap/name/ServiceInterfaceStrategyTest.java b/components/camel-soap/src/test/java/org/apache/camel/converter/soap/name/ServiceInterfaceStrategyTest.java index 5b2e662526e6..d00a1aee6df7 100644 --- a/components/camel-soap/src/test/java/org/apache/camel/converter/soap/name/ServiceInterfaceStrategyTest.java +++ b/components/camel-soap/src/test/java/org/apache/camel/converter/soap/name/ServiceInterfaceStrategyTest.java @@ -33,6 +33,7 @@ import org.slf4j.LoggerFactory; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.fail; public class ServiceInterfaceStrategyTest { @@ -58,12 +59,9 @@ public class ServiceInterfaceStrategyTest { null); assertNull(elName4); - try { - elName = strategy.findQNameForSoapActionOrType("test", Class.class); - fail(); - } catch (RuntimeCamelException e) { - LOG.debug("Caught expected message: {}", e.getMessage()); - } + Exception e = assertThrows(RuntimeCamelException.class, + () -> strategy.findQNameForSoapActionOrType("test", Class.class)); + LOG.debug("Caught expected message: {}", e.getMessage()); } @Test @@ -83,12 +81,9 @@ public class ServiceInterfaceStrategyTest { // this tests the case that the soap action as well as the type are not // found - try { - elName = strategy.findQNameForSoapActionOrType("test", Class.class); - fail(); - } catch (RuntimeCamelException e) { - LOG.debug("Caught expected message: {}", e.getMessage()); - } + Exception e = assertThrows(RuntimeCamelException.class, + () -> strategy.findQNameForSoapActionOrType("test", Class.class)); + LOG.debug("Caught expected message: {}", e.getMessage()); } @Test @@ -99,22 +94,17 @@ public class ServiceInterfaceStrategyTest { assertEquals("http://customerservice2.example.com/", elName.getNamespaceURI()); assertEquals("getCustomersByName", elName.getLocalPart()); - try { - elName = strategy.findQNameForSoapActionOrType("test", Class.class); - fail(); - } catch (RuntimeCamelException e) { - LOG.debug("Caught expected message: {}", e.getMessage()); - } + Exception e = assertThrows(RuntimeCamelException.class, + () -> strategy.findQNameForSoapActionOrType("test", Class.class)); + LOG.debug("Caught expected message: {}", e.getMessage()); } @Test public void testWithNonWebservice() { - try { - new ServiceInterfaceStrategy(Object.class, true); - fail("Should throw an exception for a class that is no webservice"); - } catch (IllegalArgumentException e) { - LOG.debug("Caught expected message: {}", e.getMessage()); - } + Exception e = assertThrows(IllegalArgumentException.class, + () -> new ServiceInterfaceStrategy(Object.class, true), + "Should throw an exception for a class that is no webservice"); + LOG.debug("Caught expected message: {}", e.getMessage()); } @Test diff --git a/components/camel-soap/src/test/java/org/apache/camel/converter/soap/name/TypeNameStrategyTest.java b/components/camel-soap/src/test/java/org/apache/camel/converter/soap/name/TypeNameStrategyTest.java index 1b321d2eaf00..47ae483bb9f9 100644 --- a/components/camel-soap/src/test/java/org/apache/camel/converter/soap/name/TypeNameStrategyTest.java +++ b/components/camel-soap/src/test/java/org/apache/camel/converter/soap/name/TypeNameStrategyTest.java @@ -23,7 +23,7 @@ import org.apache.camel.dataformat.soap.name.TypeNameStrategy; import org.junit.jupiter.api.Test; 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 TypeNameStrategyTest { @@ -38,12 +38,8 @@ public class TypeNameStrategyTest { @Test public void testNoAnnotation() { TypeNameStrategy strategy = new TypeNameStrategy(); - try { - strategy.findQNameForSoapActionOrType("", String.class); - fail(); - } catch (RuntimeException e) { - // Expected here - } + assertThrows(RuntimeException.class, + () -> strategy.findQNameForSoapActionOrType("", String.class)); } @Test diff --git a/components/camel-soap/src/test/java/org/apache/camel/dataformat/soap/SoapCxfClientTest.java b/components/camel-soap/src/test/java/org/apache/camel/dataformat/soap/SoapCxfClientTest.java index 54f96269b807..10557f42c078 100644 --- a/components/camel-soap/src/test/java/org/apache/camel/dataformat/soap/SoapCxfClientTest.java +++ b/components/camel-soap/src/test/java/org/apache/camel/dataformat/soap/SoapCxfClientTest.java @@ -38,7 +38,7 @@ import org.springframework.test.context.ContextConfiguration; 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; /** * Checks for interoperability between a CXF client that is attached using the Camel transport for CXF and the SOAP data @@ -91,13 +91,11 @@ public class SoapCxfClientTest extends RouteBuilder { public void testFault() { GetCustomersByName request = new GetCustomersByName(); request.setName("none"); - try { - customerService.getCustomersByName(request); - fail("NoSuchCustomerException expected"); - } catch (NoSuchCustomerException e) { - NoSuchCustomer info = e.getFaultInfo(); - assertEquals("none", info.getCustomerId()); - } + NoSuchCustomerException e = assertThrows(NoSuchCustomerException.class, + () -> customerService.getCustomersByName(request), + "NoSuchCustomerException expected"); + NoSuchCustomer info = e.getFaultInfo(); + assertEquals("none", info.getCustomerId()); } diff --git a/components/camel-soap/src/test/java/org/apache/camel/dataformat/soap/SoapCxfServerTest.java b/components/camel-soap/src/test/java/org/apache/camel/dataformat/soap/SoapCxfServerTest.java index f81c5ab3f8ef..de1673ce9db3 100644 --- a/components/camel-soap/src/test/java/org/apache/camel/dataformat/soap/SoapCxfServerTest.java +++ b/components/camel-soap/src/test/java/org/apache/camel/dataformat/soap/SoapCxfServerTest.java @@ -34,7 +34,7 @@ import org.springframework.test.context.ContextConfiguration; 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; /** * Checks for interoperability between a CXF server that is attached using the Camel transport for CXF and a dynamic @@ -61,13 +61,11 @@ public class SoapCxfServerTest extends RouteBuilder { public void testFault() { GetCustomersByName request = new GetCustomersByName(); request.setName("none"); - try { - customerServiceProxy.getCustomersByName(request); - fail("NoSuchCustomerException expected"); - } catch (NoSuchCustomerException e) { - NoSuchCustomer info = e.getFaultInfo(); - assertEquals("none", info.getCustomerId()); - } + NoSuchCustomerException e = assertThrows(NoSuchCustomerException.class, + () -> customerServiceProxy.getCustomersByName(request), + "NoSuchCustomerException expected"); + NoSuchCustomer info = e.getFaultInfo(); + assertEquals("none", info.getCustomerId()); } @Override diff --git a/components/camel-soap/src/test/java/org/apache/camel/dataformat/soap/SoapUnMarshalTest.java b/components/camel-soap/src/test/java/org/apache/camel/dataformat/soap/SoapUnMarshalTest.java index 4ff6e28e0981..132e332b89fb 100644 --- a/components/camel-soap/src/test/java/org/apache/camel/dataformat/soap/SoapUnMarshalTest.java +++ b/components/camel-soap/src/test/java/org/apache/camel/dataformat/soap/SoapUnMarshalTest.java @@ -32,7 +32,7 @@ import org.apache.camel.test.junit5.CamelTestSupport; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.fail; +import static org.junit.jupiter.api.Assertions.assertThrows; /** * Checks that a static soap request is unmarshalled to the correct java objects @@ -62,13 +62,11 @@ public class SoapUnMarshalTest extends CamelTestSupport { @Test public void testUnMarshalSoapFaultWithoutDetail() throws IOException, InterruptedException { - try { - InputStream in = this.getClass().getResourceAsStream("faultWithoutDetail.xml"); - producer.sendBody(in); - fail("Should have thrown an Exception."); - } catch (Exception e) { - assertEquals(SOAPFaultException.class, e.getCause().getClass()); - } + InputStream in = this.getClass().getResourceAsStream("faultWithoutDetail.xml"); + Exception e = assertThrows(Exception.class, + () -> producer.sendBody(in), + "Should have thrown an Exception."); + assertEquals(SOAPFaultException.class, e.getCause().getClass()); } @Override diff --git a/components/camel-soap/src/test/java/org/apache/camel/dataformat/soap12/Soap12UnMarshalTest.java b/components/camel-soap/src/test/java/org/apache/camel/dataformat/soap12/Soap12UnMarshalTest.java index 694fe3408cb8..d1fb2784104d 100644 --- a/components/camel-soap/src/test/java/org/apache/camel/dataformat/soap12/Soap12UnMarshalTest.java +++ b/components/camel-soap/src/test/java/org/apache/camel/dataformat/soap12/Soap12UnMarshalTest.java @@ -32,7 +32,7 @@ import org.apache.camel.test.junit5.CamelTestSupport; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.fail; +import static org.junit.jupiter.api.Assertions.assertThrows; /** * Checks that a static soap request is unmarshalled to the correct java objects @@ -62,13 +62,11 @@ public class Soap12UnMarshalTest extends CamelTestSupport { @Test public void testUnMarshalSoapFaultWithoutDetail() throws IOException, InterruptedException { - try { - InputStream in = this.getClass().getResourceAsStream("faultWithoutDetail.xml"); - producer.sendBody(in); - fail("Should have thrown an Exception."); - } catch (Exception e) { - assertEquals(SOAPFaultException.class, e.getCause().getClass()); - } + InputStream in = this.getClass().getResourceAsStream("faultWithoutDetail.xml"); + Exception e = assertThrows(Exception.class, + () -> producer.sendBody(in), + "Should have thrown an Exception."); + assertEquals(SOAPFaultException.class, e.getCause().getClass()); } @Override
