Skip to content

Commit

Permalink
(chores) fixed missing assertions in test code (#6002)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
orpiske committed Aug 28, 2021
1 parent 404c6b4 commit 7a43633
Show file tree
Hide file tree
Showing 14 changed files with 70 additions and 50 deletions.
Expand Up @@ -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 {

}

}
Expand Up @@ -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();
Expand Down
Expand Up @@ -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)
Expand Down Expand Up @@ -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<Map> test(String key, Object value) {
Expand Down
Expand Up @@ -34,21 +34,23 @@
*/
public class HttpInvalidConfigurationTest extends CamelTestSupport {

private FailedToCreateRouteException exception;

@BeforeEach
@Override
public void setUp() throws Exception {
try {
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
Expand Down
Expand Up @@ -34,21 +34,23 @@
*/
public class HttpInvalidHttpClientConfigurationTest extends CamelTestSupport {

private FailedToCreateRouteException exception;

@BeforeEach
@Override
public void setUp() throws Exception {
try {
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
Expand Down
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down
Expand Up @@ -17,13 +17,15 @@
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;
import org.junit.jupiter.api.Test;
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;

/**
Expand All @@ -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"));
}
}
Expand Up @@ -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;
Expand All @@ -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;

/**
Expand Down Expand Up @@ -88,9 +89,9 @@ public void setUp() throws Exception {
* Tests whether <code>receive(long)</code> honours the <code>timeout</code> 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));
}

/**
Expand Down
Expand Up @@ -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;
Expand Down Expand Up @@ -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));
}
}
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}
Expand All @@ -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"));
}
}
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}
Expand All @@ -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"));
}
}
Expand Up @@ -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;

Expand Down Expand Up @@ -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
Expand Down
Expand Up @@ -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;

Expand Down Expand Up @@ -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))));
}
}
Expand Up @@ -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;

/**
Expand All @@ -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"));
}

}

0 comments on commit 7a43633

Please sign in to comment.