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 5232cd3388a1ce2aed0613b3593503afbfc27154 Author: Otavio Rodolfo Piske <[email protected]> AuthorDate: Sat Jan 24 19:48:44 2026 +0000 CAMEL-21196: modernize exception-based assertions in camel-xslt-saxon Replace try-catch-fail patterns with assertThrows in: - SaxonXsltFeatureRouteTest.java (1 occurrence) - SaxonInvalidXsltFileTest.java (1 occurrence) --- .../camel/component/xslt/SaxonInvalidXsltFileTest.java | 13 +++++-------- .../camel/component/xslt/SaxonXsltFeatureRouteTest.java | 15 ++++++--------- 2 files changed, 11 insertions(+), 17 deletions(-) diff --git a/components/camel-xslt-saxon/src/test/java/org/apache/camel/component/xslt/SaxonInvalidXsltFileTest.java b/components/camel-xslt-saxon/src/test/java/org/apache/camel/component/xslt/SaxonInvalidXsltFileTest.java index 6dff1db2d2dd..e3c1dc7a38f6 100644 --- a/components/camel-xslt-saxon/src/test/java/org/apache/camel/component/xslt/SaxonInvalidXsltFileTest.java +++ b/components/camel-xslt-saxon/src/test/java/org/apache/camel/component/xslt/SaxonInvalidXsltFileTest.java @@ -24,24 +24,21 @@ import org.apache.camel.impl.DefaultCamelContext; 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 SaxonInvalidXsltFileTest { @Test public void testInvalidStylesheet() { - try { + Exception e = assertThrows(Exception.class, () -> { RouteBuilder builder = createRouteBuilder(); try (CamelContext context = new DefaultCamelContext()) { context.addRoutes(builder); context.start(); - - fail("Should have thrown an exception due XSL compilation error"); } - } catch (Exception e) { - // expected - assertIsInstanceOf(TransformerException.class, e.getCause().getCause().getCause()); - } + }); + // expected + assertIsInstanceOf(TransformerException.class, e.getCause().getCause().getCause()); } protected RouteBuilder createRouteBuilder() { diff --git a/components/camel-xslt-saxon/src/test/java/org/apache/camel/component/xslt/SaxonXsltFeatureRouteTest.java b/components/camel-xslt-saxon/src/test/java/org/apache/camel/component/xslt/SaxonXsltFeatureRouteTest.java index 99bb8526ee9a..248e0a83a6f8 100644 --- a/components/camel-xslt-saxon/src/test/java/org/apache/camel/component/xslt/SaxonXsltFeatureRouteTest.java +++ b/components/camel-xslt-saxon/src/test/java/org/apache/camel/component/xslt/SaxonXsltFeatureRouteTest.java @@ -22,8 +22,8 @@ import org.apache.camel.builder.RouteBuilder; import org.apache.camel.test.junit5.CamelTestSupport; 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 SaxonXsltFeatureRouteTest extends CamelTestSupport { @@ -35,15 +35,12 @@ public class SaxonXsltFeatureRouteTest extends CamelTestSupport { } public void sendXmlMessage(String uri, String message) { - try { + Exception ex = assertThrows(Exception.class, () -> { template.sendBody("direct:start1", message); - fail("expect an exception here"); - } catch (Exception ex) { - // expect an exception here - assertTrue(ex instanceof CamelExecutionException, "Get a wrong exception"); - assertTrue(ex.getCause() instanceof XPathException, "Get a wrong exception cause"); - } - + }); + // expect an exception here + assertTrue(ex instanceof CamelExecutionException, "Get a wrong exception"); + assertTrue(ex.getCause() instanceof XPathException, "Get a wrong exception cause"); } @Override
