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 852b423c272d7580492a8e4092209d1263706453 Author: Otavio Rodolfo Piske <[email protected]> AuthorDate: Sat Jan 24 19:34:34 2026 +0000 CAMEL-21196: modernize exception-based assertions in camel-disruptor --- .../disruptor/DisruptorConfigureTest.java | 14 ++++---- .../DisruptorInOutChainedTimeoutTest.java | 14 ++++---- .../disruptor/DisruptorInOutWithErrorTest.java | 12 +++---- .../disruptor/DisruptorNoConsumerTest.java | 10 +++--- .../component/disruptor/DisruptorTimeoutTest.java | 24 ++++++------- ...sruptorWaitForTaskCompleteOnCompletionTest.java | 12 +++---- .../vm/DisruptorVmInOutChainedTimeoutTest.java | 16 ++++----- .../vm/DisruptorVmInOutWithErrorTest.java | 12 +++---- .../disruptor/vm/DisruptorVmTimeoutIssueTest.java | 26 ++++++-------- .../vm/SameDisruptorVmQueueSizeAndNoSizeTest.java | 40 +++++++++------------- 10 files changed, 77 insertions(+), 103 deletions(-) diff --git a/components/camel-disruptor/src/test/java/org/apache/camel/component/disruptor/DisruptorConfigureTest.java b/components/camel-disruptor/src/test/java/org/apache/camel/component/disruptor/DisruptorConfigureTest.java index 83d8a2bdb37e..a06944f0a2bb 100644 --- a/components/camel-disruptor/src/test/java/org/apache/camel/component/disruptor/DisruptorConfigureTest.java +++ b/components/camel-disruptor/src/test/java/org/apache/camel/component/disruptor/DisruptorConfigureTest.java @@ -22,7 +22,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; public class DisruptorConfigureTest extends CamelTestSupport { @Test @@ -35,14 +35,12 @@ public class DisruptorConfigureTest extends CamelTestSupport { @Test void testIllegalSizeZeroConfigured() { - try { + ResolveEndpointFailedException e = assertThrows(ResolveEndpointFailedException.class, () -> { resolveMandatoryEndpoint("disruptor:foo?size=0", DisruptorEndpoint.class); - fail("Should have thrown exception"); - } catch (ResolveEndpointFailedException e) { - assertEquals( - "Failed to resolve endpoint: disruptor://foo?size=0 due to: size found to be 0, must be greater than 0", - e.getMessage()); - } + }); + assertEquals( + "Failed to resolve endpoint: disruptor://foo?size=0 due to: size found to be 0, must be greater than 0", + e.getMessage()); } @Test diff --git a/components/camel-disruptor/src/test/java/org/apache/camel/component/disruptor/DisruptorInOutChainedTimeoutTest.java b/components/camel-disruptor/src/test/java/org/apache/camel/component/disruptor/DisruptorInOutChainedTimeoutTest.java index dbc476e85994..83e23c2876dd 100644 --- a/components/camel-disruptor/src/test/java/org/apache/camel/component/disruptor/DisruptorInOutChainedTimeoutTest.java +++ b/components/camel-disruptor/src/test/java/org/apache/camel/component/disruptor/DisruptorInOutChainedTimeoutTest.java @@ -25,22 +25,20 @@ import org.junit.jupiter.api.Test; import static org.apache.camel.test.junit5.TestSupport.assertIsInstanceOf; import static org.junit.jupiter.api.Assertions.assertEquals; +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 DisruptorInOutChainedTimeoutTest extends CamelTestSupport { @Test void testDisruptorInOutChainedTimeout() { // time timeout after 2 sec should trigger a immediately reply final StopWatch watch = new StopWatch(); - try { + CamelExecutionException e = assertThrows(CamelExecutionException.class, () -> { template.requestBody("disruptor:a?timeout=5000", "Hello World"); - fail("Should have thrown an exception"); - } catch (CamelExecutionException e) { - final ExchangeTimedOutException cause = assertIsInstanceOf(ExchangeTimedOutException.class, - e.getCause()); - assertEquals(2000, cause.getTimeout()); - } + }); + final ExchangeTimedOutException cause = assertIsInstanceOf(ExchangeTimedOutException.class, + e.getCause()); + assertEquals(2000, cause.getTimeout()); final long delta = watch.taken(); assertTrue(delta < 4000, "Should be faster than 4000 millis, was: " + delta); diff --git a/components/camel-disruptor/src/test/java/org/apache/camel/component/disruptor/DisruptorInOutWithErrorTest.java b/components/camel-disruptor/src/test/java/org/apache/camel/component/disruptor/DisruptorInOutWithErrorTest.java index 8ee9defcba04..863a525ba6dd 100644 --- a/components/camel-disruptor/src/test/java/org/apache/camel/component/disruptor/DisruptorInOutWithErrorTest.java +++ b/components/camel-disruptor/src/test/java/org/apache/camel/component/disruptor/DisruptorInOutWithErrorTest.java @@ -24,20 +24,18 @@ import org.junit.jupiter.api.Test; import static org.apache.camel.test.junit5.TestSupport.assertIsInstanceOf; 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 DisruptorInOutWithErrorTest extends CamelTestSupport { @Test void testInOutWithError() throws Exception { getMockEndpoint("mock:result").expectedMessageCount(0); - try { + CamelExecutionException e = assertThrows(CamelExecutionException.class, () -> { template.requestBody("direct:start", "Hello World", String.class); - fail("Should have thrown an exception"); - } catch (CamelExecutionException e) { - assertIsInstanceOf(IllegalArgumentException.class, e.getCause()); - assertEquals("Damn I cannot do this", e.getCause().getMessage()); - } + }); + assertIsInstanceOf(IllegalArgumentException.class, e.getCause()); + assertEquals("Damn I cannot do this", e.getCause().getMessage()); MockEndpoint.assertIsSatisfied(context); } diff --git a/components/camel-disruptor/src/test/java/org/apache/camel/component/disruptor/DisruptorNoConsumerTest.java b/components/camel-disruptor/src/test/java/org/apache/camel/component/disruptor/DisruptorNoConsumerTest.java index c90371a79a52..12bfb0e9193e 100644 --- a/components/camel-disruptor/src/test/java/org/apache/camel/component/disruptor/DisruptorNoConsumerTest.java +++ b/components/camel-disruptor/src/test/java/org/apache/camel/component/disruptor/DisruptorNoConsumerTest.java @@ -24,7 +24,7 @@ import org.junit.jupiter.api.Test; import static org.apache.camel.test.junit5.TestSupport.assertIsInstanceOf; import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; -import static org.junit.jupiter.api.Assertions.fail; +import static org.junit.jupiter.api.Assertions.assertThrows; public class DisruptorNoConsumerTest extends CamelTestSupport { @Test @@ -35,12 +35,10 @@ public class DisruptorNoConsumerTest extends CamelTestSupport { @Test void testInOut() { - try { + CamelExecutionException e = assertThrows(CamelExecutionException.class, () -> { template.requestBody("direct:start", "Hello World"); - fail("Should throw an exception"); - } catch (CamelExecutionException e) { - assertIsInstanceOf(ExchangeTimedOutException.class, e.getCause()); - } + }); + assertIsInstanceOf(ExchangeTimedOutException.class, e.getCause()); } @Override diff --git a/components/camel-disruptor/src/test/java/org/apache/camel/component/disruptor/DisruptorTimeoutTest.java b/components/camel-disruptor/src/test/java/org/apache/camel/component/disruptor/DisruptorTimeoutTest.java index cbd8e584001a..fe88d772db41 100644 --- a/components/camel-disruptor/src/test/java/org/apache/camel/component/disruptor/DisruptorTimeoutTest.java +++ b/components/camel-disruptor/src/test/java/org/apache/camel/component/disruptor/DisruptorTimeoutTest.java @@ -30,7 +30,7 @@ import org.junit.jupiter.api.Test; import static org.apache.camel.test.junit5.TestSupport.assertIsInstanceOf; 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 DisruptorTimeoutTest extends CamelTestSupport { private int timeout = 100; @@ -52,20 +52,18 @@ public class DisruptorTimeoutTest extends CamelTestSupport { final Future<String> out = template .asyncRequestBody("disruptor:foo?timeout=" + timeout, "World", String.class); - try { + ExecutionException e = assertThrows(ExecutionException.class, () -> { out.get(); - fail("Should have thrown an exception"); - } catch (ExecutionException e) { - assertIsInstanceOf(CamelExecutionException.class, e.getCause()); - assertIsInstanceOf(ExchangeTimedOutException.class, e.getCause().getCause()); + }); + assertIsInstanceOf(CamelExecutionException.class, e.getCause()); + assertIsInstanceOf(ExchangeTimedOutException.class, e.getCause().getCause()); - final DisruptorEndpoint de = (DisruptorEndpoint) context.getRoute("disruptor").getEndpoint(); - assertNotNull(de, "Consumer endpoint cannot be null"); - //we can't remove the exchange from a Disruptor once it is published, but it should never reach the - //mock:result endpoint because it should be filtered out by the DisruptorConsumer - result.await(1, TimeUnit.SECONDS); - MockEndpoint.assertIsSatisfied(context); - } + final DisruptorEndpoint de = (DisruptorEndpoint) context.getRoute("disruptor").getEndpoint(); + assertNotNull(de, "Consumer endpoint cannot be null"); + //we can't remove the exchange from a Disruptor once it is published, but it should never reach the + //mock:result endpoint because it should be filtered out by the DisruptorConsumer + result.await(1, TimeUnit.SECONDS); + MockEndpoint.assertIsSatisfied(context); } @Test diff --git a/components/camel-disruptor/src/test/java/org/apache/camel/component/disruptor/DisruptorWaitForTaskCompleteOnCompletionTest.java b/components/camel-disruptor/src/test/java/org/apache/camel/component/disruptor/DisruptorWaitForTaskCompleteOnCompletionTest.java index 97b57fdf2725..74558d17069a 100644 --- a/components/camel-disruptor/src/test/java/org/apache/camel/component/disruptor/DisruptorWaitForTaskCompleteOnCompletionTest.java +++ b/components/camel-disruptor/src/test/java/org/apache/camel/component/disruptor/DisruptorWaitForTaskCompleteOnCompletionTest.java @@ -27,7 +27,7 @@ import org.junit.jupiter.api.Test; import static org.apache.camel.test.junit5.TestSupport.assertIsInstanceOf; 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 DisruptorWaitForTaskCompleteOnCompletionTest extends CamelTestSupport { @@ -37,13 +37,11 @@ public class DisruptorWaitForTaskCompleteOnCompletionTest extends CamelTestSuppo void testAlways() throws Exception { getMockEndpoint("mock:result").expectedMessageCount(0); - try { + CamelExecutionException e = assertThrows(CamelExecutionException.class, () -> { template.sendBody("direct:start", "Hello World"); - fail("Should have thrown an exception"); - } catch (CamelExecutionException e) { - assertIsInstanceOf(IllegalArgumentException.class, e.getCause()); - assertEquals("Forced", e.getCause().getMessage()); - } + }); + assertIsInstanceOf(IllegalArgumentException.class, e.getCause()); + assertEquals("Forced", e.getCause().getMessage()); MockEndpoint.assertIsSatisfied(context); diff --git a/components/camel-disruptor/src/test/java/org/apache/camel/component/disruptor/vm/DisruptorVmInOutChainedTimeoutTest.java b/components/camel-disruptor/src/test/java/org/apache/camel/component/disruptor/vm/DisruptorVmInOutChainedTimeoutTest.java index 57b86d9e56de..26f6dae3eb16 100644 --- a/components/camel-disruptor/src/test/java/org/apache/camel/component/disruptor/vm/DisruptorVmInOutChainedTimeoutTest.java +++ b/components/camel-disruptor/src/test/java/org/apache/camel/component/disruptor/vm/DisruptorVmInOutChainedTimeoutTest.java @@ -24,8 +24,8 @@ import org.junit.jupiter.api.Test; import static org.apache.camel.test.junit5.TestSupport.assertIsInstanceOf; import static org.junit.jupiter.api.Assertions.assertEquals; +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 DisruptorVmInOutChainedTimeoutTest extends AbstractVmTestSupport { @@ -33,15 +33,13 @@ public class DisruptorVmInOutChainedTimeoutTest extends AbstractVmTestSupport { void testDisruptorVmInOutChainedTimeout() { StopWatch watch = new StopWatch(); - try { + CamelExecutionException e = assertThrows(CamelExecutionException.class, () -> { template2.requestBody("disruptor-vm:a?timeout=1000", "Hello World"); - fail("Should have thrown an exception"); - } catch (CamelExecutionException e) { - // the chained vm caused the timeout - ExchangeTimedOutException cause = assertIsInstanceOf(ExchangeTimedOutException.class, - e.getCause()); - assertEquals(200, cause.getTimeout()); - } + }); + // the chained vm caused the timeout + ExchangeTimedOutException cause = assertIsInstanceOf(ExchangeTimedOutException.class, + e.getCause()); + assertEquals(200, cause.getTimeout()); long delta = watch.taken(); diff --git a/components/camel-disruptor/src/test/java/org/apache/camel/component/disruptor/vm/DisruptorVmInOutWithErrorTest.java b/components/camel-disruptor/src/test/java/org/apache/camel/component/disruptor/vm/DisruptorVmInOutWithErrorTest.java index f628cf14a058..40116a16821a 100644 --- a/components/camel-disruptor/src/test/java/org/apache/camel/component/disruptor/vm/DisruptorVmInOutWithErrorTest.java +++ b/components/camel-disruptor/src/test/java/org/apache/camel/component/disruptor/vm/DisruptorVmInOutWithErrorTest.java @@ -23,7 +23,7 @@ import org.junit.jupiter.api.Test; import static org.apache.camel.test.junit5.TestSupport.assertIsInstanceOf; 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 DisruptorVmInOutWithErrorTest extends AbstractVmTestSupport { @@ -31,13 +31,11 @@ public class DisruptorVmInOutWithErrorTest extends AbstractVmTestSupport { void testInOutWithError() throws Exception { getMockEndpoint("mock:result").expectedMessageCount(0); - try { + CamelExecutionException e = assertThrows(CamelExecutionException.class, () -> { template2.requestBody("direct:start", "Hello World", String.class); - fail("Should have thrown an exception"); - } catch (CamelExecutionException e) { - assertIsInstanceOf(IllegalArgumentException.class, e.getCause()); - assertEquals("Damn I cannot do this", e.getCause().getMessage()); - } + }); + assertIsInstanceOf(IllegalArgumentException.class, e.getCause()); + assertEquals("Damn I cannot do this", e.getCause().getMessage()); MockEndpoint.assertIsSatisfied(context); } diff --git a/components/camel-disruptor/src/test/java/org/apache/camel/component/disruptor/vm/DisruptorVmTimeoutIssueTest.java b/components/camel-disruptor/src/test/java/org/apache/camel/component/disruptor/vm/DisruptorVmTimeoutIssueTest.java index 0ab87032031d..db26f288a2e3 100644 --- a/components/camel-disruptor/src/test/java/org/apache/camel/component/disruptor/vm/DisruptorVmTimeoutIssueTest.java +++ b/components/camel-disruptor/src/test/java/org/apache/camel/component/disruptor/vm/DisruptorVmTimeoutIssueTest.java @@ -25,32 +25,28 @@ import org.junit.jupiter.api.Test; import static org.apache.camel.test.junit5.TestSupport.assertIsInstanceOf; 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 DisruptorVmTimeoutIssueTest extends AbstractVmTestSupport { @Test void testDisruptorVmTimeoutWithAnotherDisruptorVm() { - try { + CamelExecutionException e = assertThrows(CamelExecutionException.class, () -> { template2.requestBody("disruptor-vm:start1?timeout=4000", "Hello"); - fail("Should have thrown an exception"); - } catch (CamelExecutionException e) { - ExchangeTimedOutException cause = assertIsInstanceOf(ExchangeTimedOutException.class, - e.getCause()); - assertEquals(2000, cause.getTimeout()); - } + }); + ExchangeTimedOutException cause = assertIsInstanceOf(ExchangeTimedOutException.class, + e.getCause()); + assertEquals(2000, cause.getTimeout()); } @Test void testDisruptorVmTimeoutWithProcessor() { - try { + CamelExecutionException e = assertThrows(CamelExecutionException.class, () -> { template2.requestBody("disruptor-vm:start2?timeout=4000", "Hello"); - fail("Should have thrown an exception"); - } catch (CamelExecutionException e) { - ExchangeTimedOutException cause = assertIsInstanceOf(ExchangeTimedOutException.class, - e.getCause()); - assertEquals(2000, cause.getTimeout()); - } + }); + ExchangeTimedOutException cause = assertIsInstanceOf(ExchangeTimedOutException.class, + e.getCause()); + assertEquals(2000, cause.getTimeout()); } @Override diff --git a/components/camel-disruptor/src/test/java/org/apache/camel/component/disruptor/vm/SameDisruptorVmQueueSizeAndNoSizeTest.java b/components/camel-disruptor/src/test/java/org/apache/camel/component/disruptor/vm/SameDisruptorVmQueueSizeAndNoSizeTest.java index 722004e991a7..107fe293e864 100644 --- a/components/camel-disruptor/src/test/java/org/apache/camel/component/disruptor/vm/SameDisruptorVmQueueSizeAndNoSizeTest.java +++ b/components/camel-disruptor/src/test/java/org/apache/camel/component/disruptor/vm/SameDisruptorVmQueueSizeAndNoSizeTest.java @@ -24,7 +24,7 @@ import org.junit.jupiter.api.Test; import static org.apache.camel.test.junit5.TestSupport.assertIsInstanceOf; import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.fail; +import static org.junit.jupiter.api.Assertions.assertThrows; /** * @@ -37,39 +37,33 @@ public class SameDisruptorVmQueueSizeAndNoSizeTest extends CamelTestSupport { template.sendBody("disruptor-vm:foo?blockWhenFull=false", Integer.toString(i)); } - try { + CamelExecutionException e = assertThrows(CamelExecutionException.class, () -> { template.sendBody("disruptor-vm:foo?blockWhenFull=false", "Should be full now"); - fail("Should fail"); - } catch (CamelExecutionException e) { - IllegalStateException ise = assertIsInstanceOf(IllegalStateException.class, e.getCause()); - assertEquals("Disruptors ringbuffer was full", ise.getMessage()); - } + }); + IllegalStateException ise = assertIsInstanceOf(IllegalStateException.class, e.getCause()); + assertEquals("Disruptors ringbuffer was full", ise.getMessage()); } @Test void testSameQueueDifferentSize() { - try { + ResolveEndpointFailedException e = assertThrows(ResolveEndpointFailedException.class, () -> { template.sendBody("disruptor-vm:foo?size=256", "Should fail"); - fail("Should fail"); - } catch (ResolveEndpointFailedException e) { - IllegalArgumentException ise = assertIsInstanceOf(IllegalArgumentException.class, e.getCause()); - assertEquals( - "Cannot use existing queue disruptor-vm://foo as the existing queue size 128 does not match given queue size 256", - ise.getMessage()); - } + }); + IllegalArgumentException ise = assertIsInstanceOf(IllegalArgumentException.class, e.getCause()); + assertEquals( + "Cannot use existing queue disruptor-vm://foo as the existing queue size 128 does not match given queue size 256", + ise.getMessage()); } @Test void testSameQueueDifferentSizeBar() { - try { + ResolveEndpointFailedException e = assertThrows(ResolveEndpointFailedException.class, () -> { template.sendBody("disruptor-vm:bar?size=256", "Should fail"); - fail("Should fail"); - } catch (ResolveEndpointFailedException e) { - IllegalArgumentException ise = assertIsInstanceOf(IllegalArgumentException.class, e.getCause()); - assertEquals("Cannot use existing queue disruptor-vm://bar as the existing queue size " + 1024 - + " does not match given queue size 256", - ise.getMessage()); - } + }); + IllegalArgumentException ise = assertIsInstanceOf(IllegalArgumentException.class, e.getCause()); + assertEquals("Cannot use existing queue disruptor-vm://bar as the existing queue size " + 1024 + + " does not match given queue size 256", + ise.getMessage()); } @Override
