Port to Mockito 5

This commit is contained in:
Marian Koncek 2023-12-12 12:19:38 +01:00
parent e8d8c396b1
commit 90936ce55f
2 changed files with 384 additions and 5 deletions

View File

@ -0,0 +1,374 @@
From 919dd0b1be2ff0bb9532131c18eafcd68d6196d6 Mon Sep 17 00:00:00 2001
From: Marian Koncek <mkoncek@redhat.com>
Date: Tue, 12 Dec 2023 12:13:58 +0100
Subject: [PATCH] Port to Mockito 5
Generated by running:
find -name '*.java' -exec sed -i \
-e 's/org\.mockito\.Matchers/org.mockito.ArgumentMatchers/g' \
-e 's/\([^[:alnum:]]\)Matchers\([^[:alnum:]]\)/\1ArgumentMatchers\2/g' \
-e 's/Mockito\.anyObject()/Mockito\.any()/g' \
{} +
---
.../client/cache/TestAsynchronousValidator.java | 2 +-
.../cache/TestCachedHttpResponseGenerator.java | 4 ++--
.../client/cache/TestHttpCacheJiraNumber1147.java | 14 +++++++-------
.../cache/ehcache/TestEhcacheHttpCacheStorage.java | 4 ++--
.../org/apache/http/client/entity/TestGZip.java | 4 ++--
.../client/protocol/TestRequestAddCookies.java | 4 ++--
.../impl/client/TestIdleConnectionEvictor.java | 4 ++--
.../impl/client/integration/TestSPNegoScheme.java | 10 +++++-----
.../TestPoolingHttpClientConnectionManager.java | 2 +-
.../impl/conn/TestSystemDefaultRoutePlanner.java | 4 ++--
.../http/impl/cookie/TestRFC6265CookieSpec.java | 14 +++++++-------
.../http/impl/execchain/TestConnectionHolder.java | 8 ++++----
.../http/impl/execchain/TestRedirectExec.java | 4 ++--
13 files changed, 39 insertions(+), 39 deletions(-)
diff --git a/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestAsynchronousValidator.java b/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestAsynchronousValidator.java
index 58ecef1..6932fc4 100644
--- a/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestAsynchronousValidator.java
+++ b/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestAsynchronousValidator.java
@@ -26,7 +26,7 @@
*/
package org.apache.http.impl.client.cache;
-import static org.mockito.Matchers.isA;
+import static org.mockito.ArgumentMatchers.isA;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
diff --git a/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestCachedHttpResponseGenerator.java b/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestCachedHttpResponseGenerator.java
index 3fc12f6..84bd347 100644
--- a/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestCachedHttpResponseGenerator.java
+++ b/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestCachedHttpResponseGenerator.java
@@ -26,8 +26,8 @@
*/
package org.apache.http.impl.client.cache;
-import static org.mockito.Matchers.isA;
-import static org.mockito.Matchers.same;
+import static org.mockito.ArgumentMatchers.isA;
+import static org.mockito.ArgumentMatchers.same;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
diff --git a/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestHttpCacheJiraNumber1147.java b/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestHttpCacheJiraNumber1147.java
index ceb8f71..674bccd 100644
--- a/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestHttpCacheJiraNumber1147.java
+++ b/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestHttpCacheJiraNumber1147.java
@@ -26,8 +26,8 @@
*/
package org.apache.http.impl.client.cache;
-import static org.mockito.Matchers.eq;
-import static org.mockito.Matchers.isA;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.ArgumentMatchers.isA;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.reset;
import static org.mockito.Mockito.verify;
@@ -53,7 +53,7 @@ import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
-import org.mockito.Matchers;
+import org.mockito.ArgumentMatchers;
public class TestHttpCacheJiraNumber1147 {
@@ -116,7 +116,7 @@ public class TestHttpCacheJiraNumber1147 {
eq(route),
isA(HttpRequestWrapper.class),
isA(HttpClientContext.class),
- (HttpExecutionAware) Matchers.isNull())).thenReturn(Proxies.enhanceResponse(response));
+ (HttpExecutionAware) ArgumentMatchers.isNull())).thenReturn(Proxies.enhanceResponse(response));
final BasicHttpCache cache = new BasicHttpCache(resourceFactory, httpCacheStorage, cacheConfig);
final ClientExecChain t = createCachingExecChain(backend, cache, cacheConfig);
@@ -129,7 +129,7 @@ public class TestHttpCacheJiraNumber1147 {
eq(route),
isA(HttpRequestWrapper.class),
isA(HttpClientContext.class),
- (HttpExecutionAware) Matchers.isNull());
+ (HttpExecutionAware) ArgumentMatchers.isNull());
removeCache();
@@ -138,7 +138,7 @@ public class TestHttpCacheJiraNumber1147 {
eq(route),
isA(HttpRequestWrapper.class),
isA(HttpClientContext.class),
- (HttpExecutionAware) Matchers.isNull())).thenReturn(Proxies.enhanceResponse(response));
+ (HttpExecutionAware) ArgumentMatchers.isNull())).thenReturn(Proxies.enhanceResponse(response));
final HttpResponse response2 = t.execute(route, get, context, null);
Assert.assertEquals(200, response2.getStatusLine().getStatusCode());
@@ -148,7 +148,7 @@ public class TestHttpCacheJiraNumber1147 {
eq(route),
isA(HttpRequestWrapper.class),
isA(HttpClientContext.class),
- (HttpExecutionAware) Matchers.isNull());
+ (HttpExecutionAware) ArgumentMatchers.isNull());
}
protected ClientExecChain createCachingExecChain(final ClientExecChain backend,
diff --git a/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/ehcache/TestEhcacheHttpCacheStorage.java b/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/ehcache/TestEhcacheHttpCacheStorage.java
index a1366e8..30b40bf 100644
--- a/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/ehcache/TestEhcacheHttpCacheStorage.java
+++ b/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/ehcache/TestEhcacheHttpCacheStorage.java
@@ -26,8 +26,8 @@
*/
package org.apache.http.impl.client.cache.ehcache;
-import static org.mockito.Matchers.isA;
-import static org.mockito.Matchers.same;
+import static org.mockito.ArgumentMatchers.isA;
+import static org.mockito.ArgumentMatchers.same;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
diff --git a/httpclient/src/test/java/org/apache/http/client/entity/TestGZip.java b/httpclient/src/test/java/org/apache/http/client/entity/TestGZip.java
index 516299d..76472c6 100644
--- a/httpclient/src/test/java/org/apache/http/client/entity/TestGZip.java
+++ b/httpclient/src/test/java/org/apache/http/client/entity/TestGZip.java
@@ -41,7 +41,7 @@ import org.apache.http.entity.StringEntity;
import org.apache.http.util.EntityUtils;
import org.junit.Assert;
import org.junit.Test;
-import org.mockito.Matchers;
+import org.mockito.ArgumentMatchers;
import org.mockito.Mockito;
public class TestGZip {
@@ -72,7 +72,7 @@ public class TestGZip {
@Test
public void testCompressionIOExceptionLeavesOutputStreamOpen() throws Exception {
final HttpEntity in = Mockito.mock(HttpEntity.class);
- Mockito.doThrow(new IOException("Ooopsie")).when(in).writeTo(Matchers.<OutputStream>any());
+ Mockito.doThrow(new IOException("Ooopsie")).when(in).writeTo(ArgumentMatchers.<OutputStream>any());
final GzipCompressingEntity gzipe = new GzipCompressingEntity(in);
final OutputStream out = Mockito.mock(OutputStream.class);
try {
diff --git a/httpclient/src/test/java/org/apache/http/client/protocol/TestRequestAddCookies.java b/httpclient/src/test/java/org/apache/http/client/protocol/TestRequestAddCookies.java
index 4854f52..5968542 100644
--- a/httpclient/src/test/java/org/apache/http/client/protocol/TestRequestAddCookies.java
+++ b/httpclient/src/test/java/org/apache/http/client/protocol/TestRequestAddCookies.java
@@ -57,7 +57,7 @@ import org.apache.http.protocol.HttpCoreContext;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
-import org.mockito.Matchers;
+import org.mockito.ArgumentMatchers;
import org.mockito.Mockito;
public class TestRequestAddCookies {
@@ -403,7 +403,7 @@ public class TestRequestAddCookies {
Assert.assertNotNull(headers2);
Assert.assertEquals(0, headers2.length);
- Mockito.verify(this.cookieStore, Mockito.times(1)).clearExpired(Matchers.<Date>any());
+ Mockito.verify(this.cookieStore, Mockito.times(1)).clearExpired(ArgumentMatchers.<Date>any());
}
@Test
diff --git a/httpclient/src/test/java/org/apache/http/impl/client/TestIdleConnectionEvictor.java b/httpclient/src/test/java/org/apache/http/impl/client/TestIdleConnectionEvictor.java
index da0d9bd..07b34da 100644
--- a/httpclient/src/test/java/org/apache/http/impl/client/TestIdleConnectionEvictor.java
+++ b/httpclient/src/test/java/org/apache/http/impl/client/TestIdleConnectionEvictor.java
@@ -32,7 +32,7 @@ import java.util.concurrent.TimeUnit;
import org.apache.http.conn.HttpClientConnectionManager;
import org.junit.Assert;
import org.junit.Test;
-import org.mockito.Matchers;
+import org.mockito.ArgumentMatchers;
import org.mockito.Mockito;
/**
@@ -69,7 +69,7 @@ public class TestIdleConnectionEvictor {
Thread.sleep(1000);
Mockito.verify(cm, Mockito.atLeast(1)).closeExpiredConnections();
- Mockito.verify(cm, Mockito.never()).closeIdleConnections(Matchers.anyLong(), Matchers.<TimeUnit>any());
+ Mockito.verify(cm, Mockito.never()).closeIdleConnections(ArgumentMatchers.anyLong(), ArgumentMatchers.<TimeUnit>any());
Assert.assertTrue(connectionEvictor.isRunning());
diff --git a/httpclient/src/test/java/org/apache/http/impl/client/integration/TestSPNegoScheme.java b/httpclient/src/test/java/org/apache/http/impl/client/integration/TestSPNegoScheme.java
index 31799cb..91806c4 100644
--- a/httpclient/src/test/java/org/apache/http/impl/client/integration/TestSPNegoScheme.java
+++ b/httpclient/src/test/java/org/apache/http/impl/client/integration/TestSPNegoScheme.java
@@ -59,7 +59,7 @@ import org.ietf.jgss.GSSName;
import org.ietf.jgss.Oid;
import org.junit.Assert;
import org.junit.Test;
-import org.mockito.Matchers;
+import org.mockito.ArgumentMatchers;
import org.mockito.Mockito;
/**
@@ -98,14 +98,14 @@ public class TestSPNegoScheme extends LocalServerTestBase {
NegotiateSchemeWithMockGssManager() throws Exception {
super(true);
Mockito.when(context.initSecContext(
- Matchers.any(byte[].class), Matchers.anyInt(), Matchers.anyInt()))
+ ArgumentMatchers.any(byte[].class), ArgumentMatchers.anyInt(), ArgumentMatchers.anyInt()))
.thenReturn("12345678".getBytes());
Mockito.when(manager.createName(
- Matchers.any(String.class), Matchers.any(Oid.class)))
+ ArgumentMatchers.any(String.class), ArgumentMatchers.any(Oid.class)))
.thenReturn(name);
Mockito.when(manager.createContext(
- Matchers.any(GSSName.class), Matchers.any(Oid.class),
- Matchers.any(GSSCredential.class), Matchers.anyInt()))
+ ArgumentMatchers.any(GSSName.class), ArgumentMatchers.any(Oid.class),
+ ArgumentMatchers.any(GSSCredential.class), ArgumentMatchers.anyInt()))
.thenReturn(context);
}
diff --git a/httpclient/src/test/java/org/apache/http/impl/conn/TestPoolingHttpClientConnectionManager.java b/httpclient/src/test/java/org/apache/http/impl/conn/TestPoolingHttpClientConnectionManager.java
index 51bc2ef..02c375b 100644
--- a/httpclient/src/test/java/org/apache/http/impl/conn/TestPoolingHttpClientConnectionManager.java
+++ b/httpclient/src/test/java/org/apache/http/impl/conn/TestPoolingHttpClientConnectionManager.java
@@ -226,7 +226,7 @@ public class TestPoolingHttpClientConnectionManager {
mgr.releaseConnection(conn1, "some state", 0, TimeUnit.MILLISECONDS);
Mockito.verify(pool).release(entry, false);
- Mockito.verify(entry, Mockito.never()).setState(Mockito.anyObject());
+ Mockito.verify(entry, Mockito.never()).setState(Mockito.any());
Mockito.verify(entry, Mockito.never()).updateExpiry(Mockito.anyLong(), Mockito.eq(TimeUnit.MILLISECONDS));
}
diff --git a/httpclient/src/test/java/org/apache/http/impl/conn/TestSystemDefaultRoutePlanner.java b/httpclient/src/test/java/org/apache/http/impl/conn/TestSystemDefaultRoutePlanner.java
index 38920ba..690f2b5 100644
--- a/httpclient/src/test/java/org/apache/http/impl/conn/TestSystemDefaultRoutePlanner.java
+++ b/httpclient/src/test/java/org/apache/http/impl/conn/TestSystemDefaultRoutePlanner.java
@@ -46,7 +46,7 @@ import org.apache.http.protocol.HttpContext;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
-import org.mockito.Matchers;
+import org.mockito.ArgumentMatchers;
import org.mockito.Mockito;
/**
@@ -77,7 +77,7 @@ public class TestSystemDefaultRoutePlanner {
Assert.assertEquals(target, route.getTargetHost());
Assert.assertEquals(1, route.getHopCount());
Assert.assertFalse(route.isSecure());
- Mockito.verify(schemePortResolver, Mockito.never()).resolve(Matchers.<HttpHost>any());
+ Mockito.verify(schemePortResolver, Mockito.never()).resolve(ArgumentMatchers.<HttpHost>any());
}
@Test
diff --git a/httpclient/src/test/java/org/apache/http/impl/cookie/TestRFC6265CookieSpec.java b/httpclient/src/test/java/org/apache/http/impl/cookie/TestRFC6265CookieSpec.java
index 35753fd..bdf4ecd 100644
--- a/httpclient/src/test/java/org/apache/http/impl/cookie/TestRFC6265CookieSpec.java
+++ b/httpclient/src/test/java/org/apache/http/impl/cookie/TestRFC6265CookieSpec.java
@@ -40,7 +40,7 @@ import org.apache.http.cookie.SetCookie;
import org.apache.http.message.BasicHeader;
import org.junit.Assert;
import org.junit.Test;
-import org.mockito.Matchers;
+import org.mockito.ArgumentMatchers;
import org.mockito.Mockito;
public class TestRFC6265CookieSpec {
@@ -69,8 +69,8 @@ public class TestRFC6265CookieSpec {
Assert.assertEquals("stuff", clientCookie.getAttribute("this"));
Assert.assertEquals(null, clientCookie.getAttribute("that"));
- Mockito.verify(h1).parse(Matchers.<SetCookie>any(), Matchers.eq("stuff"));
- Mockito.verify(h2, Mockito.never()).parse(Matchers.<SetCookie>any(), Matchers.anyString());
+ Mockito.verify(h1).parse(ArgumentMatchers.<SetCookie>any(), ArgumentMatchers.eq("stuff"));
+ Mockito.verify(h2, Mockito.never()).parse(ArgumentMatchers.<SetCookie>any(), ArgumentMatchers.anyString());
}
@Test
@@ -316,8 +316,8 @@ public class TestRFC6265CookieSpec {
final CookieOrigin origin = new CookieOrigin("host", 80, "/path/", true);
cookiespec.parse(header, origin);
- Mockito.verify(h1).parse(Matchers.<SetCookie>any(), Matchers.eq("morestuff"));
- Mockito.verify(h1, Mockito.times(1)).parse(Matchers.<SetCookie>any(), Matchers.anyString());
+ Mockito.verify(h1).parse(ArgumentMatchers.<SetCookie>any(), ArgumentMatchers.eq("morestuff"));
+ Mockito.verify(h1, Mockito.times(1)).parse(ArgumentMatchers.<SetCookie>any(), ArgumentMatchers.anyString());
}
@Test
@@ -333,8 +333,8 @@ public class TestRFC6265CookieSpec {
final CookieOrigin origin = new CookieOrigin("host", 80, "/path/", true);
cookiespec.parse(header, origin);
- Mockito.verify(h1, Mockito.never()).parse(Matchers.<SetCookie>any(), Matchers.anyString());
- Mockito.verify(h2).parse(Matchers.<SetCookie>any(), Matchers.eq("otherstuff"));
+ Mockito.verify(h1, Mockito.never()).parse(ArgumentMatchers.<SetCookie>any(), ArgumentMatchers.anyString());
+ Mockito.verify(h2).parse(ArgumentMatchers.<SetCookie>any(), ArgumentMatchers.eq("otherstuff"));
}
}
diff --git a/httpclient/src/test/java/org/apache/http/impl/execchain/TestConnectionHolder.java b/httpclient/src/test/java/org/apache/http/impl/execchain/TestConnectionHolder.java
index a908141..8f1c8f7 100644
--- a/httpclient/src/test/java/org/apache/http/impl/execchain/TestConnectionHolder.java
+++ b/httpclient/src/test/java/org/apache/http/impl/execchain/TestConnectionHolder.java
@@ -67,7 +67,7 @@ public class TestConnectionHolder {
Mockito.verify(conn, Mockito.times(1)).shutdown();
Mockito.verify(mgr, Mockito.times(1)).releaseConnection(
Mockito.<HttpClientConnection>any(),
- Mockito.anyObject(),
+ Mockito.any(),
Mockito.anyLong(),
Mockito.<TimeUnit>any());
}
@@ -98,7 +98,7 @@ public class TestConnectionHolder {
Mockito.verify(conn, Mockito.times(1)).shutdown();
Mockito.verify(mgr, Mockito.times(1)).releaseConnection(
Mockito.<HttpClientConnection>any(),
- Mockito.anyObject(),
+ Mockito.any(),
Mockito.anyLong(),
Mockito.<TimeUnit>any());
}
@@ -120,7 +120,7 @@ public class TestConnectionHolder {
Mockito.verify(mgr, Mockito.times(1)).releaseConnection(
Mockito.<HttpClientConnection>any(),
- Mockito.anyObject(),
+ Mockito.any(),
Mockito.anyLong(),
Mockito.<TimeUnit>any());
}
@@ -142,7 +142,7 @@ public class TestConnectionHolder {
Mockito.verify(mgr, Mockito.times(1)).releaseConnection(
Mockito.<HttpClientConnection>any(),
- Mockito.anyObject(),
+ Mockito.any(),
Mockito.anyLong(),
Mockito.<TimeUnit>any());
}
diff --git a/httpclient/src/test/java/org/apache/http/impl/execchain/TestRedirectExec.java b/httpclient/src/test/java/org/apache/http/impl/execchain/TestRedirectExec.java
index 78b1af4..da34722 100644
--- a/httpclient/src/test/java/org/apache/http/impl/execchain/TestRedirectExec.java
+++ b/httpclient/src/test/java/org/apache/http/impl/execchain/TestRedirectExec.java
@@ -55,7 +55,7 @@ import org.junit.Before;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
import org.mockito.ArgumentMatcher;
-import org.mockito.Matchers;
+import org.mockito.ArgumentMatchers;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
@@ -363,7 +363,7 @@ public class TestRedirectExec {
}
static HttpRequestWrapper same(final HttpRequest original) {
- return Matchers.argThat(new HttpRequestWrapperMatcher(original));
+ return ArgumentMatchers.argThat(new HttpRequestWrapperMatcher(original));
}
}
--
2.43.0

View File

@ -3,15 +3,16 @@
Name: httpcomponents-client Name: httpcomponents-client
Summary: HTTP agent implementation based on httpcomponents HttpCore Summary: HTTP agent implementation based on httpcomponents HttpCore
Version: 4.5.14 Version: 4.5.14
Release: 3%{?dist} Release: 4%{?dist}
License: Apache-2.0 License: Apache-2.0
URL: http://hc.apache.org/ URL: http://hc.apache.org/
Source0: https://repo1.maven.org/maven2/org/apache/httpcomponents/httpcomponents-client/%{version}/httpcomponents-client-%{version}-source-release.zip Source0: https://repo1.maven.org/maven2/org/apache/httpcomponents/httpcomponents-client/%{version}/httpcomponents-client-%{version}-source-release.zip
BuildArch: noarch BuildArch: noarch
ExclusiveArch: %{java_arches} noarch ExclusiveArch: %{java_arches} noarch
Patch0: 0001-Use-system-copy-of-effective_tld_names.dat.patch Patch1: 0001-Use-system-copy-of-effective_tld_names.dat.patch
Patch1: 0002-Port-to-mockito-2.patch Patch2: 0002-Port-to-mockito-2.patch
Patch3: 0003-Port-to-Mockito-5.patch
%if %{with bootstrap} %if %{with bootstrap}
BuildRequires: javapackages-bootstrap BuildRequires: javapackages-bootstrap
@ -44,8 +45,9 @@ encouraged to upgrade.
%prep %prep
%setup -q -n %{name}-%{version} %setup -q -n %{name}-%{version}
%patch0 -p1 %patch 1 -p1
%patch1 -p1 %patch 2 -p1
%patch 3 -p1
%mvn_package :::tests: __noinstall %mvn_package :::tests: __noinstall
@ -125,6 +127,9 @@ rm httpclient/src/test/java/org/apache/http/client/config/TestRequestConfig.java
%doc README.txt RELEASE_NOTES.txt %doc README.txt RELEASE_NOTES.txt
%changelog %changelog
* Tue Dec 12 2023 Marian Koncek <mkoncek@redhat.com> - 4.5.14-4
- Port to Mockito 5
* Wed Sep 20 2023 Mikolaj Izdebski <mizdebsk@redhat.com> - 4.5.14-3 * Wed Sep 20 2023 Mikolaj Izdebski <mizdebsk@redhat.com> - 4.5.14-3
- Rebuild to regenerate auto-Requires on java - Rebuild to regenerate auto-Requires on java