You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by ol...@apache.org on 2021/05/23 16:42:55 UTC

[httpcomponents-core] 03/03: Upgraded Mockito to version 3.10.0

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

olegk pushed a commit to branch devel
in repository https://gitbox.apache.org/repos/asf/httpcomponents-core.git

commit 788aa4b81654dd00b89237f910a1abee3cf01a6a
Author: Oleg Kalnichevski <ol...@apache.org>
AuthorDate: Sun May 23 18:35:58 2021 +0200

    Upgraded Mockito to version 3.10.0
---
 .../http/impl/io/TestBHttpConnectionBase.java      | 19 ++------
 .../impl/io/TestDefaultBHttpClientConnection.java  | 17 +++----
 .../impl/io/TestDefaultBHttpServerConnection.java  | 17 +++----
 .../hc/core5/http/impl/io/TestHttpService.java     |  7 +--
 ...tAbstractHttp1StreamDuplexerCapacityWindow.java | 52 ++++++++++++----------
 .../nio/support/classic/TestSharedInputBuffer.java |  8 ++--
 .../support/classic/TestSharedOutputBuffer.java    |  4 +-
 pom.xml                                            |  2 +-
 8 files changed, 62 insertions(+), 64 deletions(-)

diff --git a/httpcore5/src/test/java/org/apache/hc/core5/http/impl/io/TestBHttpConnectionBase.java b/httpcore5/src/test/java/org/apache/hc/core5/http/impl/io/TestBHttpConnectionBase.java
index fc0cdb4..8559dca 100644
--- a/httpcore5/src/test/java/org/apache/hc/core5/http/impl/io/TestBHttpConnectionBase.java
+++ b/httpcore5/src/test/java/org/apache/hc/core5/http/impl/io/TestBHttpConnectionBase.java
@@ -45,11 +45,13 @@ import org.apache.hc.core5.util.Timeout;
 import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
+import org.junit.runner.RunWith;
 import org.mockito.ArgumentMatchers;
 import org.mockito.Mock;
 import org.mockito.Mockito;
-import org.mockito.MockitoAnnotations;
+import org.mockito.junit.MockitoJUnitRunner;
 
+@RunWith(MockitoJUnitRunner.class)
 public class TestBHttpConnectionBase {
 
     @Mock
@@ -58,8 +60,7 @@ public class TestBHttpConnectionBase {
     private BHttpConnectionBase conn;
 
     @Before
-    public void setUp() throws Exception {
-        MockitoAnnotations.initMocks(this);
+    public void prepareMocks() {
         conn = new BHttpConnectionBase(Http1Config.DEFAULT, null, null);
     }
 
@@ -81,10 +82,6 @@ public class TestBHttpConnectionBase {
         final InetSocketAddress remoteSockAddress = new InetSocketAddress(remoteAddress, remotePort);
         Mockito.when(socket.getLocalSocketAddress()).thenReturn(localSockAddress);
         Mockito.when(socket.getRemoteSocketAddress()).thenReturn(remoteSockAddress);
-        Mockito.when(socket.getLocalAddress()).thenReturn(localAddress);
-        Mockito.when(socket.getLocalPort()).thenReturn(localPort);
-        Mockito.when(socket.getInetAddress()).thenReturn(remoteAddress);
-        Mockito.when(socket.getPort()).thenReturn(remotePort);
         conn.bind(socket);
 
         Assert.assertEquals("127.0.0.1:8888<->10.0.0.2:80", conn.toString());
@@ -98,10 +95,7 @@ public class TestBHttpConnectionBase {
 
     @Test
     public void testConnectionClose() throws Exception {
-        final InputStream inStream = Mockito.mock(InputStream.class);
         final OutputStream outStream = Mockito.mock(OutputStream.class);
-
-        Mockito.when(socket.getInputStream()).thenReturn(inStream);
         Mockito.when(socket.getOutputStream()).thenReturn(outStream);
 
         conn.bind(socket);
@@ -126,10 +120,7 @@ public class TestBHttpConnectionBase {
 
     @Test
     public void testConnectionShutdown() throws Exception {
-        final InputStream inStream = Mockito.mock(InputStream.class);
         final OutputStream outStream = Mockito.mock(OutputStream.class);
-        Mockito.when(socket.getInputStream()).thenReturn(inStream);
-        Mockito.when(socket.getOutputStream()).thenReturn(outStream);
 
         conn.bind(socket);
         conn.ensureOpen();
@@ -242,8 +233,6 @@ public class TestBHttpConnectionBase {
     public void testAwaitInputInBuffer() throws Exception {
         final ByteArrayInputStream inStream = Mockito.spy(new ByteArrayInputStream(
                 new byte[] {1, 2, 3, 4, 5}));
-        Mockito.when(socket.getInputStream()).thenReturn(inStream);
-
         conn.bind(socket);
         conn.ensureOpen();
         conn.inBuffer.read(inStream);
diff --git a/httpcore5/src/test/java/org/apache/hc/core5/http/impl/io/TestDefaultBHttpClientConnection.java b/httpcore5/src/test/java/org/apache/hc/core5/http/impl/io/TestDefaultBHttpClientConnection.java
index 41d1ffe..d74cc79 100644
--- a/httpcore5/src/test/java/org/apache/hc/core5/http/impl/io/TestDefaultBHttpClientConnection.java
+++ b/httpcore5/src/test/java/org/apache/hc/core5/http/impl/io/TestDefaultBHttpClientConnection.java
@@ -47,10 +47,12 @@ import org.apache.hc.core5.http.message.BasicClassicHttpRequest;
 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.MockitoAnnotations;
+import org.mockito.junit.MockitoJUnitRunner;
 
+@RunWith(MockitoJUnitRunner.class)
 public class TestDefaultBHttpClientConnection {
 
     @Mock
@@ -59,14 +61,13 @@ public class TestDefaultBHttpClientConnection {
     private DefaultBHttpClientConnection conn;
 
     @Before
-    public void setUp() throws Exception {
-        MockitoAnnotations.initMocks(this);
+    public void prepareMocks() {
         conn = new DefaultBHttpClientConnection(Http1Config.DEFAULT,
-            null, null,
-            DefaultContentLengthStrategy.INSTANCE,
-            DefaultContentLengthStrategy.INSTANCE,
-            DefaultHttpRequestWriterFactory.INSTANCE,
-            DefaultHttpResponseParserFactory.INSTANCE);
+                null, null,
+                DefaultContentLengthStrategy.INSTANCE,
+                DefaultContentLengthStrategy.INSTANCE,
+                DefaultHttpRequestWriterFactory.INSTANCE,
+                DefaultHttpResponseParserFactory.INSTANCE);
     }
 
     @Test
diff --git a/httpcore5/src/test/java/org/apache/hc/core5/http/impl/io/TestDefaultBHttpServerConnection.java b/httpcore5/src/test/java/org/apache/hc/core5/http/impl/io/TestDefaultBHttpServerConnection.java
index 6919075..016d10d 100644
--- a/httpcore5/src/test/java/org/apache/hc/core5/http/impl/io/TestDefaultBHttpServerConnection.java
+++ b/httpcore5/src/test/java/org/apache/hc/core5/http/impl/io/TestDefaultBHttpServerConnection.java
@@ -46,10 +46,12 @@ import org.apache.hc.core5.http.message.BasicClassicHttpResponse;
 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.MockitoAnnotations;
+import org.mockito.junit.MockitoJUnitRunner;
 
+@RunWith(MockitoJUnitRunner.class)
 public class TestDefaultBHttpServerConnection {
 
     @Mock
@@ -58,14 +60,13 @@ public class TestDefaultBHttpServerConnection {
     private DefaultBHttpServerConnection conn;
 
     @Before
-    public void setUp() throws Exception {
-        MockitoAnnotations.initMocks(this);
+    public void prepareMocks() {
         conn = new DefaultBHttpServerConnection("http", Http1Config.DEFAULT,
-            null, null,
-            DefaultContentLengthStrategy.INSTANCE,
-            DefaultContentLengthStrategy.INSTANCE,
-            DefaultHttpRequestParserFactory.INSTANCE,
-            DefaultHttpResponseWriterFactory.INSTANCE);
+                null, null,
+                DefaultContentLengthStrategy.INSTANCE,
+                DefaultContentLengthStrategy.INSTANCE,
+                DefaultHttpRequestParserFactory.INSTANCE,
+                DefaultHttpResponseWriterFactory.INSTANCE);
     }
 
     @Test
diff --git a/httpcore5/src/test/java/org/apache/hc/core5/http/impl/io/TestHttpService.java b/httpcore5/src/test/java/org/apache/hc/core5/http/impl/io/TestHttpService.java
index 860d0ce..df80c94 100644
--- a/httpcore5/src/test/java/org/apache/hc/core5/http/impl/io/TestHttpService.java
+++ b/httpcore5/src/test/java/org/apache/hc/core5/http/impl/io/TestHttpService.java
@@ -52,13 +52,15 @@ import org.apache.hc.core5.http.protocol.HttpProcessor;
 import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
+import org.junit.runner.RunWith;
 import org.mockito.ArgumentCaptor;
 import org.mockito.ArgumentMatchers;
 import org.mockito.Mock;
 import org.mockito.Mockito;
-import org.mockito.MockitoAnnotations;
 import org.mockito.Spy;
+import org.mockito.junit.MockitoJUnitRunner;
 
+@RunWith(MockitoJUnitRunner.class)
 public class TestHttpService {
 
     @Mock
@@ -79,8 +81,7 @@ public class TestHttpService {
     private HttpService httpservice;
 
     @Before
-    public void settup() {
-        MockitoAnnotations.initMocks(this);
+    public void prepareMocks() {
         httpservice = new HttpService(
                 httprocessor,
                 handlerResolver,
diff --git a/httpcore5/src/test/java/org/apache/hc/core5/http/impl/nio/TestAbstractHttp1StreamDuplexerCapacityWindow.java b/httpcore5/src/test/java/org/apache/hc/core5/http/impl/nio/TestAbstractHttp1StreamDuplexerCapacityWindow.java
index de22ec7..615db52 100644
--- a/httpcore5/src/test/java/org/apache/hc/core5/http/impl/nio/TestAbstractHttp1StreamDuplexerCapacityWindow.java
+++ b/httpcore5/src/test/java/org/apache/hc/core5/http/impl/nio/TestAbstractHttp1StreamDuplexerCapacityWindow.java
@@ -27,46 +27,52 @@
 
 package org.apache.hc.core5.http.impl.nio;
 
+import java.io.IOException;
+import java.nio.channels.SelectionKey;
+
 import org.apache.hc.core5.http.impl.nio.AbstractHttp1StreamDuplexer.CapacityWindow;
 import org.apache.hc.core5.reactor.IOSession;
+import org.junit.After;
+import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
 import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.MockitoAnnotations;
 
-import java.io.IOException;
-import java.nio.channels.SelectionKey;
+public class TestAbstractHttp1StreamDuplexerCapacityWindow {
 
-import static org.junit.Assert.assertEquals;
-import static org.mockito.ArgumentMatchers.eq;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.verifyNoMoreInteractions;
-import static org.mockito.Mockito.verifyZeroInteractions;
-import static org.mockito.MockitoAnnotations.initMocks;
+    @Mock
+    private IOSession ioSession;
 
-public class TestAbstractHttp1StreamDuplexerCapacityWindow {
-    @Mock private IOSession ioSession;
+    private AutoCloseable closeable;
 
     @Before
-    public void before() {
-        initMocks(this);
+    public void prepareMocks() {
+        closeable = MockitoAnnotations.openMocks(this);
+    }
+
+    @After
+    public void releaseMocks() throws Exception {
+        closeable.close();
     }
 
     @Test
     public void testWindowUpdate() throws IOException {
         final CapacityWindow window = new CapacityWindow(0, ioSession);
         window.update(1);
-        assertEquals(1, window.getWindow());
-        verify(ioSession).setEvent(eq(SelectionKey.OP_READ));
-        verifyNoMoreInteractions(ioSession);
+        Assert.assertEquals(1, window.getWindow());
+        Mockito.verify(ioSession).setEvent(Mockito.eq(SelectionKey.OP_READ));
+        Mockito.verifyNoMoreInteractions(ioSession);
     }
 
     @Test
     public void testRemoveCapacity() {
         final CapacityWindow window = new CapacityWindow(1, ioSession);
         window.removeCapacity(1);
-        assertEquals(0, window.getWindow());
-        verify(ioSession).clearEvent(eq(SelectionKey.OP_READ));
-        verifyNoMoreInteractions(ioSession);
+        Assert.assertEquals(0, window.getWindow());
+        Mockito.verify(ioSession).clearEvent(Mockito.eq(SelectionKey.OP_READ));
+        Mockito.verifyNoMoreInteractions(ioSession);
     }
 
     @Test
@@ -74,21 +80,21 @@ public class TestAbstractHttp1StreamDuplexerCapacityWindow {
         final CapacityWindow window = new CapacityWindow(1, ioSession);
         window.close();
         window.update(1);
-        verifyZeroInteractions(ioSession);
+        Mockito.verifyNoInteractions(ioSession);
     }
 
     @Test
     public void windowCannotUnderflow() {
         final CapacityWindow window = new CapacityWindow(Integer.MIN_VALUE, ioSession);
         window.removeCapacity(1);
-        assertEquals(Integer.MIN_VALUE, window.getWindow());
+        Assert.assertEquals(Integer.MIN_VALUE, window.getWindow());
     }
 
     @Test
     public void windowCannotOverflow() throws IOException{
         final CapacityWindow window = new CapacityWindow(Integer.MAX_VALUE, ioSession);
         window.update(1);
-        assertEquals(Integer.MAX_VALUE, window.getWindow());
+        Assert.assertEquals(Integer.MAX_VALUE, window.getWindow());
     }
 
     @Test
@@ -96,7 +102,7 @@ public class TestAbstractHttp1StreamDuplexerCapacityWindow {
         final CapacityWindow window = new CapacityWindow(1, ioSession);
         window.update(0);
         window.update(-1);
-        assertEquals(1, window.getWindow());
-        verifyZeroInteractions(ioSession);
+        Assert.assertEquals(1, window.getWindow());
+        Mockito.verifyNoInteractions(ioSession);
     }
 }
diff --git a/httpcore5/src/test/java/org/apache/hc/core5/http/nio/support/classic/TestSharedInputBuffer.java b/httpcore5/src/test/java/org/apache/hc/core5/http/nio/support/classic/TestSharedInputBuffer.java
index bcacbc9..ec32332 100644
--- a/httpcore5/src/test/java/org/apache/hc/core5/http/nio/support/classic/TestSharedInputBuffer.java
+++ b/httpcore5/src/test/java/org/apache/hc/core5/http/nio/support/classic/TestSharedInputBuffer.java
@@ -58,18 +58,18 @@ public class TestSharedInputBuffer {
         final CapacityChannel capacityChannel = Mockito.mock(CapacityChannel.class);
 
         inputBuffer.updateCapacity(capacityChannel);
-        Mockito.verifyZeroInteractions(capacityChannel);
+        Mockito.verifyNoInteractions(capacityChannel);
 
         inputBuffer.fill(charset.encode("1234567890"));
         inputBuffer.fill(charset.encode("1234567890"));
         Assert.assertEquals(30, inputBuffer.length());
 
-        Mockito.verifyZeroInteractions(capacityChannel);
+        Mockito.verifyNoInteractions(capacityChannel);
 
         final byte[] tmp = new byte[20];
         final int bytesRead1 = inputBuffer.read(tmp, 0, tmp.length);
         Assert.assertEquals(20, bytesRead1);
-        Mockito.verifyZeroInteractions(capacityChannel);
+        Mockito.verifyNoInteractions(capacityChannel);
 
         inputBuffer.markEndStream();
 
@@ -77,7 +77,7 @@ public class TestSharedInputBuffer {
         Assert.assertEquals('2', inputBuffer.read());
         final int bytesRead2 = inputBuffer.read(tmp, 0, tmp.length);
         Assert.assertEquals(8, bytesRead2);
-        Mockito.verifyZeroInteractions(capacityChannel);
+        Mockito.verifyNoInteractions(capacityChannel);
         Assert.assertEquals(-1, inputBuffer.read(tmp, 0, tmp.length));
         Assert.assertEquals(-1, inputBuffer.read(tmp, 0, tmp.length));
         Assert.assertEquals(-1, inputBuffer.read());
diff --git a/httpcore5/src/test/java/org/apache/hc/core5/http/nio/support/classic/TestSharedOutputBuffer.java b/httpcore5/src/test/java/org/apache/hc/core5/http/nio/support/classic/TestSharedOutputBuffer.java
index 61af5c9..cabe143 100644
--- a/httpcore5/src/test/java/org/apache/hc/core5/http/nio/support/classic/TestSharedOutputBuffer.java
+++ b/httpcore5/src/test/java/org/apache/hc/core5/http/nio/support/classic/TestSharedOutputBuffer.java
@@ -95,7 +95,7 @@ public class TestSharedOutputBuffer {
         final DataStreamChannel dataStreamChannel = Mockito.spy(new DataStreamChannelMock(channel));
         outputBuffer.flush(dataStreamChannel);
 
-        Mockito.verifyZeroInteractions(dataStreamChannel);
+        Mockito.verifyNoInteractions(dataStreamChannel);
 
         Assert.assertEquals(0, outputBuffer.length());
         Assert.assertEquals(30, outputBuffer.capacity());
@@ -109,7 +109,7 @@ public class TestSharedOutputBuffer {
         Assert.assertEquals(22, outputBuffer.length());
         Assert.assertEquals(8, outputBuffer.capacity());
 
-        Mockito.verifyZeroInteractions(dataStreamChannel);
+        Mockito.verifyNoInteractions(dataStreamChannel);
     }
 
     @Test
diff --git a/pom.xml b/pom.xml
index 9df0312..d2d78e0 100644
--- a/pom.xml
+++ b/pom.xml
@@ -73,7 +73,7 @@
     <maven.compiler.showDeprecation>true</maven.compiler.showDeprecation>
     <conscrypt.version>2.2.1</conscrypt.version>
     <junit.version>4.13</junit.version>
-    <mockito.version>2.25.1</mockito.version>
+    <mockito.version>3.10.0</mockito.version>
     <slf4j.version>1.7.25</slf4j.version>
     <log4j.version>2.8.2</log4j.version>
     <rxjava.version>2.2.8</rxjava.version>