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 2f96d33ea08f11f7674916181738a6a97978850f Author: Otavio Rodolfo Piske <[email protected]> AuthorDate: Sat Jan 24 19:21:26 2026 +0000 CAMEL-21196: modernize exception-based assertions in camel-jaxb Replace try-catch-fail patterns with assertThrows in: - JaxbDataFormatMustBeJAXBElementTest - CamelJaxbFallbackConverterTest - NonXmlCharFiltererTest --- .../camel/jaxb/CamelJaxbFallbackConverterTest.java | 31 ++++++++-------------- .../jaxb/JaxbDataFormatMustBeJAXBElementTest.java | 16 +++++------ 2 files changed, 18 insertions(+), 29 deletions(-) diff --git a/components/camel-jaxb/src/test/java/org/apache/camel/jaxb/CamelJaxbFallbackConverterTest.java b/components/camel-jaxb/src/test/java/org/apache/camel/jaxb/CamelJaxbFallbackConverterTest.java index f3cb6624d6f4..ccb2c49c2dde 100644 --- a/components/camel-jaxb/src/test/java/org/apache/camel/jaxb/CamelJaxbFallbackConverterTest.java +++ b/components/camel-jaxb/src/test/java/org/apache/camel/jaxb/CamelJaxbFallbackConverterTest.java @@ -31,8 +31,8 @@ import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; +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 CamelJaxbFallbackConverterTest extends ExchangeTestSupport { @@ -62,19 +62,13 @@ public class CamelJaxbFallbackConverterTest extends ExchangeTestSupport { public void testFallbackConverterUnmarshalWithNonJAXBComplaintValue() { TypeConverter converter = context.getTypeConverter(); - try { - converter.convertTo(Foo.class, "Not every String is XML"); - fail("Should have thrown exception"); - } catch (TypeConversionException e) { - // expected - } - - try { - converter.convertTo(Bar.class, "<bar></bar"); - fail("Should have thrown exception"); - } catch (TypeConversionException e) { - // expected - } + assertThrows(TypeConversionException.class, + () -> converter.convertTo(Foo.class, "Not every String is XML"), + "Should have thrown exception"); + + assertThrows(TypeConversionException.class, + () -> converter.convertTo(Bar.class, "<bar></bar"), + "Should have thrown exception"); } @Test @@ -93,12 +87,9 @@ public class CamelJaxbFallbackConverterTest extends ExchangeTestSupport { byte[] buffers = "<Person><firstName>FOO</firstName><lastName>BAR\u0008</lastName></Person>".getBytes("UTF-8"); InputStream is = new ByteArrayInputStream(buffers); - try { - converter.convertTo(PersonType.class, exchange, is); - fail("Should have thrown exception"); - } catch (TypeConversionException e) { - // expected - } + assertThrows(TypeConversionException.class, + () -> converter.convertTo(PersonType.class, exchange, is), + "Should have thrown exception"); } @Test diff --git a/components/camel-jaxb/src/test/java/org/apache/camel/jaxb/JaxbDataFormatMustBeJAXBElementTest.java b/components/camel-jaxb/src/test/java/org/apache/camel/jaxb/JaxbDataFormatMustBeJAXBElementTest.java index d8185656d8cd..a4499084d9be 100644 --- a/components/camel-jaxb/src/test/java/org/apache/camel/jaxb/JaxbDataFormatMustBeJAXBElementTest.java +++ b/components/camel-jaxb/src/test/java/org/apache/camel/jaxb/JaxbDataFormatMustBeJAXBElementTest.java @@ -31,7 +31,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 JaxbDataFormatMustBeJAXBElementTest extends CamelTestSupport { @@ -50,14 +50,12 @@ public class JaxbDataFormatMustBeJAXBElementTest extends CamelTestSupport { public void testJaxbMarshalling2() throws InterruptedException { getMockEndpoint("mock:result").expectedMessageCount(0); - try { - template.sendBody("direct:start2", "<foo><bar>Hello Bar</bar></foo>"); - fail("Should have thrown exception"); - } catch (CamelExecutionException e) { - InvalidPayloadException ipe = assertIsInstanceOf(InvalidPayloadException.class, e.getCause().getCause()); - assertNotNull(ipe); - assertEquals(JAXBElement.class, ipe.getType()); - } + CamelExecutionException e = assertThrows(CamelExecutionException.class, + () -> template.sendBody("direct:start2", "<foo><bar>Hello Bar</bar></foo>"), + "Should have thrown exception"); + InvalidPayloadException ipe = assertIsInstanceOf(InvalidPayloadException.class, e.getCause().getCause()); + assertNotNull(ipe); + assertEquals(JAXBElement.class, ipe.getType()); MockEndpoint.assertIsSatisfied(context); }
