Upgraded Mockito to version 3.10.0

This commit is contained in:
Oleg Kalnichevski 2021-05-24 14:43:08 +02:00
parent e02467e363
commit 2072651983
10 changed files with 32 additions and 62 deletions

View File

@ -63,13 +63,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.Mock;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
import org.mockito.junit.MockitoJUnitRunner;
import org.mockito.stubbing.Answer;
@SuppressWarnings({"boxing","static-access"}) // test code
@RunWith(MockitoJUnitRunner.class)
public class TestConnectExec {
@Mock
@ -89,7 +91,6 @@ public class TestConnectExec {
@Before
public void setup() throws Exception {
MockitoAnnotations.initMocks(this);
exec = new ConnectExec(reuseStrategy, proxyHttpProcessor, proxyAuthStrategy);
target = new HttpHost("foo", 80);
proxy = new HttpHost("bar", 8888);
@ -107,14 +108,6 @@ public class TestConnectExec {
context.setUserToken("Blah");
Mockito.when(execRuntime.isEndpointAcquired()).thenReturn(false);
Mockito.when(execRuntime.execute(
Mockito.eq("test"),
Mockito.same(request),
Mockito.<HttpClientContext>any())).thenReturn(response);
Mockito.when(reuseStrategy.keepAlive(
Mockito.same(request),
Mockito.same(response),
Mockito.<HttpClientContext>any())).thenReturn(false);
final ExecChain.Scope scope = new ExecChain.Scope("test", route, request, execRuntime, context);
exec.execute(request, scope, execChain);
Mockito.verify(execRuntime).acquireEndpoint("test", route, "Blah", context);

View File

@ -52,11 +52,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.Mock;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
import org.mockito.junit.MockitoJUnitRunner;
@SuppressWarnings({"boxing","static-access"}) // test code
@RunWith(MockitoJUnitRunner.class)
public class TestHttpRequestRetryExec {
@Mock
@ -71,7 +73,6 @@ public class TestHttpRequestRetryExec {
@Before
public void setup() throws Exception {
MockitoAnnotations.initMocks(this);
retryExec = new HttpRequestRetryExec(retryStrategy);
target = new HttpHost("localhost", 80);
}
@ -207,10 +208,6 @@ public class TestHttpRequestRetryExec {
Mockito.when(chain.proceed(
Mockito.<ClassicHttpRequest>any(),
Mockito.<ExecChain.Scope>any())).thenReturn(response);
Mockito.when(retryStrategy.retryRequest(
Mockito.<HttpResponse>any(),
Mockito.anyInt(),
Mockito.<HttpContext>any())).thenReturn(Boolean.TRUE, Boolean.FALSE);
final ExecChain.Scope scope = new ExecChain.Scope("test", route, request, endpoint, context);
final ClassicHttpResponse finalResponse = retryExec.execute(request, scope, chain);
@ -303,11 +300,6 @@ public class TestHttpRequestRetryExec {
req.getEntity().writeTo(new ByteArrayOutputStream());
throw new IOException("Ka-boom");
});
Mockito.when(retryStrategy.retryRequest(
Mockito.<HttpRequest>any(),
Mockito.<IOException>any(),
Mockito.eq(1),
Mockito.<HttpContext>any())).thenReturn(Boolean.TRUE);
final ExecChain.Scope scope = new ExecChain.Scope("test", route, originalRequest, endpoint, context);
final ClassicHttpRequest request = ClassicRequestBuilder.copy(originalRequest).build();
try {

View File

@ -47,12 +47,14 @@ 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.Mock;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
import org.mockito.junit.MockitoJUnitRunner;
import org.slf4j.Logger;
@SuppressWarnings({"static-access"}) // test code
@RunWith(MockitoJUnitRunner.class)
public class TestInternalExecRuntime {
@Mock
@ -73,7 +75,6 @@ public class TestInternalExecRuntime {
@Before
public void setup() {
MockitoAnnotations.initMocks(this);
route = new HttpRoute(new HttpHost("host", 80));
execRuntime = new InternalExecRuntime(log, mgr, requestExecutor, cancellableDependency);
}

View File

@ -51,14 +51,16 @@ import org.apache.hc.core5.http.impl.io.HttpRequestExecutor;
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;
/**
* Simple tests for {@link InternalHttpClient}.
*/
@SuppressWarnings({"static-access"}) // test code
@RunWith(MockitoJUnitRunner.class)
public class TestInternalHttpClient {
@Mock
@ -88,7 +90,6 @@ public class TestInternalHttpClient {
@Before
public void setup() throws Exception {
MockitoAnnotations.initMocks(this);
client = new InternalHttpClient(connManager, requestExecutor, new ExecChainElement(execChain, null), routePlanner,
cookieSpecRegistry, authSchemeRegistry, cookieStore, credentialsProvider,
defaultConfig, Arrays.asList(closeable1, closeable2));

View File

@ -50,12 +50,14 @@ import org.apache.hc.core5.util.TimeValue;
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;
import org.mockito.stubbing.Answer;
@SuppressWarnings({"boxing","static-access"}) // test code
@RunWith(MockitoJUnitRunner.class)
public class TestMainClientExec {
@Mock
@ -74,7 +76,6 @@ public class TestMainClientExec {
@Before
public void setup() throws Exception {
MockitoAnnotations.initMocks(this);
mainClientExec = new MainClientExec(connectionManager, reuseStrategy, keepAliveStrategy, userTokenHandler);
target = new HttpHost("foo", 80);
}
@ -89,7 +90,6 @@ public class TestMainClientExec {
.setStream(new ByteArrayInputStream(new byte[]{}))
.build());
Mockito.when(endpoint.isEndpointAcquired()).thenReturn(false);
Mockito.when(endpoint.execute(
Mockito.anyString(),
Mockito.same(request),
@ -118,7 +118,6 @@ public class TestMainClientExec {
final ClassicHttpResponse response = new BasicClassicHttpResponse(200, "OK");
response.setEntity(null);
Mockito.when(endpoint.isEndpointAcquired()).thenReturn(false);
Mockito.when(endpoint.execute(
Mockito.anyString(),
Mockito.same(request),
@ -151,8 +150,6 @@ public class TestMainClientExec {
.build());
final ConnectionState connectionState = new ConnectionState();
Mockito.doAnswer(connectionState.connectAnswer()).when(endpoint).connectEndpoint(Mockito.<HttpClientContext>any());
Mockito.when(endpoint.isEndpointConnected()).thenAnswer(connectionState.isConnectedAnswer());
Mockito.when(endpoint.execute(
Mockito.anyString(),
Mockito.same(request),
@ -183,9 +180,6 @@ public class TestMainClientExec {
final ClassicHttpRequest request = new HttpGet("http://bar/test");
final ClassicHttpResponse response = new BasicClassicHttpResponse(200, "OK");
final ConnectionState connectionState = new ConnectionState();
Mockito.doAnswer(connectionState.connectAnswer()).when(endpoint).connectEndpoint(Mockito.<HttpClientContext>any());
Mockito.when(endpoint.isEndpointConnected()).thenAnswer(connectionState.isConnectedAnswer());
Mockito.when(endpoint.execute(
Mockito.anyString(),
Mockito.same(request),
@ -220,8 +214,6 @@ public class TestMainClientExec {
.build());
final ConnectionState connectionState = new ConnectionState();
Mockito.doAnswer(connectionState.connectAnswer()).when(endpoint).connectEndpoint(Mockito.<HttpClientContext>any());
Mockito.when(endpoint.isEndpointConnected()).thenAnswer(connectionState.isConnectedAnswer());
Mockito.when(endpoint.execute(
Mockito.anyString(),
Mockito.same(request),

View File

@ -67,12 +67,14 @@ 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.Mock;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
import org.mockito.junit.MockitoJUnitRunner;
import org.mockito.stubbing.Answer;
@SuppressWarnings({"static-access"}) // test code
@RunWith(MockitoJUnitRunner.class)
public class TestProtocolExec {
@Mock
@ -92,7 +94,6 @@ public class TestProtocolExec {
@Before
public void setup() throws Exception {
MockitoAnnotations.initMocks(this);
protocolExec = new ProtocolExec(httpProcessor, targetAuthStrategy, proxyAuthStrategy);
target = new HttpHost("foo", 80);
proxy = new HttpHost("bar", 8888);
@ -323,11 +324,6 @@ public class TestProtocolExec {
return response1;
});
Mockito.when(targetAuthStrategy.select(
Mockito.eq(ChallengeType.TARGET),
Mockito.<Map<String, AuthChallenge>>any(),
Mockito.<HttpClientContext>any())).thenReturn(Collections.<AuthScheme>singletonList(new BasicScheme()));
final ExecChain.Scope scope = new ExecChain.Scope("test", route, request, execRuntime, context);
final ClassicHttpResponse response = protocolExec.execute(request, scope, chain);
Assert.assertEquals(401, response.getCode());

View File

@ -27,6 +27,10 @@
package org.apache.hc.client5.http.impl.classic;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.util.List;
import org.apache.hc.client5.http.classic.ExecRuntime;
import org.apache.hc.core5.function.Supplier;
import org.apache.hc.core5.http.ClassicHttpResponse;
@ -38,15 +42,13 @@ import org.apache.hc.core5.http.io.SessionInputBuffer;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.util.List;
import org.mockito.junit.MockitoJUnitRunner;
@RunWith(MockitoJUnitRunner.class)
public class TestResponseEntityProxy {
@Mock
@ -58,7 +60,6 @@ public class TestResponseEntityProxy {
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
Mockito.when(entity.isStreaming()).thenReturn(Boolean.TRUE);
Mockito.when(response.getEntity()).thenReturn(entity);
}

View File

@ -51,11 +51,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.Mock;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
import org.mockito.junit.MockitoJUnitRunner;
@SuppressWarnings({"boxing","static-access"}) // test code
@RunWith(MockitoJUnitRunner.class)
public class TestBasicHttpClientConnectionManager {
@Mock
@ -79,7 +81,6 @@ public class TestBasicHttpClientConnectionManager {
@Before
public void setup() throws Exception {
MockitoAnnotations.initMocks(this);
mgr = new BasicHttpClientConnectionManager(
socketFactoryRegistry, connFactory, schemePortResolver, dnsResolver);
}

View File

@ -56,14 +56,16 @@ 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.Mock;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
import org.mockito.junit.MockitoJUnitRunner;
/**
* {@link PoolingHttpClientConnectionManager} tests.
*/
@SuppressWarnings({"boxing","static-access","resource"}) // test code
@RunWith(MockitoJUnitRunner.class)
public class TestPoolingHttpClientConnectionManager {
@Mock
@ -88,7 +90,6 @@ public class TestPoolingHttpClientConnectionManager {
@Before
public void setup() throws Exception {
MockitoAnnotations.initMocks(this);
mgr = new PoolingHttpClientConnectionManager(
new DefaultHttpClientConnectionOperator(socketFactoryRegistry, schemePortResolver, dnsResolver), pool, null);
}
@ -102,9 +103,6 @@ public class TestPoolingHttpClientConnectionManager {
entry.assignConnection(conn);
Mockito.when(future.isCancelled()).thenReturn(Boolean.FALSE);
Mockito.when(socketFactoryRegistry.lookup("http")).thenReturn(plainSocketFactory);
Mockito.when(schemePortResolver.resolve(target)).thenReturn(80);
Mockito.when(plainSocketFactory.createSocket(Mockito.<HttpContext>any())).thenReturn(socket);
Mockito.when(conn.isOpen()).thenReturn(true);
Mockito.when(conn.isConsistent()).thenReturn(true);
@ -135,11 +133,7 @@ public class TestPoolingHttpClientConnectionManager {
final PoolEntry<HttpRoute, ManagedHttpClientConnection> entry = new PoolEntry<>(route, TimeValue.NEG_ONE_MILLISECOND);
Mockito.when(future.isCancelled()).thenReturn(Boolean.FALSE);
Mockito.when(socketFactoryRegistry.lookup("http")).thenReturn(plainSocketFactory);
Mockito.when(schemePortResolver.resolve(target)).thenReturn(80);
Mockito.when(plainSocketFactory.createSocket(Mockito.<HttpContext>any())).thenReturn(socket);
Mockito.when(conn.isOpen()).thenReturn(true);
Mockito.when(future.isCancelled()).thenReturn(false);
Mockito.when(future.get(1, TimeUnit.SECONDS)).thenReturn(entry);
Mockito.when(pool.lease(
@ -185,7 +179,6 @@ public class TestPoolingHttpClientConnectionManager {
final HttpHost target = new HttpHost("localhost", 80);
final HttpRoute route = new HttpRoute(target);
Mockito.when(future.isCancelled()).thenReturn(Boolean.TRUE);
Mockito.when(future.get(1, TimeUnit.SECONDS)).thenThrow(new TimeoutException());
Mockito.when(pool.lease(
Mockito.eq(route),

View File

@ -71,7 +71,7 @@
<slf4j.version>1.7.25</slf4j.version>
<junit.version>4.12</junit.version>
<easymock.version>3.6</easymock.version>
<mockito.version>2.23.0</mockito.version>
<mockito.version>3.10.0</mockito.version>
<jna.version>5.2.0</jna.version>
<hc.stylecheck.version>1</hc.stylecheck.version>
<rxjava.version>2.2.7</rxjava.version>