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 2017/11/28 17:32:13 UTC

[camel] branch master updated: CAMEL-11869: Upgrade mockito-core to version 2.11.0 for camel-couchbase

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 d12cfc1  CAMEL-11869: Upgrade mockito-core to version 2.11.0 for camel-couchbase
d12cfc1 is described below

commit d12cfc1718185d9044a35921c3e823626548e8de
Author: aldettinger <al...@gmail.com>
AuthorDate: Tue Nov 28 18:31:28 2017 +0100

    CAMEL-11869: Upgrade mockito-core to version 2.11.0 for camel-couchbase
---
 components/camel-couchbase/pom.xml                 |  2 +-
 .../couchbase/CouchbaseComponentTest.java          | 25 ++++-------
 .../component/couchbase/CouchbaseConsumerTest.java |  2 +-
 .../component/couchbase/CouchbaseProducerTest.java | 50 ++++++++--------------
 4 files changed, 29 insertions(+), 50 deletions(-)

diff --git a/components/camel-couchbase/pom.xml b/components/camel-couchbase/pom.xml
index 3dd9635..440a1d4 100644
--- a/components/camel-couchbase/pom.xml
+++ b/components/camel-couchbase/pom.xml
@@ -65,10 +65,10 @@
     <dependency>
       <groupId>org.mockito</groupId>
       <artifactId>mockito-core</artifactId>
+      <version>${mockito2-version}</version>
       <scope>test</scope>
     </dependency>
 
   </dependencies>
 
-
 </project>
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 cd3850a..2314523 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
@@ -26,7 +26,7 @@ import org.apache.camel.Endpoint;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.mockito.Mock;
-import org.mockito.runners.MockitoJUnitRunner;
+import org.mockito.junit.MockitoJUnitRunner;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
@@ -40,7 +40,7 @@ public class CouchbaseComponentTest {
 
     @Test
     public void testEndpointCreated() throws Exception {
-        Map<String, Object> params = new HashMap<String, Object>();
+        Map<String, Object> params = new HashMap<>();
 
         String uri = "couchbase:http://localhost:9191/bucket";
         String remaining = "http://localhost:9191/bucket";
@@ -51,7 +51,7 @@ public class CouchbaseComponentTest {
 
     @Test
     public void testPropertiesSet() throws Exception {
-        Map<String, Object> params = new HashMap<String, Object>();
+        Map<String, Object> params = new HashMap<>();
         params.put("username", "ugol");
         params.put("password", "pwd");
         params.put("additionalHosts", "127.0.0.1,example.com,another-host");
@@ -77,7 +77,7 @@ public class CouchbaseComponentTest {
     @Test
     public void testCouchbaseURI() throws Exception {
 
-        Map<String, Object> params = new HashMap<String, Object>();
+        Map<String, Object> params = new HashMap<>();
         String uri = "couchbase:http://localhost/bucket?param=true";
         String remaining = "http://localhost/bucket?param=true";
 
@@ -89,15 +89,13 @@ public class CouchbaseComponentTest {
     @Test
     public void testCouchbaseAdditionalHosts() throws Exception {
 
-        Map<String, Object> params = new HashMap<String, Object>();
+        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";
         String remaining = "http://localhost/bucket?param=true";
 
         CouchbaseEndpoint endpoint = new CouchbaseComponent(context).createEndpoint(uri, remaining, params);
 
-        // System.out.print(endpoint.makeBootstrapURI()[0].toString() + " " +
-        // endpoint.makeBootstrapURI().length + " ");
         URI[] endpointArray = endpoint.makeBootstrapURI();
         assertEquals(new URI("http://localhost:8091/pools"), endpointArray[0]);
         assertEquals(new URI("http://127.0.0.1:8091/pools"), endpointArray[1]);
@@ -110,15 +108,13 @@ public class CouchbaseComponentTest {
     @Test
     public void testCouchbaseAdditionalHostsWithSpaces() throws Exception {
 
-        Map<String, Object> params = new HashMap<String, Object>();
+        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";
         String remaining = "http://localhost/bucket?param=true";
 
         CouchbaseEndpoint endpoint = new CouchbaseComponent(context).createEndpoint(uri, remaining, params);
 
-        // System.out.print(endpoint.makeBootstrapURI()[0].toString() + " " +
-        // endpoint.makeBootstrapURI().length + " ");
         URI[] endpointArray = endpoint.makeBootstrapURI();
         assertEquals(new URI("http://localhost:8091/pools"), endpointArray[0]);
         assertEquals(new URI("http://127.0.0.1:8091/pools"), endpointArray[1]);
@@ -131,7 +127,7 @@ public class CouchbaseComponentTest {
     @Test
     public void testCouchbaseDuplicateAdditionalHosts() throws Exception {
 
-        Map<String, Object> params = new HashMap<String, Object>();
+        Map<String, Object> params = new HashMap<>();
         params.put("additionalHosts", "127.0.0.1,localhost, localhost");
         String uri = "couchbase:http://localhost/bucket?param=true";
         String remaining = "http://localhost/bucket?param=true";
@@ -147,25 +143,22 @@ public class CouchbaseComponentTest {
     @Test
     public void testCouchbaseNullAdditionalHosts() throws Exception {
 
-        Map<String, Object> params = new HashMap<String, Object>();
+        Map<String, Object> params = new HashMap<>();
         params.put("additionalHosts", null);
         String uri = "couchbase:http://localhost/bucket?param=true";
         String remaining = "http://localhost/bucket?param=true";
 
         CouchbaseEndpoint endpoint = new CouchbaseComponent(context).createEndpoint(uri, remaining, params);
 
-        // System.out.print(endpoint.makeBootstrapURI()[0].toString() + " " +
-        // endpoint.makeBootstrapURI().length + " ");
         URI[] endpointArray = endpoint.makeBootstrapURI();
 
         assertEquals(1, endpointArray.length);
-
     }
 
     @Test
     public void testCouchbasePersistToAndReplicateToParameters() throws Exception {
 
-        Map<String, Object> params = new HashMap<String, Object>();
+        Map<String, Object> params = new HashMap<>();
         params.put("persistTo", "1");
         params.put("replicateTo", "2");
         String uri = "couchbase:http://localhost/bucket?param=true";
diff --git a/components/camel-couchbase/src/test/java/org/apache/camel/component/couchbase/CouchbaseConsumerTest.java b/components/camel-couchbase/src/test/java/org/apache/camel/component/couchbase/CouchbaseConsumerTest.java
index 3a52077..064216e 100644
--- a/components/camel-couchbase/src/test/java/org/apache/camel/component/couchbase/CouchbaseConsumerTest.java
+++ b/components/camel-couchbase/src/test/java/org/apache/camel/component/couchbase/CouchbaseConsumerTest.java
@@ -31,7 +31,7 @@ public class CouchbaseConsumerTest {
 
     @Test(expected = ConfigurationException.class)
     public void testNewCouchbaseConsumer() throws Exception {
-        CouchbaseConsumer couchbaseConsumer = new CouchbaseConsumer(new CouchbaseEndpoint(), new CouchbaseClient(new ArrayList<URI>(), "bucketName", "pwd"), new Processor() {
+        new CouchbaseConsumer(new CouchbaseEndpoint(), new CouchbaseClient(new ArrayList<URI>(), "bucketName", "pwd"), new Processor() {
             @Override
             public void process(Exchange exchange) throws Exception {
                 // Nothing to do
diff --git a/components/camel-couchbase/src/test/java/org/apache/camel/component/couchbase/CouchbaseProducerTest.java b/components/camel-couchbase/src/test/java/org/apache/camel/component/couchbase/CouchbaseProducerTest.java
index a2230fb..af9e26c 100644
--- a/components/camel-couchbase/src/test/java/org/apache/camel/component/couchbase/CouchbaseProducerTest.java
+++ b/components/camel-couchbase/src/test/java/org/apache/camel/component/couchbase/CouchbaseProducerTest.java
@@ -21,28 +21,29 @@ import java.util.Map;
 
 import com.couchbase.client.CouchbaseClient;
 
-import net.spy.memcached.PersistTo;
-import net.spy.memcached.ReplicateTo;
 import net.spy.memcached.internal.OperationFuture;
 
 import org.apache.camel.Exchange;
-import org.apache.camel.InvalidPayloadException;
 import org.apache.camel.Message;
 import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
+import org.junit.runner.RunWith;
 import org.mockito.Mock;
-import org.mockito.Mockito;
 import org.mockito.invocation.InvocationOnMock;
+import org.mockito.junit.MockitoJUnitRunner;
 import org.mockito.stubbing.Answer;
 
 import static org.apache.camel.component.couchbase.CouchbaseConstants.HEADER_TTL;
-import static org.mockito.Mockito.mock;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyInt;
+import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.ArgumentMatchers.eq;
 import static org.mockito.Mockito.times;
 import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
-import static org.mockito.MockitoAnnotations.initMocks;
 
+@RunWith(MockitoJUnitRunner.class)
 public class CouchbaseProducerTest {
 
     @Mock
@@ -58,22 +59,22 @@ public class CouchbaseProducerTest {
     private Message msg;
 
     @Mock
-    private OperationFuture response;
+    private OperationFuture<?> response;
+
+    @Mock
+    private OperationFuture<Boolean> of;
 
     private CouchbaseProducer producer;
 
     @Before
     public void before() throws Exception {
-        initMocks(this);
         when(endpoint.getProducerRetryAttempts()).thenReturn(CouchbaseConstants.DEFAULT_PRODUCER_RETRIES);
         producer = new CouchbaseProducer(endpoint, client, 0, 0);
         when(exchange.getIn()).thenReturn(msg);
     }
 
-    @SuppressWarnings("unchecked")
     @Test(expected = CouchbaseException.class)
     public void testBodyMandatory() throws Exception {
-        when(msg.getMandatoryBody()).thenThrow(InvalidPayloadException.class);
         producer.process(exchange);
     }
 
@@ -108,7 +109,6 @@ public class CouchbaseProducerTest {
 
     @Test
     public void testExpiryTimeIsSet() throws Exception {
-        OperationFuture of = mock(OperationFuture.class);
         when(of.get()).thenAnswer(new Answer<Object>() {
             @Override
             public Object answer(InvocationOnMock invocation) throws Exception {
@@ -117,31 +117,27 @@ public class CouchbaseProducerTest {
             }
         });
 
-        when(client.set(org.mockito.Matchers.anyString(), org.mockito.Matchers.anyInt(), org.mockito.Matchers.anyObject(), org.mockito.Matchers.any(PersistTo.class),
-                        org.mockito.Matchers.any(ReplicateTo.class))).thenReturn(of);
+        when(client.set(anyString(), anyInt(), any(), any(), any())).thenReturn(of);
+
         // Mock out some headers so we can set an expiry
         int expiry = 5000;
-        Map<String, Object> testHeaders = new HashMap<String, Object>();
+        Map<String, Object> testHeaders = new HashMap<>();
         testHeaders.put("CCB_TTL", Integer.toString(expiry));
         when(msg.getHeaders()).thenReturn(testHeaders);
         when(msg.getHeader(HEADER_TTL, String.class)).thenReturn(Integer.toString(expiry));
 
         when(endpoint.getId()).thenReturn("123");
         when(endpoint.getOperation()).thenReturn("CCB_PUT");
-        Message outmsg = mock(Message.class);
         when(exchange.getOut()).thenReturn(msg);
 
         producer.process(exchange);
 
-        verify(client).set(org.mockito.Matchers.anyString(), Mockito.eq(expiry), org.mockito.Matchers.anyObject(), org.mockito.Matchers.any(PersistTo.class),
-                           org.mockito.Matchers.any(ReplicateTo.class));
-
+        verify(client).set(anyString(), eq(expiry), any(), any(), any());
     }
 
     @Test
     public void testTimeOutRetryToException() throws Exception {
 
-        OperationFuture of = mock(OperationFuture.class);
         when(of.get()).thenAnswer(new Answer<Object>() {
             @Override
             public Object answer(InvocationOnMock invocation) throws Exception {
@@ -150,8 +146,7 @@ public class CouchbaseProducerTest {
             }
         });
 
-        when(client.set(org.mockito.Matchers.anyString(), org.mockito.Matchers.anyInt(), org.mockito.Matchers.anyObject(), org.mockito.Matchers.any(PersistTo.class),
-                        org.mockito.Matchers.any(ReplicateTo.class))).thenReturn(of);
+        when(client.set(anyString(), anyInt(), any(), any(), any())).thenReturn(of);
         when(endpoint.getId()).thenReturn("123");
         when(endpoint.getOperation()).thenReturn("CCB_PUT");
         try {
@@ -166,23 +161,19 @@ public class CouchbaseProducerTest {
     @Test
     public void testTimeOutRetryThenSuccess() throws Exception {
 
-        OperationFuture of = mock(OperationFuture.class);
         when(of.get()).thenAnswer(new Answer<Object>() {
             @Override
             public Object answer(InvocationOnMock invocation) throws Exception {
                 throw new RuntimeException("Timed out waiting for operation");
-
             }
         }).thenAnswer(new Answer<Object>() {
             @Override
             public Object answer(InvocationOnMock invocation) throws Exception {
                 return true;
-
             }
         });
 
-        when(client.set(org.mockito.Matchers.anyString(), org.mockito.Matchers.anyInt(), org.mockito.Matchers.anyObject(), org.mockito.Matchers.any(PersistTo.class),
-                        org.mockito.Matchers.any(ReplicateTo.class))).thenReturn(of);
+        when(client.set(anyString(), anyInt(), any(), any(), any())).thenReturn(of);
         when(endpoint.getId()).thenReturn("123");
         when(endpoint.getOperation()).thenReturn("CCB_PUT");
         when(exchange.getOut()).thenReturn(msg);
@@ -196,29 +187,24 @@ public class CouchbaseProducerTest {
     @Test
     public void testTimeOutRetryTwiceThenSuccess() throws Exception {
 
-        OperationFuture of = mock(OperationFuture.class);
         when(of.get()).thenAnswer(new Answer<Object>() {
             @Override
             public Object answer(InvocationOnMock invocation) throws Exception {
                 throw new RuntimeException("Timed out waiting for operation");
-
             }
         }).thenAnswer(new Answer<Object>() {
             @Override
             public Object answer(InvocationOnMock invocation) throws Exception {
                 throw new RuntimeException("Timed out waiting for operation");
-
             }
         }).thenAnswer(new Answer<Object>() {
             @Override
             public Object answer(InvocationOnMock invocation) throws Exception {
                 return true;
-
             }
         });
 
-        when(client.set(org.mockito.Matchers.anyString(), org.mockito.Matchers.anyInt(), org.mockito.Matchers.anyObject(), org.mockito.Matchers.any(PersistTo.class),
-                        org.mockito.Matchers.any(ReplicateTo.class))).thenReturn(of);
+        when(client.set(anyString(), anyInt(), any(), any(), any())).thenReturn(of);
         when(endpoint.getId()).thenReturn("123");
         when(endpoint.getOperation()).thenReturn("CCB_PUT");
         when(exchange.getOut()).thenReturn(msg);

-- 
To stop receiving notification emails like this one, please contact
['"commits@camel.apache.org" <co...@camel.apache.org>'].