You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by or...@apache.org on 2023/05/25 16:11:23 UTC
[camel] branch main updated: (chores) camel-core: minor test cleanups
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 a5bd5172ab6 (chores) camel-core: minor test cleanups
a5bd5172ab6 is described below
commit a5bd5172ab6185f15ebc6a29c4a9657482da9398
Author: Otavio Rodolfo Piske <an...@gmail.com>
AuthorDate: Thu May 25 16:16:48 2023 +0200
(chores) camel-core: minor test cleanups
---
.../java/org/apache/camel/CamelExceptionsTest.java | 8 ++------
.../ExceptionBuilderWithHandledExceptionTest.java | 17 +++++++----------
.../component/direct/DirectNoConsumerTest.java | 12 ++++++------
.../apache/camel/component/ref/RefInvalidTest.java | 21 +++++++++------------
.../toolbox/FlexibleAggregationStrategiesTest.java | 12 +++---------
5 files changed, 27 insertions(+), 43 deletions(-)
diff --git a/core/camel-core/src/test/java/org/apache/camel/CamelExceptionsTest.java b/core/camel-core/src/test/java/org/apache/camel/CamelExceptionsTest.java
index ce12ec8d810..7cf1a1aa272 100644
--- a/core/camel-core/src/test/java/org/apache/camel/CamelExceptionsTest.java
+++ b/core/camel-core/src/test/java/org/apache/camel/CamelExceptionsTest.java
@@ -231,12 +231,8 @@ public class CamelExceptionsTest extends ContextTestSupport {
assertEquals(ExchangePattern.InOnly, ExchangePattern.asEnum("InOnly"));
assertEquals(ExchangePattern.InOut, ExchangePattern.asEnum("InOut"));
- try {
- ExchangePattern.asEnum("foo");
- fail("Should have thrown an exception");
- } catch (IllegalArgumentException e) {
- // expected
- }
+ assertThrows(IllegalArgumentException.class, () -> ExchangePattern.asEnum("foo"),
+ "Should have thrown an exception");
}
@Test
diff --git a/core/camel-core/src/test/java/org/apache/camel/builder/ExceptionBuilderWithHandledExceptionTest.java b/core/camel-core/src/test/java/org/apache/camel/builder/ExceptionBuilderWithHandledExceptionTest.java
index 386ef609cb4..5aa874c5665 100644
--- a/core/camel-core/src/test/java/org/apache/camel/builder/ExceptionBuilderWithHandledExceptionTest.java
+++ b/core/camel-core/src/test/java/org/apache/camel/builder/ExceptionBuilderWithHandledExceptionTest.java
@@ -26,8 +26,7 @@ import org.apache.camel.RuntimeCamelException;
import org.apache.camel.component.mock.MockEndpoint;
import org.junit.jupiter.api.Test;
-import static org.junit.jupiter.api.Assertions.assertTrue;
-import static org.junit.jupiter.api.Assertions.fail;
+import static org.junit.jupiter.api.Assertions.*;
/**
* Unit test to test exception configuration
@@ -70,14 +69,12 @@ public class ExceptionBuilderWithHandledExceptionTest extends ContextTestSupport
mock.expectedMessageCount(1);
mock.expectedHeaderReceived(MESSAGE_INFO, "Handled exchange with IOException");
- try {
- template.sendBodyAndHeader("direct:a", "Hello IOE", "foo", "something that does not match");
- fail("Should have thrown a IOException");
- } catch (RuntimeCamelException e) {
- boolean b = e.getCause() instanceof IOException;
- assertTrue(b);
- // expected, failure is not handled because predicate doesn't match
- }
+ // expected, failure is not handled because predicate doesn't match
+ Exception ex = assertThrows(RuntimeCamelException.class,
+ () -> template.sendBodyAndHeader("direct:a", "Hello IOE", "foo", "something that does not match"),
+ "Should have thrown a IOException");
+ boolean b = ex.getCause() instanceof IOException;
+ assertTrue(b);
MockEndpoint.assertIsSatisfied(result, mock);
}
diff --git a/core/camel-core/src/test/java/org/apache/camel/component/direct/DirectNoConsumerTest.java b/core/camel-core/src/test/java/org/apache/camel/component/direct/DirectNoConsumerTest.java
index 61e9ba032b5..f2d1fdd7e4e 100644
--- a/core/camel-core/src/test/java/org/apache/camel/component/direct/DirectNoConsumerTest.java
+++ b/core/camel-core/src/test/java/org/apache/camel/component/direct/DirectNoConsumerTest.java
@@ -23,6 +23,7 @@ import org.apache.camel.ContextTestSupport;
import org.apache.camel.builder.RouteBuilder;
import org.junit.jupiter.api.Test;
+import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.fail;
public class DirectNoConsumerTest extends ContextTestSupport {
@@ -129,12 +130,11 @@ public class DirectNoConsumerTest extends ContextTestSupport {
context.getRouteController().stopRoute("stopThisRoute");
TimeUnit.MILLISECONDS.sleep(100);
- try {
- template.sendBody("direct:foo", "Hello World");
- fail("Should throw an exception");
- } catch (CamelExecutionException e) {
- assertIsInstanceOf(DirectConsumerNotAvailableException.class, e.getCause());
- }
+
+ CamelExecutionException e = assertThrows(CamelExecutionException.class,
+ () -> template.sendBody("direct:foo", "Hello World"),
+ "Should have thrown an exception");
+ assertIsInstanceOf(DirectConsumerNotAvailableException.class, e.getCause());
}
@Test
diff --git a/core/camel-core/src/test/java/org/apache/camel/component/ref/RefInvalidTest.java b/core/camel-core/src/test/java/org/apache/camel/component/ref/RefInvalidTest.java
index e260608952c..dedc010f9c9 100644
--- a/core/camel-core/src/test/java/org/apache/camel/component/ref/RefInvalidTest.java
+++ b/core/camel-core/src/test/java/org/apache/camel/component/ref/RefInvalidTest.java
@@ -24,8 +24,7 @@ import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.impl.DefaultCamelContext;
import org.junit.jupiter.api.Test;
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.fail;
+import static org.junit.jupiter.api.Assertions.*;
public class RefInvalidTest extends ContextTestSupport {
@@ -40,16 +39,14 @@ public class RefInvalidTest extends ContextTestSupport {
@Test
public void testInvalid() throws Exception {
- try {
- template.sendBody("ref:xxx", "Hello World");
- fail("Should have thrown an exception");
- } catch (ResolveEndpointFailedException e) {
- assertEquals(
- "Failed to resolve endpoint: ref://xxx due to: No bean could be found in the registry for: xxx of type: org.apache.camel.Endpoint",
- e.getMessage());
- NoSuchBeanException cause = assertIsInstanceOf(NoSuchBeanException.class, e.getCause());
- assertEquals("xxx", cause.getName());
- }
+ Exception ex = assertThrows(ResolveEndpointFailedException.class, () -> template.sendBody("ref:xxx", "Hello World"),
+ "Should have thrown an exception");
+
+ assertEquals(
+ "Failed to resolve endpoint: ref://xxx due to: No bean could be found in the registry for: xxx of type: org.apache.camel.Endpoint",
+ ex.getMessage());
+ NoSuchBeanException cause = assertIsInstanceOf(NoSuchBeanException.class, ex.getCause());
+ assertEquals("xxx", cause.getName());
}
@Override
diff --git a/core/camel-core/src/test/java/org/apache/camel/util/toolbox/FlexibleAggregationStrategiesTest.java b/core/camel-core/src/test/java/org/apache/camel/util/toolbox/FlexibleAggregationStrategiesTest.java
index 59606461784..efaeaf90fec 100644
--- a/core/camel-core/src/test/java/org/apache/camel/util/toolbox/FlexibleAggregationStrategiesTest.java
+++ b/core/camel-core/src/test/java/org/apache/camel/util/toolbox/FlexibleAggregationStrategiesTest.java
@@ -146,15 +146,9 @@ public class FlexibleAggregationStrategiesTest extends ContextTestSupport {
public void testFlexibleAggregationStrategyFailWithInvalidCast() throws Exception {
getMockEndpoint("mock:result5").expectedMessageCount(0);
- try {
- template.sendBody("direct:start5", "AGGREGATE1");
- } catch (Exception exception) {
- assertMockEndpointsSatisfied();
- return;
- }
-
- fail("Type Conversion exception expected, as we are not ignoring invalid casts");
-
+ Exception ex = assertThrows(Exception.class, () -> template.sendBody("direct:start5", "AGGREGATE1"),
+ "Type Conversion exception expected, as we are not ignoring invalid casts");
+ assertMockEndpointsSatisfied();
}
@Test