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 83996de6c3270ca018713cc1064b8f52c17ae25c Author: Otavio Rodolfo Piske <[email protected]> AuthorDate: Sat Jan 24 19:37:04 2026 +0000 CAMEL-21196: modernize exception-based assertions in camel-dns --- .../camel/component/dns/DnsIpEndpointSpringTest.java | 18 +++++++----------- .../apache/camel/component/dns/DnsIpEndpointTest.java | 18 +++++++----------- .../camel/component/dns/DnsIpHeaderTransferTest.java | 18 +++++++----------- .../component/dns/DnsLookupEndpointSpringTest.java | 18 +++++++----------- .../camel/component/dns/DnsLookupEndpointTest.java | 18 +++++++----------- 5 files changed, 35 insertions(+), 55 deletions(-) diff --git a/components/camel-dns/src/test/java/org/apache/camel/component/dns/DnsIpEndpointSpringTest.java b/components/camel-dns/src/test/java/org/apache/camel/component/dns/DnsIpEndpointSpringTest.java index 93f88f62f17f..e526b243bc1e 100644 --- a/components/camel-dns/src/test/java/org/apache/camel/component/dns/DnsIpEndpointSpringTest.java +++ b/components/camel-dns/src/test/java/org/apache/camel/component/dns/DnsIpEndpointSpringTest.java @@ -26,8 +26,8 @@ import org.junit.jupiter.api.Test; import org.springframework.context.support.AbstractApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; +import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.junit.jupiter.api.Assertions.fail; /** * A series of tests to check the IP lookup operation. @@ -43,24 +43,20 @@ public class DnsIpEndpointSpringTest extends CamelSpringTestSupport { @Test void testNullIPRequests() throws Exception { resultEndpoint.expectedMessageCount(0); - try { + Exception e = assertThrows(Exception.class, () -> { template.sendBodyAndHeader("hello", "dns.domain", null); - fail("Should have thrown exception"); - } catch (Exception t) { - assertTrue(t.getCause() instanceof IllegalArgumentException); - } + }); + assertTrue(e.getCause() instanceof IllegalArgumentException); resultEndpoint.assertIsSatisfied(); } @Test void testEmptyIPRequests() throws Exception { resultEndpoint.expectedMessageCount(0); - try { + Exception e = assertThrows(Exception.class, () -> { template.sendBodyAndHeader("hello", "dns.domain", ""); - fail("Should have thrown exception"); - } catch (Exception t) { - assertTrue(t.getCause() instanceof IllegalArgumentException); - } + }); + assertTrue(e.getCause() instanceof IllegalArgumentException); resultEndpoint.assertIsSatisfied(); } diff --git a/components/camel-dns/src/test/java/org/apache/camel/component/dns/DnsIpEndpointTest.java b/components/camel-dns/src/test/java/org/apache/camel/component/dns/DnsIpEndpointTest.java index 91a2c0eba20b..41be3b617ab9 100644 --- a/components/camel-dns/src/test/java/org/apache/camel/component/dns/DnsIpEndpointTest.java +++ b/components/camel-dns/src/test/java/org/apache/camel/component/dns/DnsIpEndpointTest.java @@ -25,8 +25,8 @@ import org.apache.camel.test.junit5.CamelTestSupport; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.junit.jupiter.api.Assertions.fail; /** * A series of tests to check the IP lookup operation. @@ -52,24 +52,20 @@ public class DnsIpEndpointTest extends CamelTestSupport { @Test void testNullIPRequests() throws Exception { resultEndpoint.expectedMessageCount(0); - try { + Exception e = assertThrows(Exception.class, () -> { template.sendBodyAndHeader("hello", "dns.domain", null); - fail("Should have thrown exception"); - } catch (Exception t) { - assertTrue(t.getCause() instanceof IllegalArgumentException); - } + }); + assertTrue(e.getCause() instanceof IllegalArgumentException); resultEndpoint.assertIsSatisfied(); } @Test void testEmptyIPRequests() throws Exception { resultEndpoint.expectedMessageCount(0); - try { + Exception e = assertThrows(Exception.class, () -> { template.sendBodyAndHeader("hello", "dns.domain", ""); - fail("Should have thrown exception"); - } catch (Exception t) { - assertTrue(t.getCause() instanceof IllegalArgumentException); - } + }); + assertTrue(e.getCause() instanceof IllegalArgumentException); resultEndpoint.assertIsSatisfied(); } diff --git a/components/camel-dns/src/test/java/org/apache/camel/component/dns/DnsIpHeaderTransferTest.java b/components/camel-dns/src/test/java/org/apache/camel/component/dns/DnsIpHeaderTransferTest.java index da712b107db6..cdaa093ed821 100644 --- a/components/camel-dns/src/test/java/org/apache/camel/component/dns/DnsIpHeaderTransferTest.java +++ b/components/camel-dns/src/test/java/org/apache/camel/component/dns/DnsIpHeaderTransferTest.java @@ -25,8 +25,8 @@ import org.apache.camel.test.junit5.CamelTestSupport; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.junit.jupiter.api.Assertions.fail; public class DnsIpHeaderTransferTest extends CamelTestSupport { @@ -50,12 +50,10 @@ public class DnsIpHeaderTransferTest extends CamelTestSupport { void testNullIPRequests() throws Exception { resultEndpoint.expectedMessageCount(0); - try { + Exception e = assertThrows(Exception.class, () -> { template.sendBodyAndHeader("hello", "dns.domain", null); - fail("Should have thrown exception"); - } catch (Exception t) { - assertTrue(t.getCause() instanceof IllegalArgumentException); - } + }); + assertTrue(e.getCause() instanceof IllegalArgumentException); resultEndpoint.assertIsSatisfied(); } @@ -63,12 +61,10 @@ public class DnsIpHeaderTransferTest extends CamelTestSupport { void testEmptyIPRequests() throws Exception { resultEndpoint.expectedMessageCount(0); - try { + Exception e = assertThrows(Exception.class, () -> { template.sendBodyAndHeader("hello", "dns.domain", ""); - fail("Should have thrown exception"); - } catch (Exception t) { - assertTrue(t.getCause() instanceof IllegalArgumentException); - } + }); + assertTrue(e.getCause() instanceof IllegalArgumentException); resultEndpoint.assertIsSatisfied(); } diff --git a/components/camel-dns/src/test/java/org/apache/camel/component/dns/DnsLookupEndpointSpringTest.java b/components/camel-dns/src/test/java/org/apache/camel/component/dns/DnsLookupEndpointSpringTest.java index 8e88cab02d97..715825753a48 100644 --- a/components/camel-dns/src/test/java/org/apache/camel/component/dns/DnsLookupEndpointSpringTest.java +++ b/components/camel-dns/src/test/java/org/apache/camel/component/dns/DnsLookupEndpointSpringTest.java @@ -32,8 +32,8 @@ import org.springframework.context.support.AbstractApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; import org.xbill.DNS.Record; +import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.junit.jupiter.api.Assertions.fail; /** * A set of test cases to make DNS lookups. @@ -49,24 +49,20 @@ public class DnsLookupEndpointSpringTest extends CamelSpringTestSupport { @Test void testDNSWithNoHeaders() throws Exception { resultEndpoint.expectedMessageCount(0); - try { + Exception e = assertThrows(Exception.class, () -> { template.sendBody("hello"); - fail("Should have thrown exception"); - } catch (Exception t) { - assertTrue(t.getCause() instanceof IllegalArgumentException); - } + }); + assertTrue(e.getCause() instanceof IllegalArgumentException); resultEndpoint.assertIsSatisfied(); } @Test void testDNSWithEmptyNameHeader() throws Exception { resultEndpoint.expectedMessageCount(0); - try { + Exception e = assertThrows(Exception.class, () -> { template.sendBodyAndHeader("hello", "dns.name", ""); - fail("Should have thrown exception"); - } catch (Exception t) { - assertTrue(t.getCause() instanceof IllegalArgumentException, t.toString()); - } + }); + assertTrue(e.getCause() instanceof IllegalArgumentException, e.toString()); resultEndpoint.assertIsSatisfied(); } diff --git a/components/camel-dns/src/test/java/org/apache/camel/component/dns/DnsLookupEndpointTest.java b/components/camel-dns/src/test/java/org/apache/camel/component/dns/DnsLookupEndpointTest.java index fd21dae42797..500a8e0e0b15 100644 --- a/components/camel-dns/src/test/java/org/apache/camel/component/dns/DnsLookupEndpointTest.java +++ b/components/camel-dns/src/test/java/org/apache/camel/component/dns/DnsLookupEndpointTest.java @@ -31,8 +31,8 @@ import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import org.xbill.DNS.Record; +import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.junit.jupiter.api.Assertions.fail; /** * A set of test cases to make DNS lookups. @@ -58,24 +58,20 @@ public class DnsLookupEndpointTest extends CamelTestSupport { @Test void testDNSWithNoHeaders() throws Exception { resultEndpoint.expectedMessageCount(0); - try { + Exception e = assertThrows(Exception.class, () -> { template.sendBody("hello"); - fail("Should have thrown exception"); - } catch (Exception t) { - assertTrue(t.getCause() instanceof IllegalArgumentException); - } + }); + assertTrue(e.getCause() instanceof IllegalArgumentException); resultEndpoint.assertIsSatisfied(); } @Test void testDNSWithEmptyNameHeader() throws Exception { resultEndpoint.expectedMessageCount(0); - try { + Exception e = assertThrows(Exception.class, () -> { template.sendBodyAndHeader("hello", "dns.name", ""); - fail("Should have thrown exception"); - } catch (Exception t) { - assertTrue(t.getCause() instanceof IllegalArgumentException, t.toString()); - } + }); + assertTrue(e.getCause() instanceof IllegalArgumentException, e.toString()); resultEndpoint.assertIsSatisfied(); }
