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
The following commit(s) were added to refs/heads/main by this push:
new cec819c3b17 CAMEL-21196: modernized assertions in camel-core.builder
cec819c3b17 is described below
commit cec819c3b176768504548bb2b4004ba704008609
Author: Nikita Konovalov <[email protected]>
AuthorDate: Wed Sep 11 14:29:58 2024 +0200
CAMEL-21196: modernized assertions in camel-core.builder
---
.../org/apache/camel/builder/RouteTemplateTest.java | 12 ++++++------
.../java/org/apache/camel/builder/xml/XPathTest.java | 18 +++++++++++-------
.../org/apache/camel/builder/xml/XsltBuilderTest.java | 18 +++++-------------
.../apache/camel/builder/xml/XsltOutputFileTest.java | 16 ++++++++--------
4 files changed, 30 insertions(+), 34 deletions(-)
diff --git
a/core/camel-core/src/test/java/org/apache/camel/builder/RouteTemplateTest.java
b/core/camel-core/src/test/java/org/apache/camel/builder/RouteTemplateTest.java
index 794b4ef55c0..81454f8ee87 100644
---
a/core/camel-core/src/test/java/org/apache/camel/builder/RouteTemplateTest.java
+++
b/core/camel-core/src/test/java/org/apache/camel/builder/RouteTemplateTest.java
@@ -178,12 +178,12 @@ public class RouteTemplateTest extends ContextTestSupport
{
Map<String, Object> parameters = new HashMap<>();
parameters.put("foo", "one");
- try {
- context.addRouteFromTemplate(null, "myTemplate", parameters);
- fail("Should throw exception");
- } catch (IllegalArgumentException e) {
- assertEquals("Route template myTemplate the following mandatory
parameters must be provided: bar", e.getMessage());
- }
+
+ IllegalArgumentException e =
assertThrows(IllegalArgumentException.class,
+ () -> context.addRouteFromTemplate(null, "myTemplate",
parameters),
+ "Should throw exception");
+
+ assertEquals("Route template myTemplate the following mandatory
parameters must be provided: bar", e.getMessage());
}
@Override
diff --git
a/core/camel-core/src/test/java/org/apache/camel/builder/xml/XPathTest.java
b/core/camel-core/src/test/java/org/apache/camel/builder/xml/XPathTest.java
index fe34690494a..2df8dd27c37 100644
--- a/core/camel-core/src/test/java/org/apache/camel/builder/xml/XPathTest.java
+++ b/core/camel-core/src/test/java/org/apache/camel/builder/xml/XPathTest.java
@@ -46,7 +46,12 @@ import org.apache.camel.util.StringHelper;
import org.junit.jupiter.api.Test;
import static org.apache.camel.language.xpath.XPathBuilder.xpath;
-import static org.junit.jupiter.api.Assertions.*;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
public class XPathTest extends ContextTestSupport {
@@ -81,12 +86,11 @@ public class XPathTest extends ContextTestSupport {
@Test
public void testInvalidXPath() {
- try {
- assertPredicate("/foo/", "<foo><bar xyz='cheese'/></foo>", true);
- fail("Should have thrown exception");
- } catch (Exception e) {
- assertIsInstanceOf(XPathExpressionException.class, e.getCause());
- }
+ Exception e = assertThrows(Exception.class,
+ () -> assertPredicate("/foo/", "<foo><bar
xyz='cheese'/></foo>", true),
+ "Should have thrown exception");
+
+ assertIsInstanceOf(XPathExpressionException.class, e.getCause());
}
@Test
diff --git
a/core/camel-core/src/test/java/org/apache/camel/builder/xml/XsltBuilderTest.java
b/core/camel-core/src/test/java/org/apache/camel/builder/xml/XsltBuilderTest.java
index cd129ac2c19..40838053892 100644
---
a/core/camel-core/src/test/java/org/apache/camel/builder/xml/XsltBuilderTest.java
+++
b/core/camel-core/src/test/java/org/apache/camel/builder/xml/XsltBuilderTest.java
@@ -44,8 +44,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 XsltBuilderTest extends ContextTestSupport {
@@ -294,12 +294,8 @@ public class XsltBuilderTest extends ContextTestSupport {
Exchange exchange = new DefaultExchange(context);
exchange.getIn().setBody(null);
- try {
- builder.process(exchange);
- fail("Should thrown an exception");
- } catch (ExpectedBodyTypeException e) {
- // expected
- }
+ assertThrows(ExpectedBodyTypeException.class,
+ () -> builder.process(exchange), "Should thrown an exception");
}
@Test
@@ -312,12 +308,8 @@ public class XsltBuilderTest extends ContextTestSupport {
Exchange exchange = new DefaultExchange(context);
exchange.getIn().setBody(null);
- try {
- builder.process(exchange);
- fail("Should thrown an exception");
- } catch (ExpectedBodyTypeException e) {
- // expected
- }
+ assertThrows(ExpectedBodyTypeException.class,
+ () -> builder.process(exchange), "Should thrown an exception");
}
@Test
diff --git
a/core/camel-core/src/test/java/org/apache/camel/builder/xml/XsltOutputFileTest.java
b/core/camel-core/src/test/java/org/apache/camel/builder/xml/XsltOutputFileTest.java
index 41e6ec1f18d..8d5d1fdaba9 100644
---
a/core/camel-core/src/test/java/org/apache/camel/builder/xml/XsltOutputFileTest.java
+++
b/core/camel-core/src/test/java/org/apache/camel/builder/xml/XsltOutputFileTest.java
@@ -30,7 +30,7 @@ import org.junit.jupiter.api.Test;
import static org.apache.camel.component.xslt.XsltBuilder.xslt;
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 XsltOutputFileTest extends ContextTestSupport {
@@ -51,13 +51,13 @@ public class XsltOutputFileTest extends ContextTestSupport {
@Test
public void testXsltOutputFileMissingHeader() {
- try {
- template.sendBody("direct:start", "<hello>world!</hello>");
- fail("Should thrown exception");
- } catch (CamelExecutionException e) {
- NoSuchHeaderException nshe =
assertIsInstanceOf(NoSuchHeaderException.class, e.getCause());
- assertEquals(Exchange.XSLT_FILE_NAME, nshe.getHeaderName());
- }
+
+ CamelExecutionException e = assertThrows(CamelExecutionException.class,
+ () -> template.sendBody("direct:start",
"<hello>world!</hello>"),
+ "Should thrown exception");
+
+ NoSuchHeaderException nshe =
assertIsInstanceOf(NoSuchHeaderException.class, e.getCause());
+ assertEquals(Exchange.XSLT_FILE_NAME, nshe.getHeaderName());
}
@Override