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 df4bf3cdc87bbadba8fea47386c292cd7b7900ee Author: Otavio Rodolfo Piske <[email protected]> AuthorDate: Sat Jan 24 18:39:12 2026 +0000 CAMEL-21196: modernize exception-based assertions in camel-test --- .../camel/test/junit5/patterns/AdviceWithNotStartedTest.java | 10 ++++------ .../apache/camel/test/junit5/patterns/AsyncSendMockTest.java | 9 +++------ .../camel/test/junit6/patterns/AdviceWithNotStartedTest.java | 10 ++++------ .../apache/camel/test/junit6/patterns/AsyncSendMockTest.java | 9 +++------ 4 files changed, 14 insertions(+), 24 deletions(-) diff --git a/components/camel-test/camel-test-junit5/src/test/java/org/apache/camel/test/junit5/patterns/AdviceWithNotStartedTest.java b/components/camel-test/camel-test-junit5/src/test/java/org/apache/camel/test/junit5/patterns/AdviceWithNotStartedTest.java index d8d7b470d1f1..7b7825eaa011 100644 --- a/components/camel-test/camel-test-junit5/src/test/java/org/apache/camel/test/junit5/patterns/AdviceWithNotStartedTest.java +++ b/components/camel-test/camel-test-junit5/src/test/java/org/apache/camel/test/junit5/patterns/AdviceWithNotStartedTest.java @@ -28,7 +28,7 @@ import org.apache.camel.test.junit5.CamelTestSupport; import org.junit.jupiter.api.Test; import static org.apache.camel.test.junit5.TestSupport.assertIsInstanceOf; -import static org.junit.jupiter.api.Assertions.fail; +import static org.junit.jupiter.api.Assertions.assertThrows; public class AdviceWithNotStartedTest extends CamelTestSupport { @@ -48,12 +48,10 @@ public class AdviceWithNotStartedTest extends CamelTestSupport { getMockEndpoint("mock:result").expectedMessageCount(1); - try { + CamelExecutionException e = assertThrows(CamelExecutionException.class, () -> { template.sendBody("direct:start", "Hello World"); - fail("Should throw exception"); - } catch (CamelExecutionException e) { - assertIsInstanceOf(RejectedExecutionException.class, e.getCause()); - } + }); + assertIsInstanceOf(RejectedExecutionException.class, e.getCause()); // start Camel context.start(); diff --git a/components/camel-test/camel-test-junit5/src/test/java/org/apache/camel/test/junit5/patterns/AsyncSendMockTest.java b/components/camel-test/camel-test-junit5/src/test/java/org/apache/camel/test/junit5/patterns/AsyncSendMockTest.java index 67e352f16fee..475614ac5d2f 100644 --- a/components/camel-test/camel-test-junit5/src/test/java/org/apache/camel/test/junit5/patterns/AsyncSendMockTest.java +++ b/components/camel-test/camel-test-junit5/src/test/java/org/apache/camel/test/junit5/patterns/AsyncSendMockTest.java @@ -23,7 +23,7 @@ import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import static org.junit.jupiter.api.Assertions.fail; +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; public class AsyncSendMockTest extends CamelTestSupport { private static final Logger LOG = LoggerFactory.getLogger(AsyncSendMockTest.class); @@ -35,7 +35,7 @@ public class AsyncSendMockTest extends CamelTestSupport { @Test public void testMakeAsyncApiCall() { - try { + assertDoesNotThrow(() -> { getMockEndpoint("mock:seda:start").expectedHeaderReceived("username", "admin123"); getMockEndpoint("mock:seda:start").expectedBodiesReceived("Hello"); DefaultExchange dfex = new DefaultExchange(context); @@ -44,9 +44,6 @@ public class AsyncSendMockTest extends CamelTestSupport { dfex.getIn().setBody("Hello"); template.asyncSend("seda:start", dfex); MockEndpoint.assertIsSatisfied(context); - } catch (Exception e) { - LOG.warn("Failed to make async call to api: {}", e.getMessage(), e); - fail("Failed to make async call to api"); - } + }); } } diff --git a/components/camel-test/camel-test-junit6/src/test/java/org/apache/camel/test/junit6/patterns/AdviceWithNotStartedTest.java b/components/camel-test/camel-test-junit6/src/test/java/org/apache/camel/test/junit6/patterns/AdviceWithNotStartedTest.java index f75627b13475..1badcf820084 100644 --- a/components/camel-test/camel-test-junit6/src/test/java/org/apache/camel/test/junit6/patterns/AdviceWithNotStartedTest.java +++ b/components/camel-test/camel-test-junit6/src/test/java/org/apache/camel/test/junit6/patterns/AdviceWithNotStartedTest.java @@ -28,7 +28,7 @@ import org.apache.camel.test.junit6.CamelTestSupport; import org.junit.jupiter.api.Test; import static org.apache.camel.test.junit6.TestSupport.assertIsInstanceOf; -import static org.junit.jupiter.api.Assertions.fail; +import static org.junit.jupiter.api.Assertions.assertThrows; public class AdviceWithNotStartedTest extends CamelTestSupport { @@ -48,12 +48,10 @@ public class AdviceWithNotStartedTest extends CamelTestSupport { getMockEndpoint("mock:result").expectedMessageCount(1); - try { + CamelExecutionException e = assertThrows(CamelExecutionException.class, () -> { template.sendBody("direct:start", "Hello World"); - fail("Should throw exception"); - } catch (CamelExecutionException e) { - assertIsInstanceOf(RejectedExecutionException.class, e.getCause()); - } + }); + assertIsInstanceOf(RejectedExecutionException.class, e.getCause()); // start Camel context.start(); diff --git a/components/camel-test/camel-test-junit6/src/test/java/org/apache/camel/test/junit6/patterns/AsyncSendMockTest.java b/components/camel-test/camel-test-junit6/src/test/java/org/apache/camel/test/junit6/patterns/AsyncSendMockTest.java index 9ab3503834a6..dc3e15b930a3 100644 --- a/components/camel-test/camel-test-junit6/src/test/java/org/apache/camel/test/junit6/patterns/AsyncSendMockTest.java +++ b/components/camel-test/camel-test-junit6/src/test/java/org/apache/camel/test/junit6/patterns/AsyncSendMockTest.java @@ -23,7 +23,7 @@ import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import static org.junit.jupiter.api.Assertions.fail; +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; public class AsyncSendMockTest extends CamelTestSupport { private static final Logger LOG = LoggerFactory.getLogger(AsyncSendMockTest.class); @@ -35,7 +35,7 @@ public class AsyncSendMockTest extends CamelTestSupport { @Test public void testMakeAsyncApiCall() { - try { + assertDoesNotThrow(() -> { getMockEndpoint("mock:seda:start").expectedHeaderReceived("username", "admin123"); getMockEndpoint("mock:seda:start").expectedBodiesReceived("Hello"); DefaultExchange dfex = new DefaultExchange(context); @@ -44,9 +44,6 @@ public class AsyncSendMockTest extends CamelTestSupport { dfex.getIn().setBody("Hello"); template.asyncSend("seda:start", dfex); MockEndpoint.assertIsSatisfied(context); - } catch (Exception e) { - LOG.warn("Failed to make async call to api: {}", e.getMessage(), e); - fail("Failed to make async call to api"); - } + }); } }
