You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2019/08/23 07:30:55 UTC

[camel] 03/06: Avoid using mockito when possible

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

davsclaus pushed a commit to branch CAMEL-13870
in repository https://gitbox.apache.org/repos/asf/camel.git

commit e316246745682c8f5dcb21bdef66e14f111eedc3
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Fri Aug 23 08:00:29 2019 +0200

    Avoid using mockito when possible
---
 components/camel-couchbase/pom.xml                 | 19 ++++++++--
 .../couchbase/CouchbaseComponentTest.java          | 41 ++++++++--------------
 .../component/couchdb/CouchDbComponentTest.java    | 29 +++++----------
 3 files changed, 40 insertions(+), 49 deletions(-)

diff --git a/components/camel-couchbase/pom.xml b/components/camel-couchbase/pom.xml
index 296384d..09be1d2 100644
--- a/components/camel-couchbase/pom.xml
+++ b/components/camel-couchbase/pom.xml
@@ -49,8 +49,23 @@
         </dependency>
 
         <dependency>
-            <groupId>org.slf4j</groupId>
-            <artifactId>slf4j-log4j12</artifactId>
+            <groupId>org.apache.logging.log4j</groupId>
+            <artifactId>log4j-api</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.logging.log4j</groupId>
+            <artifactId>log4j-core</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.logging.log4j</groupId>
+            <artifactId>log4j-slf4j-impl</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.logging.log4j</groupId>
+            <artifactId>log4j-1.2-api</artifactId>
             <scope>test</scope>
         </dependency>
 
diff --git a/components/camel-couchbase/src/test/java/org/apache/camel/component/couchbase/CouchbaseComponentTest.java b/components/camel-couchbase/src/test/java/org/apache/camel/component/couchbase/CouchbaseComponentTest.java
index 6af8326..a2b0222 100644
--- a/components/camel-couchbase/src/test/java/org/apache/camel/component/couchbase/CouchbaseComponentTest.java
+++ b/components/camel-couchbase/src/test/java/org/apache/camel/component/couchbase/CouchbaseComponentTest.java
@@ -20,24 +20,23 @@ import java.net.URI;
 import java.util.HashMap;
 import java.util.Map;
 
-import org.apache.camel.CamelContext;
-import org.apache.camel.Endpoint;
+import org.apache.camel.test.junit4.CamelTestSupport;
 import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.Mock;
-import org.mockito.junit.MockitoJUnitRunner;
 
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.mockito.AdditionalAnswers.returnsFirstArg;
-import static org.mockito.ArgumentMatchers.anyString;
-import static org.mockito.Mockito.when;
+public class CouchbaseComponentTest extends CamelTestSupport {
 
-@RunWith(MockitoJUnitRunner.class)
-public class CouchbaseComponentTest {
+    private CouchbaseComponent component;
 
-    @Mock
-    private CamelContext context;
+    @Override
+    public void setUp() throws Exception {
+        super.setUp();
+        component = context.getComponent("couchbase",  CouchbaseComponent.class);
+    }
+
+    @Override
+    public boolean isUseRouteBuilder() {
+        return false;
+    }
 
     @Test
     public void testEndpointCreated() throws Exception {
@@ -46,14 +45,12 @@ public class CouchbaseComponentTest {
         String uri = "couchbase:http://localhost:9191/bucket";
         String remaining = "http://localhost:9191/bucket";
 
-        Endpoint endpoint = new CouchbaseComponent(context).createEndpoint(uri, remaining, params);
+        CouchbaseEndpoint endpoint = component.createEndpoint(uri, remaining, params);
         assertNotNull(endpoint);
     }
 
     @Test
     public void testPropertiesSet() throws Exception {
-        when(context.resolvePropertyPlaceholders(anyString())).then(returnsFirstArg());
-
         Map<String, Object> params = new HashMap<>();
         params.put("username", "ugol");
         params.put("password", "pwd");
@@ -64,7 +61,7 @@ public class CouchbaseComponentTest {
         String uri = "couchdb:http://localhost:91234/bucket";
         String remaining = "http://localhost:91234/bucket";
 
-        CouchbaseEndpoint endpoint = new CouchbaseComponent(context).createEndpoint(uri, remaining, params);
+        CouchbaseEndpoint endpoint = component.createEndpoint(uri, remaining, params);
 
         assertEquals("http", endpoint.getProtocol());
         assertEquals("localhost", endpoint.getHostname());
@@ -89,8 +86,6 @@ public class CouchbaseComponentTest {
 
     @Test
     public void testCouchbaseAdditionalHosts() throws Exception {
-        when(context.resolvePropertyPlaceholders(anyString())).then(returnsFirstArg());
-
         Map<String, Object> params = new HashMap<>();
         params.put("additionalHosts", "127.0.0.1,example.com,another-host");
         String uri = "couchbase:http://localhost/bucket?param=true";
@@ -108,8 +103,6 @@ public class CouchbaseComponentTest {
 
     @Test
     public void testCouchbaseAdditionalHostsWithSpaces() throws Exception {
-        when(context.resolvePropertyPlaceholders(anyString())).then(returnsFirstArg());
-
         Map<String, Object> params = new HashMap<>();
         params.put("additionalHosts", " 127.0.0.1, example.com, another-host ");
         String uri = "couchbase:http://localhost/bucket?param=true";
@@ -127,8 +120,6 @@ public class CouchbaseComponentTest {
 
     @Test
     public void testCouchbaseDuplicateAdditionalHosts() throws Exception {
-        when(context.resolvePropertyPlaceholders(anyString())).then(returnsFirstArg());
-
         Map<String, Object> params = new HashMap<>();
         params.put("additionalHosts", "127.0.0.1,localhost, localhost");
         String uri = "couchbase:http://localhost/bucket?param=true";
@@ -143,8 +134,6 @@ public class CouchbaseComponentTest {
 
     @Test
     public void testCouchbaseNullAdditionalHosts() throws Exception {
-        when(context.resolvePropertyPlaceholders(anyString())).then(returnsFirstArg());
-
         Map<String, Object> params = new HashMap<>();
         params.put("additionalHosts", null);
         String uri = "couchbase:http://localhost/bucket?param=true";
diff --git a/components/camel-couchdb/src/test/java/org/apache/camel/component/couchdb/CouchDbComponentTest.java b/components/camel-couchdb/src/test/java/org/apache/camel/component/couchdb/CouchDbComponentTest.java
index c375dd0..5d472a6 100644
--- a/components/camel-couchdb/src/test/java/org/apache/camel/component/couchdb/CouchDbComponentTest.java
+++ b/components/camel-couchdb/src/test/java/org/apache/camel/component/couchdb/CouchDbComponentTest.java
@@ -19,26 +19,15 @@ package org.apache.camel.component.couchdb;
 import java.util.HashMap;
 import java.util.Map;
 
-import org.apache.camel.CamelContext;
-import org.apache.camel.Endpoint;
+import org.apache.camel.test.junit4.CamelTestSupport;
 import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.Mock;
-import org.mockito.junit.MockitoJUnitRunner;
 
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-import static org.mockito.AdditionalAnswers.returnsFirstArg;
-import static org.mockito.ArgumentMatchers.anyString;
-import static org.mockito.Mockito.when;
+public class CouchDbComponentTest extends CamelTestSupport {
 
-@RunWith(MockitoJUnitRunner.class)
-public class CouchDbComponentTest {
-
-    @Mock
-    private CamelContext context;
+    @Override
+    public boolean isUseRouteBuilder() {
+        return false;
+    }
 
     @Test
     public void testEndpointCreated() throws Exception {
@@ -47,14 +36,12 @@ public class CouchDbComponentTest {
         String uri = "couchdb:http://localhost:5984/db";
         String remaining = "http://localhost:5984/db";
 
-        Endpoint endpoint = new CouchDbComponent(context).createEndpoint(uri, remaining, params);
+        CouchDbEndpoint endpoint = context.getComponent("couchdb", CouchDbComponent.class).createEndpoint(uri, remaining, params);
         assertNotNull(endpoint);
     }
 
     @Test
     public void testPropertiesSet() throws Exception {
-        when(context.resolvePropertyPlaceholders(anyString())).then(returnsFirstArg());
-
         Map<String, Object> params = new HashMap<>();
         params.put("createDatabase", true);
         params.put("username", "coldplay");
@@ -67,7 +54,7 @@ public class CouchDbComponentTest {
         String uri = "couchdb:http://localhost:14/db";
         String remaining = "http://localhost:14/db";
 
-        CouchDbEndpoint endpoint = new CouchDbComponent(context).createEndpoint(uri, remaining, params);
+        CouchDbEndpoint endpoint = context.getComponent("couchdb", CouchDbComponent.class).createEndpoint(uri, remaining, params);
         assertEquals("http", endpoint.getProtocol());
         assertEquals("localhost", endpoint.getHostname());
         assertEquals("db", endpoint.getDatabase());