From 7a43633b3c3587d949724f580ad0015a6f65ef82 Mon Sep 17 00:00:00 2001 From: Otavio Rodolfo Piske Date: Sat, 28 Aug 2021 11:23:48 +0200 Subject: [PATCH] (chores) fixed missing assertions in test code (#6002) components: camel-bindy, camel-facebook, camel-grok, camel-http, camel-jetty, camel-jooq, camel-jt400, camel-kafka, camel-leveldb, camel-leveldb-legacy, camel-microprofile, camel-milo --- .../factories/BigDecimalFormatFactoryTest.java | 6 ------ .../data/FacebookMethodsTypeHelperTest.java | 5 ----- .../camel/component/grok/GrokPatternsTest.java | 6 ++++-- .../http/HttpInvalidConfigurationTest.java | 8 +++++--- ...HttpInvalidHttpClientConfigurationTest.java | 10 ++++++---- .../jetty/HttpProducerJMXBeansIssueTest.java | 6 ++++-- .../camel/component/jooq/JooqXMLTest.java | 18 ++++++++++++++---- .../jt400/Jt400DataQueueConsumerTest.java | 7 ++++--- .../component/kafka/KafkaConsumerTest.java | 4 +++- .../component/leveldb/LevelDBSetupTest.java | 12 +++++++----- .../component/leveldb/LevelDBSetupTest.java | 12 +++++++----- .../metrics/MicroProfileMetricsHelperTest.java | 4 +++- .../component/milo/server/ServerLocalTest.java | 13 +++++++------ .../server/ServerSetSecurityPoliciesTest.java | 9 ++++++--- 14 files changed, 70 insertions(+), 50 deletions(-) diff --git a/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/format/factories/BigDecimalFormatFactoryTest.java b/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/format/factories/BigDecimalFormatFactoryTest.java index 0712429081161..a7d66447e6b34 100644 --- a/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/format/factories/BigDecimalFormatFactoryTest.java +++ b/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/format/factories/BigDecimalFormatFactoryTest.java @@ -40,10 +40,4 @@ public void canBuild() throws Exception { assertThat(new BigDecimalFormatFactory().canBuild(wrongClass), is(false)); assertThat(new BigDecimalFormatFactory().canBuild(hasPattern), is(false)); } - - @Test - public void build() throws Exception { - - } - } diff --git a/components/camel-facebook/src/test/java/org/apache/camel/component/facebook/data/FacebookMethodsTypeHelperTest.java b/components/camel-facebook/src/test/java/org/apache/camel/component/facebook/data/FacebookMethodsTypeHelperTest.java index 80567005c4e66..c87f4f5a329d8 100644 --- a/components/camel-facebook/src/test/java/org/apache/camel/component/facebook/data/FacebookMethodsTypeHelperTest.java +++ b/components/camel-facebook/src/test/java/org/apache/camel/component/facebook/data/FacebookMethodsTypeHelperTest.java @@ -71,11 +71,6 @@ public void testGetCandidateMethods() throws Exception { } } - @Test - public void testfiltermethods() throws Exception { - // TODO - } - @Test public void testGetArguments() throws Exception { final Class[] interfaces = Facebook.class.getInterfaces(); diff --git a/components/camel-grok/src/test/java/org/apache/camel/component/grok/GrokPatternsTest.java b/components/camel-grok/src/test/java/org/apache/camel/component/grok/GrokPatternsTest.java index 265c9bc432985..6d06655a7b94b 100644 --- a/components/camel-grok/src/test/java/org/apache/camel/component/grok/GrokPatternsTest.java +++ b/components/camel-grok/src/test/java/org/apache/camel/component/grok/GrokPatternsTest.java @@ -32,6 +32,7 @@ import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; import static org.junit.jupiter.api.Assertions.assertTrue; @TestInstance(TestInstance.Lifecycle.PER_METHOD) @@ -82,8 +83,9 @@ public void configure() throws Exception { .unmarshal().grok(pattern); } }); - expectedOutputTest.accept( - template.requestBody("direct:input", input, Map.class)); + + assertDoesNotThrow(() -> expectedOutputTest.accept( + template.requestBody("direct:input", input, Map.class))); } private static Consumer test(String key, Object value) { diff --git a/components/camel-http/src/test/java/org/apache/camel/component/http/HttpInvalidConfigurationTest.java b/components/camel-http/src/test/java/org/apache/camel/component/http/HttpInvalidConfigurationTest.java index fc97475f4b546..6f89cfa93ed0f 100644 --- a/components/camel-http/src/test/java/org/apache/camel/component/http/HttpInvalidConfigurationTest.java +++ b/components/camel-http/src/test/java/org/apache/camel/component/http/HttpInvalidConfigurationTest.java @@ -34,6 +34,8 @@ */ public class HttpInvalidConfigurationTest extends CamelTestSupport { + private FailedToCreateRouteException exception; + @BeforeEach @Override public void setUp() throws Exception { @@ -41,14 +43,14 @@ public void setUp() throws Exception { super.setUp(); fail("Should have thrown ResolveEndpointFailedException"); } catch (FailedToCreateRouteException e) { - ResolveEndpointFailedException cause = assertIsInstanceOf(ResolveEndpointFailedException.class, e.getCause()); - assertTrue(cause.getMessage().endsWith("You have duplicated the http(s) protocol.")); + exception = e; } } @Test public void testInvalidHostConfiguration() { - // dummy + ResolveEndpointFailedException cause = assertIsInstanceOf(ResolveEndpointFailedException.class, exception.getCause()); + assertTrue(cause.getMessage().endsWith("You have duplicated the http(s) protocol.")); } @Override diff --git a/components/camel-http/src/test/java/org/apache/camel/component/http/HttpInvalidHttpClientConfigurationTest.java b/components/camel-http/src/test/java/org/apache/camel/component/http/HttpInvalidHttpClientConfigurationTest.java index 4d657b68c9559..c3d072f85d6a7 100644 --- a/components/camel-http/src/test/java/org/apache/camel/component/http/HttpInvalidHttpClientConfigurationTest.java +++ b/components/camel-http/src/test/java/org/apache/camel/component/http/HttpInvalidHttpClientConfigurationTest.java @@ -34,6 +34,8 @@ */ public class HttpInvalidHttpClientConfigurationTest extends CamelTestSupport { + private FailedToCreateRouteException exception; + @BeforeEach @Override public void setUp() throws Exception { @@ -41,14 +43,14 @@ public void setUp() throws Exception { super.setUp(); fail("Should have thrown ResolveEndpointFailedException"); } catch (FailedToCreateRouteException e) { - ResolveEndpointFailedException cause = assertIsInstanceOf(ResolveEndpointFailedException.class, e.getCause()); - assertTrue(cause.getMessage().endsWith("Unknown parameters=[{xxx=true}]")); + exception = e; } } @Test - public void testInvalidHostConfiguration() throws Exception { - // dummy + public void testInvalidHostConfiguration() { + ResolveEndpointFailedException cause = assertIsInstanceOf(ResolveEndpointFailedException.class, exception.getCause()); + assertTrue(cause.getMessage().endsWith("Unknown parameters=[{xxx=true}]")); } @Override diff --git a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpProducerJMXBeansIssueTest.java b/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpProducerJMXBeansIssueTest.java index c0b04d892482b..ef338588196d0 100644 --- a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpProducerJMXBeansIssueTest.java +++ b/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpProducerJMXBeansIssueTest.java @@ -22,6 +22,7 @@ import org.apache.camel.Producer; import org.apache.camel.builder.RouteBuilder; import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -56,12 +57,13 @@ public void process(Exchange exchange) throws Exception { } @Test + @Disabled("disabled as this is a manual test") public void testNothing() { // do nothing as this test is manual } - // @Test - // TODO: disabled as this is a manual test + @Test + @Disabled("disabled as this is a manual test") public void testSendAlot() throws Exception { Endpoint ep = context.getEndpoint("direct:leak"); Producer p = ep.createProducer(); diff --git a/components/camel-jooq/src/test/java/org/apache/camel/component/jooq/JooqXMLTest.java b/components/camel-jooq/src/test/java/org/apache/camel/component/jooq/JooqXMLTest.java index fae13c19f2e43..cf8a97440961e 100644 --- a/components/camel-jooq/src/test/java/org/apache/camel/component/jooq/JooqXMLTest.java +++ b/components/camel-jooq/src/test/java/org/apache/camel/component/jooq/JooqXMLTest.java @@ -17,6 +17,7 @@ package org.apache.camel.component.jooq; import org.apache.camel.CamelContext; +import org.apache.camel.Endpoint; import org.apache.camel.ExchangePattern; import org.apache.camel.ProducerTemplate; import org.jooq.UpdatableRecord; @@ -24,6 +25,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.context.ContextConfiguration; +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; import static org.junit.jupiter.api.Assertions.assertNotNull; /** @@ -46,24 +48,32 @@ public void testInsert() { @Test public void testExecute() { ProducerTemplate producerTemplate = context.createProducerTemplate(); - producerTemplate.sendBody(context.getEndpoint("direct:execute"), ExchangePattern.InOut, "empty"); + Endpoint ep = context.getEndpoint("direct:execute"); + + assertDoesNotThrow(() -> producerTemplate.sendBody(ep, ExchangePattern.InOut, "empty")); } @Test public void testFetch() { ProducerTemplate producerTemplate = context.createProducerTemplate(); - producerTemplate.sendBody(context.getEndpoint("direct:fetch"), ExchangePattern.InOut, "empty"); + + Endpoint ep = context.getEndpoint("direct:fetch"); + assertDoesNotThrow(() -> producerTemplate.sendBody(ep, ExchangePattern.InOut, "empty")); } @Test public void testSQLSelect() { ProducerTemplate producerTemplate = context.createProducerTemplate(); - producerTemplate.sendBody(context.getEndpoint("direct:sql-select"), ExchangePattern.InOut, "empty"); + + Endpoint ep = context.getEndpoint("direct:sql-select"); + assertDoesNotThrow(() -> producerTemplate.sendBody(ep, ExchangePattern.InOut, "empty")); } @Test public void testSQLDelete() { ProducerTemplate producerTemplate = context.createProducerTemplate(); - producerTemplate.sendBody(context.getEndpoint("direct:sql-delete"), ExchangePattern.InOut, "empty"); + + Endpoint ep = context.getEndpoint("direct:sql-delete"); + assertDoesNotThrow(() -> producerTemplate.sendBody(ep, ExchangePattern.InOut, "empty")); } } diff --git a/components/camel-jt400/src/test/java/org/apache/camel/component/jt400/Jt400DataQueueConsumerTest.java b/components/camel-jt400/src/test/java/org/apache/camel/component/jt400/Jt400DataQueueConsumerTest.java index 3ae5aa4d15790..2ff7cb10ed494 100644 --- a/components/camel-jt400/src/test/java/org/apache/camel/component/jt400/Jt400DataQueueConsumerTest.java +++ b/components/camel-jt400/src/test/java/org/apache/camel/component/jt400/Jt400DataQueueConsumerTest.java @@ -17,8 +17,8 @@ package org.apache.camel.component.jt400; import java.io.InputStream; +import java.time.Duration; import java.util.Properties; -import java.util.concurrent.TimeUnit; import org.apache.camel.CamelContext; import org.apache.camel.impl.DefaultCamelContext; @@ -27,6 +27,7 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Timeout; +import static org.junit.jupiter.api.Assertions.assertTimeout; import static org.junit.jupiter.api.Assertions.fail; /** @@ -88,9 +89,9 @@ public void setUp() throws Exception { * Tests whether receive(long) honours the timeout parameter. */ @Test - @Timeout(value = TIMEOUT_VALUE + TIMEOUT_TOLERANCE, unit = TimeUnit.MILLISECONDS) public void testReceiveLong() { - consumer.receive(TIMEOUT_VALUE); + assertTimeout(Duration.ofMillis(TIMEOUT_VALUE + TIMEOUT_TOLERANCE), + () -> consumer.receive(TIMEOUT_VALUE)); } /** diff --git a/components/camel-kafka/src/test/java/org/apache/camel/component/kafka/KafkaConsumerTest.java b/components/camel-kafka/src/test/java/org/apache/camel/component/kafka/KafkaConsumerTest.java index d5232403881d7..71712641c93a2 100644 --- a/components/camel-kafka/src/test/java/org/apache/camel/component/kafka/KafkaConsumerTest.java +++ b/components/camel-kafka/src/test/java/org/apache/camel/component/kafka/KafkaConsumerTest.java @@ -21,6 +21,7 @@ import org.apache.camel.spi.ExchangeFactory; import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; @@ -62,6 +63,7 @@ public void consumerOnlyRequiresBootstrapServers() throws Exception { when(endpoint.getComponent()).thenReturn(component); when(endpoint.getConfiguration()).thenReturn(configuration); when(endpoint.getConfiguration().getBrokers()).thenReturn("localhost:2181"); - new KafkaConsumer(endpoint, processor); + + assertDoesNotThrow(() -> new KafkaConsumer(endpoint, processor)); } } diff --git a/components/camel-leveldb-legacy/src/test/java/org/apache/camel/component/leveldb/LevelDBSetupTest.java b/components/camel-leveldb-legacy/src/test/java/org/apache/camel/component/leveldb/LevelDBSetupTest.java index e7e8ed746f482..45399d991c861 100644 --- a/components/camel-leveldb-legacy/src/test/java/org/apache/camel/component/leveldb/LevelDBSetupTest.java +++ b/components/camel-leveldb-legacy/src/test/java/org/apache/camel/component/leveldb/LevelDBSetupTest.java @@ -18,6 +18,7 @@ package org.apache.camel.component.leveldb; import org.apache.camel.test.junit5.CamelTestSupport; +import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.condition.DisabledOnOs; import org.junit.jupiter.api.condition.OS; @@ -47,8 +48,12 @@ public void tearDown() throws Exception { */ @Test public void testLevelDBStartWithNoPath() { + Assertions.assertDoesNotThrow(() -> runTest("leveldb.dat")); + } + + private void runTest(String fileName) { levelDBFile = new LevelDBFile(); - levelDBFile.setFileName("leveldb.dat"); + levelDBFile.setFileName(fileName); levelDBFile.start(); levelDBFile.stop(); } @@ -59,9 +64,6 @@ public void testLevelDBStartWithNoPath() { @Test public void testLevelDBStartWithPath() { deleteDirectory("target/data"); - levelDBFile = new LevelDBFile(); - levelDBFile.setFileName("target/data/leveldb.dat"); - levelDBFile.start(); - levelDBFile.stop(); + Assertions.assertDoesNotThrow(() -> runTest("target/data/leveldb.dat")); } } diff --git a/components/camel-leveldb/src/test/java/org/apache/camel/component/leveldb/LevelDBSetupTest.java b/components/camel-leveldb/src/test/java/org/apache/camel/component/leveldb/LevelDBSetupTest.java index e7e8ed746f482..45399d991c861 100644 --- a/components/camel-leveldb/src/test/java/org/apache/camel/component/leveldb/LevelDBSetupTest.java +++ b/components/camel-leveldb/src/test/java/org/apache/camel/component/leveldb/LevelDBSetupTest.java @@ -18,6 +18,7 @@ package org.apache.camel.component.leveldb; import org.apache.camel.test.junit5.CamelTestSupport; +import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.condition.DisabledOnOs; import org.junit.jupiter.api.condition.OS; @@ -47,8 +48,12 @@ public void tearDown() throws Exception { */ @Test public void testLevelDBStartWithNoPath() { + Assertions.assertDoesNotThrow(() -> runTest("leveldb.dat")); + } + + private void runTest(String fileName) { levelDBFile = new LevelDBFile(); - levelDBFile.setFileName("leveldb.dat"); + levelDBFile.setFileName(fileName); levelDBFile.start(); levelDBFile.stop(); } @@ -59,9 +64,6 @@ public void testLevelDBStartWithNoPath() { @Test public void testLevelDBStartWithPath() { deleteDirectory("target/data"); - levelDBFile = new LevelDBFile(); - levelDBFile.setFileName("target/data/leveldb.dat"); - levelDBFile.start(); - levelDBFile.stop(); + Assertions.assertDoesNotThrow(() -> runTest("target/data/leveldb.dat")); } } diff --git a/components/camel-microprofile/camel-microprofile-metrics/src/test/java/org/apache/camel/component/microprofile/metrics/MicroProfileMetricsHelperTest.java b/components/camel-microprofile/camel-microprofile-metrics/src/test/java/org/apache/camel/component/microprofile/metrics/MicroProfileMetricsHelperTest.java index d08745ad458fe..fee0c84a855e9 100644 --- a/components/camel-microprofile/camel-microprofile-metrics/src/test/java/org/apache/camel/component/microprofile/metrics/MicroProfileMetricsHelperTest.java +++ b/components/camel-microprofile/camel-microprofile-metrics/src/test/java/org/apache/camel/component/microprofile/metrics/MicroProfileMetricsHelperTest.java @@ -23,6 +23,7 @@ import org.eclipse.microprofile.metrics.Tag; import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; @@ -68,7 +69,8 @@ public void testGetMetricRegistry() { DefaultCamelContext camelContext = new DefaultCamelContext(); Registry registry = camelContext.getRegistry(); registry.bind(MicroProfileMetricsConstants.METRIC_REGISTRY_NAME, MetricRegistries.get(MetricRegistry.Type.APPLICATION)); - MicroProfileMetricsHelper.getMetricRegistry(camelContext); + + assertDoesNotThrow(() -> MicroProfileMetricsHelper.getMetricRegistry(camelContext)); } @Test diff --git a/components/camel-milo/src/test/java/org/apache/camel/component/milo/server/ServerLocalTest.java b/components/camel-milo/src/test/java/org/apache/camel/component/milo/server/ServerLocalTest.java index 42738d3ebbd06..e358f4fd07bb5 100644 --- a/components/camel-milo/src/test/java/org/apache/camel/component/milo/server/ServerLocalTest.java +++ b/components/camel-milo/src/test/java/org/apache/camel/component/milo/server/ServerLocalTest.java @@ -26,6 +26,7 @@ import org.apache.camel.test.junit5.CamelTestSupport; import org.eclipse.milo.opcua.stack.core.types.builtin.DataValue; import org.eclipse.milo.opcua.stack.core.types.builtin.Variant; +import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -63,31 +64,31 @@ public void shouldStartComponent() { @Test public void testAcceptVariantString() { - sendBody(MILO_ITEM_1, new Variant("Foo")); + Assertions.assertDoesNotThrow(() -> sendBody(MILO_ITEM_1, new Variant("Foo"))); } @Test public void testAcceptVariantDouble() { - sendBody(MILO_ITEM_1, new Variant(0.0)); + Assertions.assertDoesNotThrow(() -> sendBody(MILO_ITEM_1, new Variant(0.0))); } @Test public void testAcceptString() { - sendBody(MILO_ITEM_1, "Foo"); + Assertions.assertDoesNotThrow(() -> sendBody(MILO_ITEM_1, "Foo")); } @Test public void testAcceptDouble() { - sendBody(MILO_ITEM_1, 0.0); + Assertions.assertDoesNotThrow(() -> sendBody(MILO_ITEM_1, 0.0)); } @Test public void testAcceptDataValueString() { - sendBody(MILO_ITEM_1, new DataValue(new Variant("Foo"))); + Assertions.assertDoesNotThrow(() -> sendBody(MILO_ITEM_1, new DataValue(new Variant("Foo")))); } @Test public void testAcceptDataValueDouble() { - sendBody(MILO_ITEM_1, new DataValue(new Variant(0.0))); + Assertions.assertDoesNotThrow(() -> sendBody(MILO_ITEM_1, new DataValue(new Variant(0.0)))); } } diff --git a/components/camel-milo/src/test/java/org/apache/camel/component/milo/server/ServerSetSecurityPoliciesTest.java b/components/camel-milo/src/test/java/org/apache/camel/component/milo/server/ServerSetSecurityPoliciesTest.java index ccb550d799009..c28ca63ae2559 100644 --- a/components/camel-milo/src/test/java/org/apache/camel/component/milo/server/ServerSetSecurityPoliciesTest.java +++ b/components/camel-milo/src/test/java/org/apache/camel/component/milo/server/ServerSetSecurityPoliciesTest.java @@ -17,6 +17,7 @@ package org.apache.camel.component.milo.server; import org.apache.camel.test.junit5.CamelTestSupport; +import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; /** @@ -27,19 +28,21 @@ public class ServerSetSecurityPoliciesTest extends CamelTestSupport { @Test public void testSetSecurityPolicies1() { final MiloServerComponent component = new MiloServerComponent(); - component.setSecurityPoliciesById("None"); + Assertions.assertDoesNotThrow(() -> component.setSecurityPoliciesById("None")); } @Test public void testSetSecurityPolicies2() { final MiloServerComponent component = new MiloServerComponent(); - component.setSecurityPoliciesById("http://opcfoundation.org/UA/SecurityPolicy#Basic256Sha256"); + Assertions.assertDoesNotThrow( + () -> component.setSecurityPoliciesById("http://opcfoundation.org/UA/SecurityPolicy#Basic256Sha256")); } @Test public void testSetSecurityPolicies3() { final MiloServerComponent component = new MiloServerComponent(); - component.setSecurityPoliciesById("None,http://opcfoundation.org/UA/SecurityPolicy#Basic256Sha256"); + Assertions.assertDoesNotThrow( + () -> component.setSecurityPoliciesById("None,http://opcfoundation.org/UA/SecurityPolicy#Basic256Sha256")); } }