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/08/02 12:52:22 UTC
[camel] branch main updated: Camel 19557 (#10804)
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 6ad6abd1531 Camel 19557 (#10804)
6ad6abd1531 is described below
commit 6ad6abd1531ae473b54e23e742007673c3c44dce
Author: LostArtist <93...@users.noreply.github.com>
AuthorDate: Wed Aug 2 14:52:15 2023 +0200
Camel 19557 (#10804)
* (chores) camel-core: minor test cleanups
---------
Co-authored-by: Nikita Konovalov <nk...@redhat.com>
---
.../camel/builder/FluentProducerTemplateTest.java | 29 +++++--------
.../direct/DirectNoMultipleConsumersTest.java | 18 +++-----
...BeginAndCommitExpressionRenameStrategyTest.java | 19 ++++-----
...leConsumerBeginAndCommitRenameStrategyTest.java | 31 +++++---------
.../GenericFileDeleteProcessStrategyTest.java | 12 +++---
.../log/DefaultExchangeFormatterTest.java | 10 ++++-
.../camel/component/log/LogCustomLoggerTest.java | 9 ++--
.../component/mock/MockEndpointTimeClauseTest.java | 2 +-
...ropertiesComponentOnlyUseDefaultValuesTest.java | 9 +---
.../component/rest/FromRestUriPrefixTest.java | 2 +-
.../camel/component/saga/SagaComponentTest.java | 9 +---
.../seda/SameSedaQueueSizeAndNoSizeTest.java | 48 ++++++++--------------
.../SedaBlockWhenFullInvalidConfigurationTest.java | 12 ++----
.../component/seda/SedaBlockWhenFullTest.java | 37 +++++++----------
.../seda/SedaConcurrentConsumersNPEIssueTest.java | 30 ++++++--------
.../seda/SedaDefaultBlockWhenFullTest.java | 16 ++++----
.../seda/SedaDefaultUnboundedQueueSizeTest.java | 10 ++---
.../seda/SedaInOutChainedTimeoutTest.java | 20 ++++-----
.../seda/SedaInOutChainedWithOnCompletionTest.java | 2 +-
.../component/seda/SedaInOutWithErrorTest.java | 13 +++---
.../camel/component/seda/SedaNoConsumerTest.java | 38 +++++++----------
.../camel/component/seda/SedaTimeoutTest.java | 30 +++++++-------
.../SedaWaitForTaskCompleteOnCompletionTest.java | 13 +++---
.../camel/component/timer/TimerEndpointTest.java | 15 +++----
.../component/timer/TimerWithTimeOptionTest.java | 17 +++-----
.../validator/ValidatorIllegalImportTest.java | 17 ++++----
.../validator/ValidatorLazyStartProducerTest.java | 17 ++++----
.../validator/ValidatorWithDirectTest.java | 11 ++---
.../camel/main/MainPropertyPlaceholderTest.java | 1 +
.../camel/main/MainSupportCommandLineTest.java | 12 ++++--
.../java/org/apache/camel/main/MainVaultTest.java | 16 ++++----
31 files changed, 217 insertions(+), 308 deletions(-)
diff --git a/core/camel-core/src/test/java/org/apache/camel/builder/FluentProducerTemplateTest.java b/core/camel-core/src/test/java/org/apache/camel/builder/FluentProducerTemplateTest.java
index 71810516913..dff23d58739 100644
--- a/core/camel-core/src/test/java/org/apache/camel/builder/FluentProducerTemplateTest.java
+++ b/core/camel-core/src/test/java/org/apache/camel/builder/FluentProducerTemplateTest.java
@@ -26,6 +26,7 @@ import org.apache.camel.FluentProducerTemplate;
import org.apache.camel.RuntimeCamelException;
import org.apache.camel.component.mock.MockEndpoint;
import org.apache.camel.impl.engine.DefaultFluentProducerTemplate;
+import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
@@ -39,22 +40,15 @@ import static org.junit.jupiter.api.Assertions.fail;
public class FluentProducerTemplateTest extends ContextTestSupport {
@Test
- public void testNoEndpoint() throws Exception {
+ public void testNoEndpoint() {
FluentProducerTemplate fluent = context.createFluentProducerTemplate();
- try {
- fluent.withBody("Hello World").send();
- fail("Should have thrown exception");
- } catch (IllegalArgumentException e) {
- // expected
- }
+ FluentProducerTemplate helloWorld = fluent.withBody("Hello World");
+ Assertions.assertThrows(IllegalArgumentException.class, () -> helloWorld.send(),
+ "Should have thrown exception");
- try {
- fluent.withBody("Hello World").request();
- fail("Should have thrown exception");
- } catch (IllegalArgumentException e) {
- // expected
- }
+ Assertions.assertThrows(IllegalArgumentException.class, () -> helloWorld.request(),
+ "Should have thrown exception");
}
@Test
@@ -239,7 +233,7 @@ public class FluentProducerTemplateTest extends ContextTestSupport {
}
@Test
- public void testExceptionUsingProcessorAndBody() throws Exception {
+ public void testExceptionUsingProcessorAndBody() {
try {
DefaultFluentProducerTemplate.on(context)
.withBody("World")
@@ -257,7 +251,6 @@ public class FluentProducerTemplateTest extends ContextTestSupport {
try {
DefaultFluentProducerTemplate.on(context).withBody("Hello World").to("direct:exception").request();
-
fail("Should have thrown RuntimeCamelException");
} catch (RuntimeCamelException e) {
boolean b = e.getCause() instanceof IllegalArgumentException;
@@ -301,7 +294,7 @@ public class FluentProducerTemplateTest extends ContextTestSupport {
}
@Test
- public void testWithExchange() throws Exception {
+ public void testWithExchange() {
Exchange exchange = ExchangeBuilder.anExchange(context).withBody("Hello!").withPattern(ExchangePattern.InOut).build();
exchange = context.createFluentProducerTemplate().withExchange(exchange).to("direct:in").send();
@@ -318,7 +311,7 @@ public class FluentProducerTemplateTest extends ContextTestSupport {
}
@Test
- public void testRequestBody() throws Exception {
+ public void testRequestBody() {
// with endpoint as string uri
FluentProducerTemplate template = DefaultFluentProducerTemplate.on(context);
@@ -443,7 +436,7 @@ public class FluentProducerTemplateTest extends ContextTestSupport {
}
@Test
- public void testPerformance() throws Exception {
+ public void testPerformance() {
FluentProducerTemplate fluent = context.createFluentProducerTemplate();
for (int i = 0; i < 1000; i++) {
Object result = fluent.withBody("Camel").withHeader("foo", "" + i).to("direct:echo").request();
diff --git a/core/camel-core/src/test/java/org/apache/camel/component/direct/DirectNoMultipleConsumersTest.java b/core/camel-core/src/test/java/org/apache/camel/component/direct/DirectNoMultipleConsumersTest.java
index 6717e58ca8c..81dae55f392 100644
--- a/core/camel-core/src/test/java/org/apache/camel/component/direct/DirectNoMultipleConsumersTest.java
+++ b/core/camel-core/src/test/java/org/apache/camel/component/direct/DirectNoMultipleConsumersTest.java
@@ -16,14 +16,12 @@
*/
package org.apache.camel.component.direct;
-import org.apache.camel.CamelContext;
-import org.apache.camel.TestSupport;
+import org.apache.camel.*;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.impl.DefaultCamelContext;
+import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
-import static org.junit.jupiter.api.Assertions.fail;
-
/**
* MultipleConsumers option test.
*/
@@ -42,13 +40,9 @@ public class DirectNoMultipleConsumersTest extends TestSupport {
}
});
- try {
- container.start();
- fail("Should have thrown an FailedToStartRouteException");
- } catch (Exception e) {
- // expected
- } finally {
- container.stop();
- }
+ Assertions.assertThrows(FailedToStartRouteException.class, () -> container.start(),
+ "Should have thrown an FailedToStartRouteException");
+
+ container.stop();
}
}
diff --git a/core/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerBeginAndCommitExpressionRenameStrategyTest.java b/core/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerBeginAndCommitExpressionRenameStrategyTest.java
index 93910908c98..c875886beba 100644
--- a/core/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerBeginAndCommitExpressionRenameStrategyTest.java
+++ b/core/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerBeginAndCommitExpressionRenameStrategyTest.java
@@ -19,15 +19,16 @@ package org.apache.camel.component.file;
import java.io.File;
import org.apache.camel.ContextTestSupport;
+import org.apache.camel.Endpoint;
import org.apache.camel.Exchange;
import org.apache.camel.Processor;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.mock.MockEndpoint;
+import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
-import static org.junit.jupiter.api.Assertions.fail;
/**
* Unit test for the FileRenameStrategy using preMoveExpression and expression options
@@ -47,16 +48,12 @@ public class FileConsumerBeginAndCommitExpressionRenameStrategyTest extends Cont
}
@Test
- public void testIllegalOptions() throws Exception {
- try {
- context.getEndpoint(fileUri("?move=../done/${file:name}&delete=true")).createConsumer(new Processor() {
- public void process(Exchange exchange) throws Exception {
- }
- });
- fail("Should have thrown an exception");
- } catch (IllegalArgumentException e) {
- // ok
- }
+ public void testIllegalOptions() {
+
+ Endpoint ep = context.getEndpoint(fileUri("?move=../done/${file:name}&delete=true"));
+
+ Assertions.assertThrows(IllegalArgumentException.class, () -> ep.createConsumer(exchange -> {
+ }), "Should have thrown an exception");
}
@Override
diff --git a/core/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerBeginAndCommitRenameStrategyTest.java b/core/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerBeginAndCommitRenameStrategyTest.java
index a4cf3cdc1ce..5fc3f18edd7 100644
--- a/core/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerBeginAndCommitRenameStrategyTest.java
+++ b/core/camel-core/src/test/java/org/apache/camel/component/file/FileConsumerBeginAndCommitRenameStrategyTest.java
@@ -19,15 +19,16 @@ package org.apache.camel.component.file;
import java.io.File;
import org.apache.camel.ContextTestSupport;
+import org.apache.camel.Endpoint;
import org.apache.camel.Exchange;
import org.apache.camel.Processor;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.mock.MockEndpoint;
+import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
-import static org.junit.jupiter.api.Assertions.fail;
/**
* Unit test for the FileRenameStrategy using preMove and move options
@@ -47,26 +48,16 @@ public class FileConsumerBeginAndCommitRenameStrategyTest extends ContextTestSup
}
@Test
- public void testIllegalOptions() throws Exception {
- try {
- context.getEndpoint(fileUri("?move=../done/${file:name}&delete=true")).createConsumer(new Processor() {
- public void process(Exchange exchange) throws Exception {
- }
- });
- fail("Should have thrown an exception");
- } catch (IllegalArgumentException e) {
- // ok
- }
+ public void testIllegalOptions() {
- try {
- context.getEndpoint(fileUri("?move=${file:name.noext}.bak&delete=true")).createConsumer(new Processor() {
- public void process(Exchange exchange) throws Exception {
- }
- });
- fail("Should have thrown an exception");
- } catch (IllegalArgumentException e) {
- // ok
- }
+ Endpoint ep1 = context.getEndpoint(fileUri("?move=../done/${file:name}&delete=true"));
+ Endpoint ep2 = context.getEndpoint(fileUri("?move=${file:name.noext}.bak&delete=true"));
+
+ Assertions.assertThrows(IllegalArgumentException.class, () -> ep1.createConsumer(exchange -> {
+ }), "Should have thrown an exception");
+
+ Assertions.assertThrows(IllegalArgumentException.class, () -> ep2.createConsumer(exchange -> {
+ }), "Should have thrown an exception");
}
@Override
diff --git a/core/camel-core/src/test/java/org/apache/camel/component/file/strategy/GenericFileDeleteProcessStrategyTest.java b/core/camel-core/src/test/java/org/apache/camel/component/file/strategy/GenericFileDeleteProcessStrategyTest.java
index 9f2768cd319..6abd921ac67 100644
--- a/core/camel-core/src/test/java/org/apache/camel/component/file/strategy/GenericFileDeleteProcessStrategyTest.java
+++ b/core/camel-core/src/test/java/org/apache/camel/component/file/strategy/GenericFileDeleteProcessStrategyTest.java
@@ -23,10 +23,10 @@ import org.apache.camel.component.file.GenericFileEndpoint;
import org.apache.camel.component.file.GenericFileOperationFailedException;
import org.apache.camel.component.file.GenericFileOperations;
import org.apache.camel.util.FileUtil;
+import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.fail;
/**
* Unit test about retrying deleting processed file, that can be a bit more tricky on some OS as java.io.delete can
@@ -147,12 +147,10 @@ public class GenericFileDeleteProcessStrategyTest extends ContextTestSupport {
file.setAbsoluteFilePath(testFile("boom.txt").toString());
GenericFileDeleteProcessStrategy<Object> strategy = new GenericFileDeleteProcessStrategy<>();
- try {
- strategy.commit(new MyGenericFileOperations(), endpoint, exchange, file);
- fail("Should have thrown an exception");
- } catch (GenericFileOperationFailedException e) {
- // expected
- }
+
+ Assertions.assertThrows(GenericFileOperationFailedException.class,
+ () -> strategy.commit(new MyGenericFileOperations(), endpoint, exchange, file),
+ "Should have thrown an exception");
assertEquals(3, deleteCounter, "Should have tried to delete file 3 times");
assertEquals(3, existsCounter, "Should have tried to delete file 3 times");
diff --git a/core/camel-core/src/test/java/org/apache/camel/component/log/DefaultExchangeFormatterTest.java b/core/camel-core/src/test/java/org/apache/camel/component/log/DefaultExchangeFormatterTest.java
index 93e7d2ae8c4..0f7ffc779d7 100644
--- a/core/camel-core/src/test/java/org/apache/camel/component/log/DefaultExchangeFormatterTest.java
+++ b/core/camel-core/src/test/java/org/apache/camel/component/log/DefaultExchangeFormatterTest.java
@@ -27,7 +27,10 @@ import org.apache.camel.Producer;
import org.apache.camel.support.processor.DefaultExchangeFormatter;
import org.junit.jupiter.api.Test;
-import static org.junit.jupiter.api.Assertions.*;
+import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* Logger formatter test.
@@ -106,6 +109,7 @@ public class DefaultExchangeFormatterTest extends ContextTestSupport {
Producer producer = endpoint.createProducer();
producer.start();
producer.process(exchange);
+ assertMockEndpointsSatisfied();
producer.stop();
}
@@ -119,6 +123,7 @@ public class DefaultExchangeFormatterTest extends ContextTestSupport {
Producer producer = endpoint.createProducer();
producer.start();
producer.process(exchange);
+ assertMockEndpointsSatisfied();
producer.stop();
}
@@ -132,6 +137,7 @@ public class DefaultExchangeFormatterTest extends ContextTestSupport {
Producer producer = endpoint.createProducer();
producer.start();
producer.process(exchange);
+ assertMockEndpointsSatisfied();
producer.stop();
}
@@ -145,6 +151,7 @@ public class DefaultExchangeFormatterTest extends ContextTestSupport {
Producer producer = endpoint.createProducer();
producer.start();
producer.process(exchange);
+ assertMockEndpointsSatisfied();
producer.stop();
}
@@ -158,6 +165,7 @@ public class DefaultExchangeFormatterTest extends ContextTestSupport {
Producer producer = endpoint.createProducer();
producer.start();
producer.process(exchange);
+ assertMockEndpointsSatisfied();
producer.stop();
}
diff --git a/core/camel-core/src/test/java/org/apache/camel/component/log/LogCustomLoggerTest.java b/core/camel-core/src/test/java/org/apache/camel/component/log/LogCustomLoggerTest.java
index a275129189c..b9c1371f4d6 100644
--- a/core/camel-core/src/test/java/org/apache/camel/component/log/LogCustomLoggerTest.java
+++ b/core/camel-core/src/test/java/org/apache/camel/component/log/LogCustomLoggerTest.java
@@ -23,6 +23,7 @@ import org.apache.camel.ContextTestSupport;
import org.apache.camel.ResolveEndpointFailedException;
import org.apache.camel.impl.DefaultCamelContext;
import org.apache.logging.log4j.Level;
+import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.slf4j.LoggerFactory;
@@ -78,11 +79,9 @@ public class LogCustomLoggerTest extends ContextTestSupport {
@Test
public void testEndpointURIParametrizedNotResolvableLogger() {
context.getRegistry().bind("logger1", LoggerFactory.getLogger("provided.logger1.name"));
- try {
- template.requestBody("log:irrelevant.logger.name?logger=#logger2", "hello");
- } catch (ResolveEndpointFailedException e) {
- // expected
- }
+ Assertions.assertThrows(ResolveEndpointFailedException.class,
+ () -> template.requestBody("log:irrelevant.logger.name?logger=#logger2", "hello"),
+ "Endpoint cannot be resolved via URI");
}
@Test
diff --git a/core/camel-core/src/test/java/org/apache/camel/component/mock/MockEndpointTimeClauseTest.java b/core/camel-core/src/test/java/org/apache/camel/component/mock/MockEndpointTimeClauseTest.java
index 4dba21460ad..6be1d2b3c79 100644
--- a/core/camel-core/src/test/java/org/apache/camel/component/mock/MockEndpointTimeClauseTest.java
+++ b/core/camel-core/src/test/java/org/apache/camel/component/mock/MockEndpointTimeClauseTest.java
@@ -127,7 +127,7 @@ public class MockEndpointTimeClauseTest extends ContextTestSupport {
}
});
- // but the assertion would be complete before hand and thus
+ // but the assertion would be complete beforehand and thus
// the assertion was valid at the time given
assertMockEndpointsSatisfied();
diff --git a/core/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentOnlyUseDefaultValuesTest.java b/core/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentOnlyUseDefaultValuesTest.java
index c6b68899aca..8f0af338370 100644
--- a/core/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentOnlyUseDefaultValuesTest.java
+++ b/core/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentOnlyUseDefaultValuesTest.java
@@ -18,6 +18,7 @@ package org.apache.camel.component.properties;
import org.apache.camel.ContextTestSupport;
import org.apache.camel.builder.RouteBuilder;
+import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.fail;
@@ -73,12 +74,6 @@ public class PropertiesComponentOnlyUseDefaultValuesTest extends ContextTestSupp
}
});
- try {
- context.start();
- fail("Should have thrown exception");
- } catch (Exception e) {
- // expected
- }
+ Assertions.assertThrows(Exception.class, () -> context.start(), "Should have thrown exception");
}
-
}
diff --git a/core/camel-core/src/test/java/org/apache/camel/component/rest/FromRestUriPrefixTest.java b/core/camel-core/src/test/java/org/apache/camel/component/rest/FromRestUriPrefixTest.java
index 8f18f579806..7500e733111 100644
--- a/core/camel-core/src/test/java/org/apache/camel/component/rest/FromRestUriPrefixTest.java
+++ b/core/camel-core/src/test/java/org/apache/camel/component/rest/FromRestUriPrefixTest.java
@@ -62,7 +62,7 @@ public class FromRestUriPrefixTest extends FromRestGetTest {
@Override
public void configure() throws Exception {
restConfiguration().host("localhost");
- // we have logic to cleanup those paths so there is only one /
+ // we have logic to clean up those paths so there is only one /
// between the paths
rest("/say/").get("/hello").to("direct:hello").get("/bye").consumes("application/json").to("direct:bye")
.post("/hi").to("mock:update");
diff --git a/core/camel-core/src/test/java/org/apache/camel/component/saga/SagaComponentTest.java b/core/camel-core/src/test/java/org/apache/camel/component/saga/SagaComponentTest.java
index a97e660aefa..3861783b385 100644
--- a/core/camel-core/src/test/java/org/apache/camel/component/saga/SagaComponentTest.java
+++ b/core/camel-core/src/test/java/org/apache/camel/component/saga/SagaComponentTest.java
@@ -23,7 +23,7 @@ import org.apache.camel.model.SagaCompletionMode;
import org.apache.camel.saga.InMemorySagaService;
import org.junit.jupiter.api.Test;
-import static org.junit.jupiter.api.Assertions.fail;
+import static org.junit.jupiter.api.Assertions.assertThrows;
/**
*
@@ -85,12 +85,7 @@ public class SagaComponentTest extends ContextTestSupport {
MockEndpoint compensated = getMockEndpoint("mock:compensated");
compensated.expectedMessageCount(1);
- try {
- template.sendBody("direct:auto-workflow", "auto-compensate");
- fail("Should throw an exception");
- } catch (Exception ex) {
- // OK
- }
+ assertThrows(Exception.class, () -> template.sendBody("direct:auto-workflow", "auto-compensate"), "Should throw an exception");
completed.assertIsNotSatisfied();
compensated.assertIsSatisfied();
diff --git a/core/camel-core/src/test/java/org/apache/camel/component/seda/SameSedaQueueSizeAndNoSizeTest.java b/core/camel-core/src/test/java/org/apache/camel/component/seda/SameSedaQueueSizeAndNoSizeTest.java
index 5429cdf4d5c..cb4d372853a 100644
--- a/core/camel-core/src/test/java/org/apache/camel/component/seda/SameSedaQueueSizeAndNoSizeTest.java
+++ b/core/camel-core/src/test/java/org/apache/camel/component/seda/SameSedaQueueSizeAndNoSizeTest.java
@@ -23,7 +23,7 @@ import org.apache.camel.builder.RouteBuilder;
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.assertThrows;
/**
*
@@ -31,46 +31,34 @@ import static org.junit.jupiter.api.Assertions.fail;
public class SameSedaQueueSizeAndNoSizeTest extends ContextTestSupport {
@Test
- public void testSameQueue() throws Exception {
+ public void testSameQueue() {
for (int i = 0; i < 100; i++) {
template.sendBody("seda:foo", "" + i);
}
- try {
- template.sendBody("seda:foo", "Should be full now");
- fail("Should fail");
- } catch (CamelExecutionException e) {
- IllegalStateException ise = assertIsInstanceOf(IllegalStateException.class, e.getCause());
- if (!isJavaVendor("ibm")) {
- assertEquals("Queue full", ise.getMessage());
- }
+ CamelExecutionException e = assertThrows(CamelExecutionException.class, () -> template.sendBody("seda:foo", "Should be full now"), "Should fail");
+ IllegalStateException ise = assertIsInstanceOf(IllegalStateException.class, e.getCause());
+ if (!isJavaVendor("ibm")) {
+ assertEquals("Queue full", ise.getMessage());
}
}
@Test
- public void testSameQueueDifferentSize() throws Exception {
- try {
- template.sendBody("seda:foo?size=200", "Should fail");
- fail("Should fail");
- } catch (ResolveEndpointFailedException e) {
- IllegalArgumentException ise = assertIsInstanceOf(IllegalArgumentException.class, e.getCause());
- assertEquals(
- "Cannot use existing queue seda://foo as the existing queue size 100 does not match given queue size 200",
- ise.getMessage());
- }
+ public void testSameQueueDifferentSize() {
+ ResolveEndpointFailedException e = assertThrows(ResolveEndpointFailedException.class, () -> template.sendBody("seda:foo?size=200", "Should fail"), "Should fail");
+ IllegalArgumentException ise = assertIsInstanceOf(IllegalArgumentException.class, e.getCause());
+ assertEquals(
+ "Cannot use existing queue seda://foo as the existing queue size 100 does not match given queue size 200",
+ ise.getMessage());
}
@Test
- public void testSameQueueDifferentSizeBar() throws Exception {
- try {
- template.sendBody("seda:bar?size=200", "Should fail");
- fail("Should fail");
- } catch (ResolveEndpointFailedException e) {
- IllegalArgumentException ise = assertIsInstanceOf(IllegalArgumentException.class, e.getCause());
- assertEquals("Cannot use existing queue seda://bar as the existing queue size " + SedaConstants.QUEUE_SIZE
- + " does not match given queue size 200",
- ise.getMessage());
- }
+ public void testSameQueueDifferentSizeBar() {
+ ResolveEndpointFailedException e = assertThrows(ResolveEndpointFailedException.class,() -> template.sendBody("seda:bar?size=200", "Should fail"), "Should fail");
+ IllegalArgumentException ise = assertIsInstanceOf(IllegalArgumentException.class, e.getCause());
+ assertEquals("Cannot use existing queue seda://bar as the existing queue size " + SedaConstants.QUEUE_SIZE
+ + " does not match given queue size 200",
+ ise.getMessage());
}
@Override
diff --git a/core/camel-core/src/test/java/org/apache/camel/component/seda/SedaBlockWhenFullInvalidConfigurationTest.java b/core/camel-core/src/test/java/org/apache/camel/component/seda/SedaBlockWhenFullInvalidConfigurationTest.java
index 51a3e20aead..3367f44ba23 100644
--- a/core/camel-core/src/test/java/org/apache/camel/component/seda/SedaBlockWhenFullInvalidConfigurationTest.java
+++ b/core/camel-core/src/test/java/org/apache/camel/component/seda/SedaBlockWhenFullInvalidConfigurationTest.java
@@ -22,7 +22,7 @@ import org.apache.camel.builder.RouteBuilder;
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.assertThrows;
public class SedaBlockWhenFullInvalidConfigurationTest extends ContextTestSupport {
@@ -39,13 +39,9 @@ public class SedaBlockWhenFullInvalidConfigurationTest extends ContextTestSuppor
from("direct:start").to("seda:foo?blockWhenFull=true&blockWhenFull=true");
}
});
- try {
- context.start();
- fail("Should fail");
- } catch (Exception e) {
- ResolveEndpointFailedException refe = assertIsInstanceOf(ResolveEndpointFailedException.class, e.getCause());
- assertEquals("Value [true, true] converted to java.lang.Boolean cannot be null", refe.getCause().getMessage());
- }
+ Exception e = assertThrows(Exception.class, () -> context.start(), "Should fail");
+ ResolveEndpointFailedException refe = assertIsInstanceOf(ResolveEndpointFailedException.class, e.getCause());
+ assertEquals("Value [true, true] converted to java.lang.Boolean cannot be null", refe.getCause().getMessage());
}
}
diff --git a/core/camel-core/src/test/java/org/apache/camel/component/seda/SedaBlockWhenFullTest.java b/core/camel-core/src/test/java/org/apache/camel/component/seda/SedaBlockWhenFullTest.java
index 4a7b9c0ca83..99ac0a0a6d5 100644
--- a/core/camel-core/src/test/java/org/apache/camel/component/seda/SedaBlockWhenFullTest.java
+++ b/core/camel-core/src/test/java/org/apache/camel/component/seda/SedaBlockWhenFullTest.java
@@ -21,7 +21,9 @@ import org.apache.camel.builder.RouteBuilder;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Timeout;
-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.assertThrows;
/**
* Tests that a Seda producer supports the blockWhenFull option by blocking when a message is sent while the queue is
@@ -54,32 +56,23 @@ public class SedaBlockWhenFullTest extends ContextTestSupport {
}
@Test
- public void testSedaOfferTimeoutWhenFull() throws Exception {
- try {
- SedaEndpoint seda = context.getEndpoint(SEDA_WITH_OFFER_TIMEOUT_URI, SedaEndpoint.class);
- assertEquals(QUEUE_SIZE, seda.getQueue().remainingCapacity());
-
- sendTwoOverCapacity(SEDA_WITH_OFFER_TIMEOUT_URI, QUEUE_SIZE);
+ public void testSedaOfferTimeoutWhenFull() {
+ SedaEndpoint seda = context.getEndpoint(SEDA_WITH_OFFER_TIMEOUT_URI, SedaEndpoint.class);
+ assertEquals(QUEUE_SIZE, seda.getQueue().remainingCapacity());
- fail("Failed to insert element into queue, " + "after timeout of " + seda.getOfferTimeout() + " milliseconds");
- } catch (Exception e) {
- assertIsInstanceOf(IllegalStateException.class, e.getCause());
- }
+ Exception e = assertThrows(Exception.class, () -> sendTwoOverCapacity(SEDA_WITH_OFFER_TIMEOUT_URI, QUEUE_SIZE),
+ "Failed to insert element into queue, " + "after timeout of " + seda.getOfferTimeout() + " milliseconds");
+ assertIsInstanceOf(IllegalStateException.class, e.getCause());
}
@Test
- public void testSedaDefaultWhenFull() throws Exception {
- try {
- SedaEndpoint seda = context.getEndpoint(DEFAULT_URI, SedaEndpoint.class);
- assertFalse(seda.isBlockWhenFull(),
- "Seda Endpoint is not setting the correct default (should be false) for \"blockWhenFull\"");
+ public void testSedaDefaultWhenFull() {
+ SedaEndpoint seda = context.getEndpoint(DEFAULT_URI, SedaEndpoint.class);
+ assertFalse(seda.isBlockWhenFull(),
+ "Seda Endpoint is not setting the correct default (should be false) for \"blockWhenFull\"");
- sendTwoOverCapacity(DEFAULT_URI, QUEUE_SIZE);
-
- fail("The route didn't fill the queue beyond capacity: test class isn't working as intended");
- } catch (Exception e) {
- assertIsInstanceOf(IllegalStateException.class, e.getCause());
- }
+ Exception e = assertThrows(Exception.class, () -> sendTwoOverCapacity(DEFAULT_URI, QUEUE_SIZE), "The route didn't fill the queue beyond capacity: test class isn't working as intended");
+ assertIsInstanceOf(IllegalStateException.class, e.getCause());
}
@Test
diff --git a/core/camel-core/src/test/java/org/apache/camel/component/seda/SedaConcurrentConsumersNPEIssueTest.java b/core/camel-core/src/test/java/org/apache/camel/component/seda/SedaConcurrentConsumersNPEIssueTest.java
index c02e734c24b..ad7f185ffea 100644
--- a/core/camel-core/src/test/java/org/apache/camel/component/seda/SedaConcurrentConsumersNPEIssueTest.java
+++ b/core/camel-core/src/test/java/org/apache/camel/component/seda/SedaConcurrentConsumersNPEIssueTest.java
@@ -23,7 +23,7 @@ import org.apache.camel.component.mock.MockEndpoint;
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.assertThrows;
public class SedaConcurrentConsumersNPEIssueTest extends ContextTestSupport {
@@ -36,14 +36,12 @@ public class SedaConcurrentConsumersNPEIssueTest extends ContextTestSupport {
assertMockEndpointsSatisfied();
- try {
- context.getRouteController().startRoute("first");
- fail("Should have thrown exception");
- } catch (FailedToStartRouteException e) {
- assertEquals("Failed to start route first because of Multiple consumers for the same endpoint is not allowed:"
- + " seda://foo?concurrentConsumers=5",
- e.getMessage());
- }
+ FailedToStartRouteException e = assertThrows(FailedToStartRouteException.class, () -> context.getRouteController().startRoute("first"),
+ "Should have thrown exception");
+
+ assertEquals("Failed to start route first because of Multiple consumers for the same endpoint is not allowed:"
+ + " seda://foo?concurrentConsumers=5",
+ e.getMessage());
}
@Test
@@ -58,14 +56,12 @@ public class SedaConcurrentConsumersNPEIssueTest extends ContextTestSupport {
// this should be okay
context.getRouteController().startRoute("third");
- try {
- context.getRouteController().startRoute("first");
- fail("Should have thrown exception");
- } catch (FailedToStartRouteException e) {
- assertEquals("Failed to start route first because of Multiple consumers for the same endpoint is not allowed:"
- + " seda://foo?concurrentConsumers=5",
- e.getMessage());
- }
+ FailedToStartRouteException e = assertThrows(FailedToStartRouteException.class, () -> context.getRouteController().startRoute("first"),
+ "Should have thrown exception");
+
+ assertEquals("Failed to start route first because of Multiple consumers for the same endpoint is not allowed:"
+ + " seda://foo?concurrentConsumers=5",
+ e.getMessage());
}
@Override
diff --git a/core/camel-core/src/test/java/org/apache/camel/component/seda/SedaDefaultBlockWhenFullTest.java b/core/camel-core/src/test/java/org/apache/camel/component/seda/SedaDefaultBlockWhenFullTest.java
index c60f693c49b..090be18b1a1 100644
--- a/core/camel-core/src/test/java/org/apache/camel/component/seda/SedaDefaultBlockWhenFullTest.java
+++ b/core/camel-core/src/test/java/org/apache/camel/component/seda/SedaDefaultBlockWhenFullTest.java
@@ -22,7 +22,10 @@ import org.apache.camel.spi.Registry;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Timeout;
-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.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertThrows;
/**
* Tests that a Seda component properly set blockWhenFull on endpoints.
@@ -70,18 +73,15 @@ public class SedaDefaultBlockWhenFullTest extends ContextTestSupport {
}
@Test
- public void testSedaDefaultWhenFull() throws Exception {
- try {
+ public void testSedaDefaultWhenFull() {
SedaEndpoint seda = context.getEndpoint(DEFAULT_URI, SedaEndpoint.class);
assertFalse(seda.isBlockWhenFull(),
"Seda Endpoint is not setting the correct default (should be false) for \"blockWhenFull\"");
- sendTwoOverCapacity(DEFAULT_URI, QUEUE_SIZE);
+ Exception e = assertThrows(Exception.class, () -> sendTwoOverCapacity(DEFAULT_URI, QUEUE_SIZE),
+ "The route didn't fill the queue beyond capacity: test class isn't working as intended");
- fail("The route didn't fill the queue beyond capacity: test class isn't working as intended");
- } catch (Exception e) {
- assertIsInstanceOf(IllegalStateException.class, e.getCause());
- }
+ assertIsInstanceOf(IllegalStateException.class, e.getCause());
}
@Test
diff --git a/core/camel-core/src/test/java/org/apache/camel/component/seda/SedaDefaultUnboundedQueueSizeTest.java b/core/camel-core/src/test/java/org/apache/camel/component/seda/SedaDefaultUnboundedQueueSizeTest.java
index 960c0c2f7bf..1a19890607c 100644
--- a/core/camel-core/src/test/java/org/apache/camel/component/seda/SedaDefaultUnboundedQueueSizeTest.java
+++ b/core/camel-core/src/test/java/org/apache/camel/component/seda/SedaDefaultUnboundedQueueSizeTest.java
@@ -19,8 +19,8 @@ package org.apache.camel.component.seda;
import org.apache.camel.ContextTestSupport;
import org.junit.jupiter.api.Test;
+import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.fail;
public class SedaDefaultUnboundedQueueSizeTest extends ContextTestSupport {
@@ -48,12 +48,8 @@ public class SedaDefaultUnboundedQueueSizeTest extends ContextTestSupport {
assertEquals(500, seda.getQueue().size());
// sending one more hit the limit
- try {
- template.sendBody("seda:foo", "Message overflow");
- fail("Should thrown an exception");
- } catch (Exception e) {
- assertIsInstanceOf(IllegalStateException.class, e.getCause());
- }
+ Exception e = assertThrows(Exception.class, () -> template.sendBody("seda:foo", "Message overflow"), "Should thrown an exception");
+ assertIsInstanceOf(IllegalStateException.class, e.getCause());
}
}
diff --git a/core/camel-core/src/test/java/org/apache/camel/component/seda/SedaInOutChainedTimeoutTest.java b/core/camel-core/src/test/java/org/apache/camel/component/seda/SedaInOutChainedTimeoutTest.java
index efa32ba8b50..d12b79d63f5 100644
--- a/core/camel-core/src/test/java/org/apache/camel/component/seda/SedaInOutChainedTimeoutTest.java
+++ b/core/camel-core/src/test/java/org/apache/camel/component/seda/SedaInOutChainedTimeoutTest.java
@@ -23,21 +23,21 @@ import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.util.StopWatch;
import org.junit.jupiter.api.Test;
-import static org.junit.jupiter.api.Assertions.*;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
public class SedaInOutChainedTimeoutTest extends ContextTestSupport {
@Test
- public void testSedaInOutChainedTimeout() throws Exception {
- // time timeout after 2 sec should trigger a immediately reply
+ public void testSedaInOutChainedTimeout() {
+ // time timeout after 2 sec should trigger an immediate reply
StopWatch watch = new StopWatch();
- try {
- template.requestBody("seda:a?timeout=5000", "Hello World");
- fail("Should have thrown an exception");
- } catch (CamelExecutionException e) {
- ExchangeTimedOutException cause = assertIsInstanceOf(ExchangeTimedOutException.class, e.getCause());
- assertEquals(2000, cause.getTimeout());
- }
+
+ CamelExecutionException e = assertThrows(CamelExecutionException.class, () -> template.requestBody("seda:a?timeout=5000", "Hello World"), "Should have thrown an exception");
+ ExchangeTimedOutException cause = assertIsInstanceOf(ExchangeTimedOutException.class, e.getCause());
+ assertEquals(2000, cause.getTimeout());
+
long delta = watch.taken();
assertTrue(delta < 4000, "Should be faster than 4000 millis, was: " + delta);
diff --git a/core/camel-core/src/test/java/org/apache/camel/component/seda/SedaInOutChainedWithOnCompletionTest.java b/core/camel-core/src/test/java/org/apache/camel/component/seda/SedaInOutChainedWithOnCompletionTest.java
index 62158d5e6a0..b0bfea8f2c6 100644
--- a/core/camel-core/src/test/java/org/apache/camel/component/seda/SedaInOutChainedWithOnCompletionTest.java
+++ b/core/camel-core/src/test/java/org/apache/camel/component/seda/SedaInOutChainedWithOnCompletionTest.java
@@ -31,7 +31,7 @@ public class SedaInOutChainedWithOnCompletionTest extends ContextTestSupport {
public void testInOutSedaChainedWithCustomOnCompletion() throws Exception {
getMockEndpoint("mock:a").expectedBodiesReceived("start");
getMockEndpoint("mock:b").expectedBodiesReceived("start-a");
- // the onCustomCompletion should be send very last (as it will be handed
+ // the onCustomCompletion should be sent very last (as it will be handed
// over)
getMockEndpoint("mock:c").expectedBodiesReceived("start-a-b", "onCustomCompletion");
diff --git a/core/camel-core/src/test/java/org/apache/camel/component/seda/SedaInOutWithErrorTest.java b/core/camel-core/src/test/java/org/apache/camel/component/seda/SedaInOutWithErrorTest.java
index cc08d4eb3a4..9982f285275 100644
--- a/core/camel-core/src/test/java/org/apache/camel/component/seda/SedaInOutWithErrorTest.java
+++ b/core/camel-core/src/test/java/org/apache/camel/component/seda/SedaInOutWithErrorTest.java
@@ -22,7 +22,7 @@ import org.apache.camel.builder.RouteBuilder;
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.assertThrows;
public class SedaInOutWithErrorTest extends ContextTestSupport {
@@ -30,14 +30,11 @@ public class SedaInOutWithErrorTest extends ContextTestSupport {
public void testInOutWithError() throws Exception {
getMockEndpoint("mock:result").expectedMessageCount(0);
- try {
- template.requestBody("direct:start", "Hello World", String.class);
- fail("Should have thrown an exception");
- } catch (CamelExecutionException e) {
- assertIsInstanceOf(IllegalArgumentException.class, e.getCause());
- assertEquals("Damn I cannot do this", e.getCause().getMessage());
- }
+ CamelExecutionException e = assertThrows(CamelExecutionException.class, () -> template.requestBody("direct:start", "Hello World", String.class),
+ "Should have thrown an exception");
+ assertIsInstanceOf(IllegalArgumentException.class, e.getCause());
+ assertEquals("Damn I cannot do this", e.getCause().getMessage());
assertMockEndpointsSatisfied();
}
diff --git a/core/camel-core/src/test/java/org/apache/camel/component/seda/SedaNoConsumerTest.java b/core/camel-core/src/test/java/org/apache/camel/component/seda/SedaNoConsumerTest.java
index 4678a975a05..66c67fc4e71 100644
--- a/core/camel-core/src/test/java/org/apache/camel/component/seda/SedaNoConsumerTest.java
+++ b/core/camel-core/src/test/java/org/apache/camel/component/seda/SedaNoConsumerTest.java
@@ -16,8 +16,6 @@
*/
package org.apache.camel.component.seda;
-import java.util.concurrent.TimeUnit;
-
import org.apache.camel.CamelExecutionException;
import org.apache.camel.ContextTestSupport;
import org.apache.camel.ExchangeTimedOutException;
@@ -25,8 +23,10 @@ import org.apache.camel.builder.NotifyBuilder;
import org.apache.camel.builder.RouteBuilder;
import org.junit.jupiter.api.Test;
+import java.util.concurrent.TimeUnit;
+
+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 SedaNoConsumerTest extends ContextTestSupport {
@@ -35,6 +35,7 @@ public class SedaNoConsumerTest extends ContextTestSupport {
return false;
}
+ @Test
public void testInOnly() throws Exception {
context.addRoutes(new RouteBuilder() {
@Override
@@ -52,42 +53,34 @@ public class SedaNoConsumerTest extends ContextTestSupport {
assertTrue(notify.matchesWaitTime());
}
+ @Test
public void testInOut() throws Exception {
context.addRoutes(new RouteBuilder() {
@Override
- public void configure() throws Exception {
+ public void configure() {
from("direct:start").to("seda:foo?timeout=1000");
}
});
context.start();
- try {
- template.requestBody("direct:start", "Hello World");
- fail("Should throw an exception");
- } catch (CamelExecutionException e) {
- assertIsInstanceOf(ExchangeTimedOutException.class, e.getCause());
- }
+ CamelExecutionException e = assertThrows(CamelExecutionException.class, () -> template.requestBody("direct:start", "Hello World"), "Should throw an exception");
+ assertIsInstanceOf(ExchangeTimedOutException.class, e.getCause());
}
@Test
public void testFailIfNoConsumer() throws Exception {
context.addRoutes(new RouteBuilder() {
@Override
- public void configure() throws Exception {
+ public void configure() {
from("direct:start").to("seda:foo?failIfNoConsumers=true");
}
});
context.start();
- try {
- template.sendBody("direct:start", "Hello World");
- fail("Should throw an exception");
- } catch (CamelExecutionException e) {
- assertIsInstanceOf(SedaConsumerNotAvailableException.class, e.getCause());
- }
-
+ CamelExecutionException e = assertThrows(CamelExecutionException.class, () -> template.sendBody("direct:start", "Hello World"), "Should throw an exception");
+ assertIsInstanceOf(SedaConsumerNotAvailableException.class, e.getCause());
}
@Test
@@ -130,12 +123,9 @@ public class SedaNoConsumerTest extends ContextTestSupport {
context.getRouteController().stopRoute("stopThisRoute");
TimeUnit.MILLISECONDS.sleep(100);
- try {
- template.sendBody("seda:foo?failIfNoConsumers=true", "Hello World");
- fail("Should throw an exception");
- } catch (CamelExecutionException e) {
- assertIsInstanceOf(SedaConsumerNotAvailableException.class, e.getCause());
- }
+
+ CamelExecutionException e = assertThrows(CamelExecutionException.class, () -> template.sendBody("seda:foo?failIfNoConsumers=true", "Hello World"), "Should throw an exception");
+ assertIsInstanceOf(SedaConsumerNotAvailableException.class, e.getCause());
}
@Test
diff --git a/core/camel-core/src/test/java/org/apache/camel/component/seda/SedaTimeoutTest.java b/core/camel-core/src/test/java/org/apache/camel/component/seda/SedaTimeoutTest.java
index bb6af4c8399..29f598ff19f 100644
--- a/core/camel-core/src/test/java/org/apache/camel/component/seda/SedaTimeoutTest.java
+++ b/core/camel-core/src/test/java/org/apache/camel/component/seda/SedaTimeoutTest.java
@@ -16,16 +16,18 @@
*/
package org.apache.camel.component.seda;
-import java.util.concurrent.ExecutionException;
-import java.util.concurrent.Future;
-
import org.apache.camel.CamelExecutionException;
import org.apache.camel.ContextTestSupport;
import org.apache.camel.ExchangeTimedOutException;
import org.apache.camel.builder.RouteBuilder;
import org.junit.jupiter.api.Test;
-import static org.junit.jupiter.api.Assertions.*;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.Future;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
public class SedaTimeoutTest extends ContextTestSupport {
private int timeout = 100;
@@ -37,19 +39,17 @@ public class SedaTimeoutTest extends ContextTestSupport {
}
@Test
- public void testSedaTimeout() throws Exception {
+ public void testSedaTimeout() {
Future<String> out = template.asyncRequestBody("seda:foo?timeout=" + timeout, "World", String.class);
- try {
- out.get();
- fail("Should have thrown an exception");
- } catch (ExecutionException e) {
- assertIsInstanceOf(CamelExecutionException.class, e.getCause());
- assertIsInstanceOf(ExchangeTimedOutException.class, e.getCause().getCause());
- SedaEndpoint se = (SedaEndpoint) context.getRoute("seda").getEndpoint();
- assertNotNull(se, "Consumer endpoint cannot be null");
- assertEquals(0, se.getCurrentQueueSize(), "Timeout Exchanges should be removed from queue");
- }
+ ExecutionException e = assertThrows(ExecutionException.class, out::get, "Should have thrown an exception");
+
+ assertIsInstanceOf(CamelExecutionException.class, e.getCause());
+ assertIsInstanceOf(ExchangeTimedOutException.class, e.getCause().getCause());
+
+ SedaEndpoint se = (SedaEndpoint) context.getRoute("seda").getEndpoint();
+ assertNotNull(se, "Consumer endpoint cannot be null");
+ assertEquals(0, se.getCurrentQueueSize(), "Timeout Exchanges should be removed from queue");
}
@Test
diff --git a/core/camel-core/src/test/java/org/apache/camel/component/seda/SedaWaitForTaskCompleteOnCompletionTest.java b/core/camel-core/src/test/java/org/apache/camel/component/seda/SedaWaitForTaskCompleteOnCompletionTest.java
index c12891081bb..ce1d421fb46 100644
--- a/core/camel-core/src/test/java/org/apache/camel/component/seda/SedaWaitForTaskCompleteOnCompletionTest.java
+++ b/core/camel-core/src/test/java/org/apache/camel/component/seda/SedaWaitForTaskCompleteOnCompletionTest.java
@@ -25,7 +25,7 @@ import org.apache.camel.support.SynchronizationAdapter;
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.assertThrows;
public class SedaWaitForTaskCompleteOnCompletionTest extends ContextTestSupport {
@@ -35,14 +35,11 @@ public class SedaWaitForTaskCompleteOnCompletionTest extends ContextTestSupport
public void testAlways() throws Exception {
getMockEndpoint("mock:result").expectedMessageCount(0);
- try {
- template.sendBody("direct:start", "Hello World");
- fail("Should have thrown an exception");
- } catch (CamelExecutionException e) {
- assertIsInstanceOf(IllegalArgumentException.class, e.getCause());
- assertEquals("Forced", e.getCause().getMessage());
- }
+ CamelExecutionException e = assertThrows(CamelExecutionException.class, () -> template.sendBody("direct:start", "Hello World"),
+ "Should have thrown an exception");
+ assertIsInstanceOf(IllegalArgumentException.class, e.getCause());
+ assertEquals("Forced", e.getCause().getMessage());
assertMockEndpointsSatisfied();
// 3 + 1 C and A should be last
diff --git a/core/camel-core/src/test/java/org/apache/camel/component/timer/TimerEndpointTest.java b/core/camel-core/src/test/java/org/apache/camel/component/timer/TimerEndpointTest.java
index 5f4dcbef2ce..5b6ab042f2b 100644
--- a/core/camel-core/src/test/java/org/apache/camel/component/timer/TimerEndpointTest.java
+++ b/core/camel-core/src/test/java/org/apache/camel/component/timer/TimerEndpointTest.java
@@ -16,16 +16,15 @@
*/
package org.apache.camel.component.timer;
-import java.util.Timer;
-
import org.apache.camel.ContextTestSupport;
import org.apache.camel.Endpoint;
import org.apache.camel.RuntimeCamelException;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.mock.MockEndpoint;
+import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
-import static org.junit.jupiter.api.Assertions.fail;
+import java.util.Timer;
public class TimerEndpointTest extends ContextTestSupport {
@@ -79,14 +78,10 @@ public class TimerEndpointTest extends ContextTestSupport {
}
@Test
- public void testTimerEndpointNoProducer() throws Exception {
+ public void testTimerEndpointNoProducer() {
Endpoint te = context.getEndpoint("timer://foo");
- try {
- te.createProducer();
- fail("Should have thrown an exception");
- } catch (RuntimeCamelException e) {
- // expected
- }
+
+ Assertions.assertThrows(RuntimeCamelException.class, te::createProducer, "Should have thrown an exception");
}
}
diff --git a/core/camel-core/src/test/java/org/apache/camel/component/timer/TimerWithTimeOptionTest.java b/core/camel-core/src/test/java/org/apache/camel/component/timer/TimerWithTimeOptionTest.java
index f65ebb02bdb..19c57198778 100644
--- a/core/camel-core/src/test/java/org/apache/camel/component/timer/TimerWithTimeOptionTest.java
+++ b/core/camel-core/src/test/java/org/apache/camel/component/timer/TimerWithTimeOptionTest.java
@@ -16,16 +16,15 @@
*/
package org.apache.camel.component.timer;
-import java.text.ParseException;
-import java.text.SimpleDateFormat;
-import java.util.Date;
-
import org.apache.camel.ContextTestSupport;
+import org.apache.camel.FailedToCreateRouteException;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.mock.MockEndpoint;
+import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
-import static org.junit.jupiter.api.Assertions.fail;
+import java.text.SimpleDateFormat;
+import java.util.Date;
public class TimerWithTimeOptionTest extends ContextTestSupport {
@@ -200,12 +199,8 @@ public class TimerWithTimeOptionTest extends ContextTestSupport {
fromF("timer://foo?time=%s", "20090101").to("mock:result");
}
});
- try {
- context.start();
- fail("Should throw an exception");
- } catch (Exception e) {
- assertIsInstanceOf(ParseException.class, e.getCause().getCause());
- }
+
+ Assertions.assertThrows(FailedToCreateRouteException.class, () -> context.start(), "Should throw an exception");
}
}
diff --git a/core/camel-core/src/test/java/org/apache/camel/component/validator/ValidatorIllegalImportTest.java b/core/camel-core/src/test/java/org/apache/camel/component/validator/ValidatorIllegalImportTest.java
index 7bfffca9362..ed43a28dae7 100644
--- a/core/camel-core/src/test/java/org/apache/camel/component/validator/ValidatorIllegalImportTest.java
+++ b/core/camel-core/src/test/java/org/apache/camel/component/validator/ValidatorIllegalImportTest.java
@@ -20,8 +20,8 @@ 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.assertTrue;
-import static org.junit.jupiter.api.Assertions.fail;
/**
*
@@ -65,14 +65,13 @@ public class ValidatorIllegalImportTest extends ContextTestSupport {
from("direct:test").to("validator:org/apache/camel/component/validator/BroadcastMonitor.xsd").to("mock:result");
}
});
- try {
- context.start();
- fail("Should have thrown exception");
- } catch (Exception e) {
- IllegalArgumentException iae = assertIsInstanceOf(IllegalArgumentException.class, e.getCause().getCause());
- assertTrue(iae.getMessage().startsWith(
- "Resource: org/apache/camel/component/validator/BroadcastMonitor.xsd refers an invalid resource without SystemId."));
- }
+
+ Exception e = assertThrows(Exception.class, () -> context.start(),
+ "Should have thrown exception");
+
+ IllegalArgumentException iae = assertIsInstanceOf(IllegalArgumentException.class, e.getCause().getCause());
+ assertTrue(iae.getMessage().startsWith(
+ "Resource: org/apache/camel/component/validator/BroadcastMonitor.xsd refers an invalid resource without SystemId."));
}
@Override
diff --git a/core/camel-core/src/test/java/org/apache/camel/component/validator/ValidatorLazyStartProducerTest.java b/core/camel-core/src/test/java/org/apache/camel/component/validator/ValidatorLazyStartProducerTest.java
index 6d59e94bf9e..ba46f959b94 100644
--- a/core/camel-core/src/test/java/org/apache/camel/component/validator/ValidatorLazyStartProducerTest.java
+++ b/core/camel-core/src/test/java/org/apache/camel/component/validator/ValidatorLazyStartProducerTest.java
@@ -16,13 +16,13 @@
*/
package org.apache.camel.component.validator;
-import java.io.FileNotFoundException;
-
import org.apache.camel.ContextTestSupport;
import org.apache.camel.builder.RouteBuilder;
import org.junit.jupiter.api.Test;
-import static org.junit.jupiter.api.Assertions.fail;
+import java.io.FileNotFoundException;
+
+import static org.junit.jupiter.api.Assertions.assertThrows;
public class ValidatorLazyStartProducerTest extends ContextTestSupport {
@@ -30,14 +30,11 @@ public class ValidatorLazyStartProducerTest extends ContextTestSupport {
public void testLazyStartProducerFail() throws Exception {
getMockEndpoint("mock:result").expectedMessageCount(0);
- try {
- template.sendBody("direct:fail",
- "<mail xmlns='http://foo.com/bar'><subject>Hey</subject><body>Hello world!</body></mail>");
- fail("Should throw exception");
- } catch (Exception e) {
- assertIsInstanceOf(FileNotFoundException.class, e.getCause());
- }
+ Exception e = assertThrows(Exception.class, () -> template.sendBody("direct:fail",
+ "<mail xmlns='http://foo.com/bar'><subject>Hey</subject><body>Hello world!</body></mail>"),
+ "Should throw exception");
+ assertIsInstanceOf(FileNotFoundException.class, e.getCause());
assertMockEndpointsSatisfied();
}
diff --git a/core/camel-core/src/test/java/org/apache/camel/component/validator/ValidatorWithDirectTest.java b/core/camel-core/src/test/java/org/apache/camel/component/validator/ValidatorWithDirectTest.java
index a3a92f15f16..1c88eb83bdf 100644
--- a/core/camel-core/src/test/java/org/apache/camel/component/validator/ValidatorWithDirectTest.java
+++ b/core/camel-core/src/test/java/org/apache/camel/component/validator/ValidatorWithDirectTest.java
@@ -21,7 +21,7 @@ import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.mock.MockEndpoint;
import org.junit.jupiter.api.Test;
-import static org.junit.jupiter.api.Assertions.fail;
+import static org.junit.jupiter.api.Assertions.assertThrows;
public class ValidatorWithDirectTest extends ContextTestSupport {
@@ -34,13 +34,8 @@ public class ValidatorWithDirectTest extends ContextTestSupport {
fail.expectedMessageCount(1);
valid.expectedMessageCount(0);
- try {
- template.sendBody("direct:start", wrongBody);
- fail("Should throw exception");
- } catch (Exception e) {
- // expected
- }
-
+ assertThrows(Exception.class, () -> template.sendBody("direct:start", wrongBody),
+ "Should throw exception");
assertMockEndpointsSatisfied();
}
diff --git a/core/camel-main/src/test/java/org/apache/camel/main/MainPropertyPlaceholderTest.java b/core/camel-main/src/test/java/org/apache/camel/main/MainPropertyPlaceholderTest.java
index 5e061d0c5c0..8196c88c21d 100644
--- a/core/camel-main/src/test/java/org/apache/camel/main/MainPropertyPlaceholderTest.java
+++ b/core/camel-main/src/test/java/org/apache/camel/main/MainPropertyPlaceholderTest.java
@@ -16,6 +16,7 @@
*/
package org.apache.camel.main;
+import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.parallel.Isolated;
diff --git a/core/camel-main/src/test/java/org/apache/camel/main/MainSupportCommandLineTest.java b/core/camel-main/src/test/java/org/apache/camel/main/MainSupportCommandLineTest.java
index de9dd3acfd0..736a8af118c 100644
--- a/core/camel-main/src/test/java/org/apache/camel/main/MainSupportCommandLineTest.java
+++ b/core/camel-main/src/test/java/org/apache/camel/main/MainSupportCommandLineTest.java
@@ -19,6 +19,7 @@ package org.apache.camel.main;
import org.apache.camel.CamelContext;
import org.apache.camel.ProducerTemplate;
import org.apache.camel.impl.DefaultCamelContext;
+import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
public class MainSupportCommandLineTest {
@@ -44,20 +45,23 @@ public class MainSupportCommandLineTest {
}
@Test
- public void testMainSupport() throws Exception {
+ public void testMainSupport() {
MyMainSupport my = new MyMainSupport();
- my.run(new String[] { "-d", "1" });
+ final int ret = Assertions.assertDoesNotThrow(() -> my.run(new String[] { "-d", "1" }));
+ Assertions.assertEquals(0, ret, "The code should return 0 when -d, 1 is requested");
}
@Test
public void testMainSupportMaxMessages() throws Exception {
MyMainSupport my = new MyMainSupport();
- my.run(new String[] { "-d", "1", "-dm", "2" });
+ final int ret = Assertions.assertDoesNotThrow(() -> my.run(new String[] { "-d", "1", "-dm", "2" }));
+ Assertions.assertEquals(0, ret, "The code should return 0 when -d, 1, -dm, 2 is requested");
}
@Test
public void testMainSupportHelp() throws Exception {
MyMainSupport my = new MyMainSupport();
- my.run(new String[] { "-h" });
+ final int ret = Assertions.assertDoesNotThrow(() -> my.run(new String[] { "-h" }));
+ Assertions.assertEquals(0, ret, "The code should return 0 when -h is requested");
}
}
diff --git a/core/camel-main/src/test/java/org/apache/camel/main/MainVaultTest.java b/core/camel-main/src/test/java/org/apache/camel/main/MainVaultTest.java
index acb016a0e7a..ca7ca42b3d8 100644
--- a/core/camel-main/src/test/java/org/apache/camel/main/MainVaultTest.java
+++ b/core/camel-main/src/test/java/org/apache/camel/main/MainVaultTest.java
@@ -48,7 +48,7 @@ public class MainVaultTest {
Assertions.assertEquals("myKey", cfg.getAccessKey());
Assertions.assertEquals("mySecret", cfg.getSecretKey());
Assertions.assertEquals("myRegion", cfg.getRegion());
- Assertions.assertEquals(false, cfg.isDefaultCredentialsProvider());
+ Assertions.assertFalse(cfg.isDefaultCredentialsProvider());
main.stop();
}
@@ -75,8 +75,8 @@ public class MainVaultTest {
Assertions.assertEquals("myKey", cfg.getAccessKey());
Assertions.assertEquals("mySecret", cfg.getSecretKey());
Assertions.assertEquals("myRegion", cfg.getRegion());
- Assertions.assertEquals(false, cfg.isDefaultCredentialsProvider());
- Assertions.assertEquals(true, cfg.isProfileCredentialsProvider());
+ Assertions.assertFalse(cfg.isDefaultCredentialsProvider());
+ Assertions.assertTrue(cfg.isProfileCredentialsProvider());
Assertions.assertEquals("jack", cfg.getProfileName());
main.stop();
@@ -103,7 +103,7 @@ public class MainVaultTest {
Assertions.assertEquals("myKey", cfg.getAccessKey());
Assertions.assertEquals("mySecret", cfg.getSecretKey());
Assertions.assertEquals("myRegion", cfg.getRegion());
- Assertions.assertEquals(false, cfg.isDefaultCredentialsProvider());
+ Assertions.assertFalse(cfg.isDefaultCredentialsProvider());
main.stop();
}
@@ -131,8 +131,8 @@ public class MainVaultTest {
Assertions.assertEquals("myKey", cfg.getAccessKey());
Assertions.assertEquals("mySecret", cfg.getSecretKey());
Assertions.assertEquals("myRegion", cfg.getRegion());
- Assertions.assertEquals(false, cfg.isDefaultCredentialsProvider());
- Assertions.assertEquals(true, cfg.isProfileCredentialsProvider());
+ Assertions.assertFalse(cfg.isDefaultCredentialsProvider());
+ Assertions.assertTrue(cfg.isProfileCredentialsProvider());
Assertions.assertEquals("jack", cfg.getProfileName());
main.stop();
@@ -155,7 +155,7 @@ public class MainVaultTest {
Assertions.assertEquals("file:////myKey", cfg.getServiceAccountKey());
Assertions.assertEquals("gcp-project", cfg.getProjectId());
- Assertions.assertEquals(false, cfg.isUseDefaultInstance());
+ Assertions.assertFalse(cfg.isUseDefaultInstance());
main.stop();
}
@@ -177,7 +177,7 @@ public class MainVaultTest {
Assertions.assertEquals("file:////myKey", cfg.getServiceAccountKey());
Assertions.assertEquals("gcp-project", cfg.getProjectId());
- Assertions.assertEquals(false, cfg.isUseDefaultInstance());
+ Assertions.assertFalse(cfg.isUseDefaultInstance());
main.stop();
}