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 7387164ff3ba391de0cff92be7ceae3cd32758ef Author: Otavio Rodolfo Piske <[email protected]> AuthorDate: Sat Jan 24 19:21:36 2026 +0000 CAMEL-21196: modernize exception-based assertions in camel-fhir Replace try-catch-fail patterns with assertThrows in: - FhirJsonDataformatErrorHandlerTest - FhirXmlDataformatErrorHandlerTest - FhirJsonDataformatErrorHandlerSpringTest - FhirXmlDataformatErrorHandlerSpringTest --- .../fhir/dataformat/FhirJsonDataformatErrorHandlerTest.java | 12 +++++------- .../fhir/dataformat/FhirXmlDataformatErrorHandlerTest.java | 12 +++++------- .../spring/FhirJsonDataformatErrorHandlerSpringTest.java | 12 +++++------- .../spring/FhirXmlDataformatErrorHandlerSpringTest.java | 12 +++++------- 4 files changed, 20 insertions(+), 28 deletions(-) diff --git a/components/camel-fhir/camel-fhir-component/src/test/java/org/apache/camel/component/fhir/dataformat/FhirJsonDataformatErrorHandlerTest.java b/components/camel-fhir/camel-fhir-component/src/test/java/org/apache/camel/component/fhir/dataformat/FhirJsonDataformatErrorHandlerTest.java index 6518be89c72c..f40488aef9f2 100644 --- a/components/camel-fhir/camel-fhir-component/src/test/java/org/apache/camel/component/fhir/dataformat/FhirJsonDataformatErrorHandlerTest.java +++ b/components/camel-fhir/camel-fhir-component/src/test/java/org/apache/camel/component/fhir/dataformat/FhirJsonDataformatErrorHandlerTest.java @@ -32,8 +32,8 @@ import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNull; +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 FhirJsonDataformatErrorHandlerTest extends CamelTestSupport { @@ -50,12 +50,10 @@ public class FhirJsonDataformatErrorHandlerTest extends CamelTestSupport { @Test public void unmarshalParserErrorHandler() { - try { - template.sendBody("direct:unmarshalErrorHandlerStrict", INPUT); - fail("Expected a DataFormatException"); - } catch (CamelExecutionException e) { - assertTrue(e.getCause() instanceof DataFormatException); - } + CamelExecutionException e = assertThrows(CamelExecutionException.class, + () -> template.sendBody("direct:unmarshalErrorHandlerStrict", INPUT), + "Expected a DataFormatException"); + assertTrue(e.getCause() instanceof DataFormatException); } @Test diff --git a/components/camel-fhir/camel-fhir-component/src/test/java/org/apache/camel/component/fhir/dataformat/FhirXmlDataformatErrorHandlerTest.java b/components/camel-fhir/camel-fhir-component/src/test/java/org/apache/camel/component/fhir/dataformat/FhirXmlDataformatErrorHandlerTest.java index c98e3dc50839..16d9c6779bb0 100644 --- a/components/camel-fhir/camel-fhir-component/src/test/java/org/apache/camel/component/fhir/dataformat/FhirXmlDataformatErrorHandlerTest.java +++ b/components/camel-fhir/camel-fhir-component/src/test/java/org/apache/camel/component/fhir/dataformat/FhirXmlDataformatErrorHandlerTest.java @@ -30,8 +30,8 @@ import org.apache.camel.test.junit5.CamelTestSupport; import org.hl7.fhir.r4.model.Patient; 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 FhirXmlDataformatErrorHandlerTest extends CamelTestSupport { @@ -47,12 +47,10 @@ public class FhirXmlDataformatErrorHandlerTest extends CamelTestSupport { @Test public void unmarshalParserErrorHandler() { - try { - template.sendBody("direct:unmarshalErrorHandlerStrict", INPUT); - fail("Expected a DataFormatException"); - } catch (CamelExecutionException e) { - assertTrue(e.getCause() instanceof DataFormatException); - } + CamelExecutionException e = assertThrows(CamelExecutionException.class, + () -> template.sendBody("direct:unmarshalErrorHandlerStrict", INPUT), + "Expected a DataFormatException"); + assertTrue(e.getCause() instanceof DataFormatException); } @Test diff --git a/components/camel-fhir/camel-fhir-component/src/test/java/org/apache/camel/component/fhir/dataformat/spring/FhirJsonDataformatErrorHandlerSpringTest.java b/components/camel-fhir/camel-fhir-component/src/test/java/org/apache/camel/component/fhir/dataformat/spring/FhirJsonDataformatErrorHandlerSpringTest.java index 2e4d16ace959..493db90c55f0 100644 --- a/components/camel-fhir/camel-fhir-component/src/test/java/org/apache/camel/component/fhir/dataformat/spring/FhirJsonDataformatErrorHandlerSpringTest.java +++ b/components/camel-fhir/camel-fhir-component/src/test/java/org/apache/camel/component/fhir/dataformat/spring/FhirJsonDataformatErrorHandlerSpringTest.java @@ -28,8 +28,8 @@ import org.springframework.context.support.ClassPathXmlApplicationContext; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNull; +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 FhirJsonDataformatErrorHandlerSpringTest extends CamelSpringTestSupport { @@ -44,12 +44,10 @@ public class FhirJsonDataformatErrorHandlerSpringTest extends CamelSpringTestSup @Test public void unmarshalParserErrorHandler() { - try { - template.sendBody("direct:unmarshalErrorHandlerStrict", INPUT); - fail("Expected a DataFormatException"); - } catch (CamelExecutionException e) { - assertTrue(e.getCause() instanceof DataFormatException); - } + CamelExecutionException e = assertThrows(CamelExecutionException.class, + () -> template.sendBody("direct:unmarshalErrorHandlerStrict", INPUT), + "Expected a DataFormatException"); + assertTrue(e.getCause() instanceof DataFormatException); } @Test diff --git a/components/camel-fhir/camel-fhir-component/src/test/java/org/apache/camel/component/fhir/dataformat/spring/FhirXmlDataformatErrorHandlerSpringTest.java b/components/camel-fhir/camel-fhir-component/src/test/java/org/apache/camel/component/fhir/dataformat/spring/FhirXmlDataformatErrorHandlerSpringTest.java index 4ecde56bbcca..9195c4e646a5 100644 --- a/components/camel-fhir/camel-fhir-component/src/test/java/org/apache/camel/component/fhir/dataformat/spring/FhirXmlDataformatErrorHandlerSpringTest.java +++ b/components/camel-fhir/camel-fhir-component/src/test/java/org/apache/camel/component/fhir/dataformat/spring/FhirXmlDataformatErrorHandlerSpringTest.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; public class FhirXmlDataformatErrorHandlerSpringTest extends CamelSpringTestSupport { @@ -42,12 +42,10 @@ public class FhirXmlDataformatErrorHandlerSpringTest extends CamelSpringTestSupp @Test public void unmarshalParserErrorHandler() { - try { - template.sendBody("direct:unmarshalErrorHandlerStrict", INPUT); - fail("Expected a DataFormatException"); - } catch (CamelExecutionException e) { - assertTrue(e.getCause() instanceof DataFormatException); - } + CamelExecutionException e = assertThrows(CamelExecutionException.class, + () -> template.sendBody("direct:unmarshalErrorHandlerStrict", INPUT), + "Expected a DataFormatException"); + assertTrue(e.getCause() instanceof DataFormatException); } @Test
