You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by al...@apache.org on 2020/01/09 14:53:13 UTC

[camel] branch master updated: CAMEL-11807: Finished to migrate camel-ganglia tests to JUnit 5

This is an automated email from the ASF dual-hosted git repository.

aldettinger pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/master by this push:
     new b1f169d  CAMEL-11807: Finished to migrate camel-ganglia tests to JUnit 5
b1f169d is described below

commit b1f169d3d095d8e8e3903e2a90bd513bb8171145
Author: aldettinger <al...@gmail.com>
AuthorDate: Thu Jan 9 15:47:59 2020 +0100

    CAMEL-11807: Finished to migrate camel-ganglia tests to JUnit 5
---
 components/camel-ganglia/pom.xml                   | 13 +---
 .../component/ganglia/CamelGangliaTestSupport.java |  6 +-
 .../component/ganglia/GangliaProducerTest.java     | 14 ++--
 .../ganglia/GangliaProtocolV30CamelTest.java       | 13 ++--
 .../ganglia/GangliaProtocolV31CamelTest.java       | 82 ++++++++--------------
 5 files changed, 48 insertions(+), 80 deletions(-)

diff --git a/components/camel-ganglia/pom.xml b/components/camel-ganglia/pom.xml
index 90318b1..d88ac0a 100644
--- a/components/camel-ganglia/pom.xml
+++ b/components/camel-ganglia/pom.xml
@@ -53,8 +53,7 @@
         <!-- test dependencies -->
         <dependency>
             <groupId>org.apache.camel</groupId>
-            <artifactId>camel-test</artifactId>
-            <optional>true</optional>
+            <artifactId>camel-test-junit5</artifactId>
             <scope>test</scope>
         </dependency>
         <dependency>
@@ -65,24 +64,16 @@
         <dependency>
             <groupId>org.junit.jupiter</groupId>
             <artifactId>junit-jupiter-api</artifactId>
-            <version>${junit-jupiter-version}</version>
             <scope>test</scope>
         </dependency>
         <dependency>
             <groupId>org.junit.jupiter</groupId>
             <artifactId>junit-jupiter-engine</artifactId>
-            <version>${junit-jupiter-version}</version>
-            <scope>test</scope>
-        </dependency>
-        <dependency>
-            <groupId>org.junit.vintage</groupId>
-            <artifactId>junit-vintage-engine</artifactId>
-            <version>${junit-jupiter-version}</version>
             <scope>test</scope>
         </dependency>
         <dependency>
             <groupId>org.mockito</groupId>
-            <artifactId>mockito-core</artifactId>
+            <artifactId>mockito-junit-jupiter</artifactId>
             <scope>test</scope>
         </dependency>
         <dependency>
diff --git a/components/camel-ganglia/src/test/java/org/apache/camel/component/ganglia/CamelGangliaTestSupport.java b/components/camel-ganglia/src/test/java/org/apache/camel/component/ganglia/CamelGangliaTestSupport.java
index c0b1f9a..b5e0cba 100644
--- a/components/camel-ganglia/src/test/java/org/apache/camel/component/ganglia/CamelGangliaTestSupport.java
+++ b/components/camel-ganglia/src/test/java/org/apache/camel/component/ganglia/CamelGangliaTestSupport.java
@@ -17,13 +17,13 @@
 package org.apache.camel.component.ganglia;
 
 import org.apache.camel.test.AvailablePortFinder;
-import org.apache.camel.test.junit4.CamelTestSupport;
-import org.junit.Before;
+import org.apache.camel.test.junit5.CamelTestSupport;
+import org.junit.jupiter.api.BeforeEach;
 
 public class CamelGangliaTestSupport extends CamelTestSupport {
     private int testPort;
 
-    @Before
+    @BeforeEach
     public void setup() {
         testPort = AvailablePortFinder.getNextAvailable();
     }
diff --git a/components/camel-ganglia/src/test/java/org/apache/camel/component/ganglia/GangliaProducerTest.java b/components/camel-ganglia/src/test/java/org/apache/camel/component/ganglia/GangliaProducerTest.java
index 67ab789..c191b1c 100644
--- a/components/camel-ganglia/src/test/java/org/apache/camel/component/ganglia/GangliaProducerTest.java
+++ b/components/camel-ganglia/src/test/java/org/apache/camel/component/ganglia/GangliaProducerTest.java
@@ -24,16 +24,16 @@ import info.ganglia.gmetric4j.gmetric.GMetricSlope;
 import info.ganglia.gmetric4j.gmetric.GMetricType;
 import org.apache.camel.Exchange;
 import org.apache.camel.Message;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
 import org.mockito.Mock;
-import org.mockito.junit.MockitoJUnitRunner;
+import org.mockito.junit.jupiter.MockitoExtension;
 
 import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
 
-@RunWith(MockitoJUnitRunner.class)
+@ExtendWith(MockitoExtension.class)
 public class GangliaProducerTest {
 
     private static final String BODY = "2.0";
@@ -61,7 +61,7 @@ public class GangliaProducerTest {
     private GangliaEndpoint mockEndpoint;
     @Mock
     private Exchange mockExchange;
-    @Mock
+    @Mock(lenient = true)
     private Message mockMessage;
     @Mock
     private GangliaConfiguration mockConf;
@@ -69,7 +69,7 @@ public class GangliaProducerTest {
 
     private GangliaProducer gangliaProducer;
 
-    @Before
+    @BeforeEach
     public void setup() {
         when(mockEndpoint.getConfiguration()).thenReturn(mockConf);
 
diff --git a/components/camel-ganglia/src/test/java/org/apache/camel/component/ganglia/GangliaProtocolV30CamelTest.java b/components/camel-ganglia/src/test/java/org/apache/camel/component/ganglia/GangliaProtocolV30CamelTest.java
index ff4569b..f289a3d 100644
--- a/components/camel-ganglia/src/test/java/org/apache/camel/component/ganglia/GangliaProtocolV30CamelTest.java
+++ b/components/camel-ganglia/src/test/java/org/apache/camel/component/ganglia/GangliaProtocolV30CamelTest.java
@@ -34,9 +34,7 @@ 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.Rule;
-import org.junit.Test;
-import org.junit.rules.ExpectedException;
+import org.junit.jupiter.api.Test;
 
 import static info.ganglia.gmetric4j.gmetric.GMetricSlope.NEGATIVE;
 import static info.ganglia.gmetric4j.gmetric.GMetricType.FLOAT;
@@ -53,6 +51,8 @@ import static org.apache.camel.component.ganglia.GangliaConstants.METRIC_SLOPE;
 import static org.apache.camel.component.ganglia.GangliaConstants.METRIC_TMAX;
 import static org.apache.camel.component.ganglia.GangliaConstants.METRIC_TYPE;
 import static org.apache.camel.component.ganglia.GangliaConstants.METRIC_UNITS;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
 
 /**
  * {@code GangliaProtocolV30CamelTest} is not shipped with an embedded gmond
@@ -62,9 +62,6 @@ import static org.apache.camel.component.ganglia.GangliaConstants.METRIC_UNITS;
  */
 public class GangliaProtocolV30CamelTest extends CamelGangliaTestSupport {
 
-    @Rule
-    public ExpectedException thrown = ExpectedException.none();
-
     @BindToRegistry("protocolV30Decoder")
     private ProtocolV30Decoder protocolV30Decoder = new ProtocolV30Decoder();
 
@@ -84,7 +81,7 @@ public class GangliaProtocolV30CamelTest extends CamelGangliaTestSupport {
             @Override
             public void process(Exchange exchange) throws Exception {
                 Ganglia_message gangliaMessage = exchange.getIn().getBody(Ganglia_message.class);
-                assertNotNull("The gmond mock should only receive a non-null ganglia message", gangliaMessage);
+                assertNotNull(gangliaMessage, "The gmond mock should only receive a non-null ganglia message");
                 assertEquals(DEFAULT_METRIC_NAME, gangliaMessage.gmetric.name);
                 assertEquals(DEFAULT_TYPE.getGangliaType(), gangliaMessage.gmetric.type);
                 assertEquals(DEFAULT_SLOPE.getGangliaSlope(), gangliaMessage.gmetric.slope);
@@ -109,7 +106,7 @@ public class GangliaProtocolV30CamelTest extends CamelGangliaTestSupport {
             @Override
             public void process(Exchange exchange) throws Exception {
                 Ganglia_message gangliaMessage = exchange.getIn().getBody(Ganglia_message.class);
-                assertNotNull("The gmond mock should only receive a non-null ganglia message", gangliaMessage);
+                assertNotNull(gangliaMessage, "The gmond mock should only receive a non-null ganglia message");
                 assertEquals("depth", gangliaMessage.gmetric.name);
                 assertEquals("float", gangliaMessage.gmetric.type);
                 assertEquals(2, gangliaMessage.gmetric.slope);
diff --git a/components/camel-ganglia/src/test/java/org/apache/camel/component/ganglia/GangliaProtocolV31CamelTest.java b/components/camel-ganglia/src/test/java/org/apache/camel/component/ganglia/GangliaProtocolV31CamelTest.java
index 465e308..32b2c73 100644
--- a/components/camel-ganglia/src/test/java/org/apache/camel/component/ganglia/GangliaProtocolV31CamelTest.java
+++ b/components/camel-ganglia/src/test/java/org/apache/camel/component/ganglia/GangliaProtocolV31CamelTest.java
@@ -21,12 +21,6 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
-import info.ganglia.gmetric4j.xdr.v31x.Ganglia_metadata_msg;
-import info.ganglia.gmetric4j.xdr.v31x.Ganglia_value_msg;
-import io.netty.channel.ChannelHandler.Sharable;
-import io.netty.channel.ChannelHandlerContext;
-import io.netty.channel.socket.DatagramPacket;
-import io.netty.handler.codec.MessageToMessageDecoder;
 import org.acplt.oncrpc.OncRpcException;
 import org.acplt.oncrpc.XdrAble;
 import org.acplt.oncrpc.XdrBufferDecodingStream;
@@ -38,14 +32,8 @@ import org.apache.camel.Processor;
 import org.apache.camel.ResolveEndpointFailedException;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.component.mock.MockEndpoint;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.ExpectedException;
+import org.junit.jupiter.api.Test;
 
-import static info.ganglia.gmetric4j.gmetric.GMetricSlope.NEGATIVE;
-import static info.ganglia.gmetric4j.gmetric.GMetricType.FLOAT;
-import static info.ganglia.gmetric4j.xdr.v31x.Ganglia_msg_formats.gmetadata_full;
-import static info.ganglia.gmetric4j.xdr.v31x.Ganglia_msg_formats.gmetric_string;
 import static org.apache.camel.component.ganglia.GangliaConfiguration.DEFAULT_DMAX;
 import static org.apache.camel.component.ganglia.GangliaConfiguration.DEFAULT_METRIC_NAME;
 import static org.apache.camel.component.ganglia.GangliaConfiguration.DEFAULT_SLOPE;
@@ -59,6 +47,21 @@ import static org.apache.camel.component.ganglia.GangliaConstants.METRIC_SLOPE;
 import static org.apache.camel.component.ganglia.GangliaConstants.METRIC_TMAX;
 import static org.apache.camel.component.ganglia.GangliaConstants.METRIC_TYPE;
 import static org.apache.camel.component.ganglia.GangliaConstants.METRIC_UNITS;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.fail;
+
+import static info.ganglia.gmetric4j.gmetric.GMetricSlope.NEGATIVE;
+import static info.ganglia.gmetric4j.gmetric.GMetricType.FLOAT;
+import static info.ganglia.gmetric4j.xdr.v31x.Ganglia_msg_formats.gmetadata_full;
+import static info.ganglia.gmetric4j.xdr.v31x.Ganglia_msg_formats.gmetric_string;
+
+import info.ganglia.gmetric4j.xdr.v31x.Ganglia_metadata_msg;
+import info.ganglia.gmetric4j.xdr.v31x.Ganglia_value_msg;
+import io.netty.channel.ChannelHandler.Sharable;
+import io.netty.channel.ChannelHandlerContext;
+import io.netty.channel.socket.DatagramPacket;
+import io.netty.handler.codec.MessageToMessageDecoder;
 
 /**
  * {@code GangliaProtocolV31CamelTest} is not shipped with an embedded gmond
@@ -68,9 +71,6 @@ import static org.apache.camel.component.ganglia.GangliaConstants.METRIC_UNITS;
  */
 public class GangliaProtocolV31CamelTest extends CamelGangliaTestSupport {
 
-    @Rule
-    public ExpectedException thrown = ExpectedException.none();
-
     @BindToRegistry("protocolV31Decoder")
     private ProtocolV31Decoder protocolV31Decoder = new ProtocolV31Decoder();
 
@@ -157,57 +157,37 @@ public class GangliaProtocolV31CamelTest extends CamelGangliaTestSupport {
 
     @Test
     public void sendWrongMetricTypeShouldThrow() throws Exception {
-        thrown.expect(CamelExecutionException.class);
-        mockGmond.setExpectedMessageCount(0);
-        mockGmond.setAssertPeriod(100L);
-
-        template.sendBodyAndHeader(getTestUri(), "28.0", METRIC_TYPE, "NotAGMetricType");
-
-        mockGmond.assertIsSatisfied();
+        assertThrows(CamelExecutionException.class, () -> {
+            template.sendBodyAndHeader(getTestUri(), "28.0", METRIC_TYPE, "NotAGMetricType");
+        });
     }
 
     @Test
     public void sendWrongMetricSlopeShouldThrow() throws Exception {
-        thrown.expect(CamelExecutionException.class);
-        mockGmond.setExpectedMessageCount(0);
-        mockGmond.setAssertPeriod(100L);
-
-        template.sendBodyAndHeader(getTestUri(), "28.0", METRIC_SLOPE, "NotAGMetricSlope");
-
-        mockGmond.assertIsSatisfied();
+        assertThrows(CamelExecutionException.class, () -> {
+            template.sendBodyAndHeader(getTestUri(), "28.0", METRIC_SLOPE, "NotAGMetricSlope");
+        });
     }
 
     @Test
     public void sendWrongMetricTMaxShouldThrow() throws Exception {
-        thrown.expect(CamelExecutionException.class);
-        mockGmond.setExpectedMessageCount(0);
-        mockGmond.setAssertPeriod(100L);
-
-        template.sendBodyAndHeader(getTestUri(), "28.0", METRIC_TMAX, new Object());
-
-        mockGmond.assertIsSatisfied();
+        assertThrows(CamelExecutionException.class, () -> {
+            template.sendBodyAndHeader(getTestUri(), "28.0", METRIC_TMAX, new Object());
+        });
     }
 
     @Test
     public void sendWrongMetricDMaxShouldThrow() throws Exception {
-        thrown.expect(CamelExecutionException.class);
-        mockGmond.setExpectedMessageCount(0);
-        mockGmond.setAssertPeriod(100L);
-
-        template.sendBodyAndHeader(getTestUri(), "28.0", METRIC_DMAX, new Object());
-
-        mockGmond.assertIsSatisfied();
+        assertThrows(CamelExecutionException.class, () -> {
+            template.sendBodyAndHeader(getTestUri(), "28.0", METRIC_DMAX, new Object());
+        });
     }
 
     @Test
     public void sendWithWrongTypeShouldThrow() throws Exception {
-        thrown.expect(ResolveEndpointFailedException.class);
-        mockGmond.setExpectedMessageCount(0);
-        mockGmond.setAssertPeriod(100L);
-
-        template.sendBody(getTestUri() + "&type=wrong", "");
-
-        mockGmond.assertIsSatisfied();
+        assertThrows(ResolveEndpointFailedException.class, () -> {
+            template.sendBody(getTestUri() + "&type=wrong", "");
+        });
     }
 
     @Override