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 15:36:17 UTC

[httpcomponents-core] 01/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 f8ca8dd4f1df94d75517eecfaf2c54b9c27ee119
Author: Oleg Kalnichevski <ol...@apache.org>
AuthorDate: Sat May 15 18:31:04 2021 +0200

    Upgraded Mockito to version 3.10.0
---
 .../http/impl/io/TestBHttpConnectionBase.java      | 12 ++++-
 .../impl/io/TestDefaultBHttpClientConnection.java  | 22 ++++++---
 .../impl/io/TestDefaultBHttpServerConnection.java  | 22 ++++++---
 .../hc/core5/http/impl/io/TestHttpService.java     | 12 ++++-
 ...tAbstractHttp1StreamDuplexerCapacityWindow.java | 52 ++++++++++++----------
 .../nio/support/classic/TestSharedInputBuffer.java |  8 ++--
 .../support/classic/TestSharedOutputBuffer.java    |  4 +-
 pom.xml                                            |  2 +-
 8 files changed, 86 insertions(+), 48 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 e098c33..2126f0d 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
@@ -42,6 +42,7 @@ import org.apache.hc.core5.http.config.Http1Config;
 import org.apache.hc.core5.http.message.BasicClassicHttpResponse;
 import org.apache.hc.core5.io.CloseMode;
 import org.apache.hc.core5.util.Timeout;
+import org.junit.After;
 import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
@@ -57,12 +58,19 @@ public class TestBHttpConnectionBase {
 
     private BHttpConnectionBase conn;
 
+    private AutoCloseable closeable;
+
     @Before
-    public void setUp() throws Exception {
-        MockitoAnnotations.initMocks(this);
+    public void prepareMocks() {
+        closeable = MockitoAnnotations.openMocks(this);
         conn = new BHttpConnectionBase(Http1Config.DEFAULT, null, null);
     }
 
+    @After
+    public void releaseMocks() throws Exception {
+        closeable.close();
+    }
+
     @Test
     public void testBasics() throws Exception {
         Assert.assertFalse(conn.isOpen());
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 286f949..986e48b 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
@@ -44,6 +44,7 @@ import org.apache.hc.core5.http.impl.DefaultContentLengthStrategy;
 import org.apache.hc.core5.http.io.entity.ByteArrayEntity;
 import org.apache.hc.core5.http.io.entity.StringEntity;
 import org.apache.hc.core5.http.message.BasicClassicHttpRequest;
+import org.junit.After;
 import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
@@ -58,15 +59,22 @@ public class TestDefaultBHttpClientConnection {
 
     private DefaultBHttpClientConnection conn;
 
+    private AutoCloseable closeable;
+
     @Before
-    public void setUp() throws Exception {
-        MockitoAnnotations.initMocks(this);
+    public void prepareMocks() {
+        closeable = MockitoAnnotations.openMocks(this);
         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);
+    }
+
+    @After
+    public void releaseMocks() throws Exception {
+        closeable.close();
     }
 
     @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 0cf8932..5ea892f 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
@@ -43,6 +43,7 @@ import org.apache.hc.core5.http.config.Http1Config;
 import org.apache.hc.core5.http.impl.DefaultContentLengthStrategy;
 import org.apache.hc.core5.http.io.entity.StringEntity;
 import org.apache.hc.core5.http.message.BasicClassicHttpResponse;
+import org.junit.After;
 import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
@@ -57,15 +58,22 @@ public class TestDefaultBHttpServerConnection {
 
     private DefaultBHttpServerConnection conn;
 
+    private AutoCloseable closeable;
+
     @Before
-    public void setUp() throws Exception {
-        MockitoAnnotations.initMocks(this);
+    public void prepareMocks() {
+        closeable = MockitoAnnotations.openMocks(this);
         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);
+    }
+
+    @After
+    public void releaseMocks() throws Exception {
+        closeable.close();
     }
 
     @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 4b75ae6..78d3ce1 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
@@ -49,6 +49,7 @@ import org.apache.hc.core5.http.message.BasicClassicHttpRequest;
 import org.apache.hc.core5.http.message.BasicClassicHttpResponse;
 import org.apache.hc.core5.http.protocol.HttpCoreContext;
 import org.apache.hc.core5.http.protocol.HttpProcessor;
+import org.junit.After;
 import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
@@ -78,9 +79,11 @@ public class TestHttpService {
 
     private HttpService httpservice;
 
+    private AutoCloseable closeable;
+
     @Before
-    public void settup() {
-        MockitoAnnotations.initMocks(this);
+    public void prepareMocks() {
+        closeable = MockitoAnnotations.openMocks(this);
         httpservice = new HttpService(
                 httprocessor,
                 handlerResolver,
@@ -88,6 +91,11 @@ public class TestHttpService {
                 responseFactory);
     }
 
+    @After
+    public void releaseMocks() throws Exception {
+        closeable.close();
+    }
+
     @Test
     public void testInvalidInitialization() throws Exception {
         try {
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>