You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicecomb.apache.org by li...@apache.org on 2022/05/13 13:40:16 UTC
[servicecomb-java-chassis] branch master updated: [SCB-2490] Bump mockito version from 1.10.19 to 3.3.3 (#2883)
This is an automated email from the ASF dual-hosted git repository.
liubao pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/servicecomb-java-chassis.git
The following commit(s) were added to refs/heads/master by this push:
new f7d091b9a [SCB-2490] Bump mockito version from 1.10.19 to 3.3.3 (#2883)
f7d091b9a is described below
commit f7d091b9af2686fc2ea24c12e73b88efb257b456
Author: ZhangJian He <sh...@gmail.com>
AuthorDate: Fri May 13 21:40:11 2022 +0800
[SCB-2490] Bump mockito version from 1.10.19 to 3.3.3 (#2883)
---
common/common-access-log/pom.xml | 5 +++++
.../core/TestConfigurationSpringInitializer.java | 6 ++----
dependencies/default/pom.xml | 12 +++++++++---
.../config/client/ApolloClientTest.java | 10 +++++-----
.../foundation/common/utils/TestJvmUtils.java | 6 +++---
.../bizkeeper/TestBizkeeperHandler.java | 6 +++---
.../tracing/zipkin/ZipkinTracingHandlerTest.java | 4 ++--
parents/default/pom.xml | 2 +-
.../registry/lightweight/StoreServiceTest.java | 6 +++---
.../rest/client/http/TestRestClientInvocation.java | 22 +++++++++++-----------
10 files changed, 44 insertions(+), 35 deletions(-)
diff --git a/common/common-access-log/pom.xml b/common/common-access-log/pom.xml
index fa20ae960..34bb8138e 100644
--- a/common/common-access-log/pom.xml
+++ b/common/common-access-log/pom.xml
@@ -41,5 +41,10 @@
<groupId>org.apache.servicecomb</groupId>
<artifactId>common-rest</artifactId>
</dependency>
+ <dependency>
+ <groupId>io.vertx</groupId>
+ <artifactId>vertx-codegen</artifactId>
+ <scope>test</scope>
+ </dependency>
</dependencies>
</project>
\ No newline at end of file
diff --git a/core/src/test/java/org/apache/servicecomb/core/TestConfigurationSpringInitializer.java b/core/src/test/java/org/apache/servicecomb/core/TestConfigurationSpringInitializer.java
index 35a0aca81..d9d8e05b1 100644
--- a/core/src/test/java/org/apache/servicecomb/core/TestConfigurationSpringInitializer.java
+++ b/core/src/test/java/org/apache/servicecomb/core/TestConfigurationSpringInitializer.java
@@ -16,8 +16,6 @@
*/
package org.apache.servicecomb.core;
-import static org.mockito.Matchers.anyString;
-
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -32,7 +30,7 @@ import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
-import org.mockito.Matchers;
+import org.mockito.ArgumentMatchers;
import org.mockito.Mockito;
import org.mockito.stubbing.Answer;
import org.springframework.core.env.CompositePropertySource;
@@ -149,7 +147,7 @@ public class TestConfigurationSpringInitializer {
Assertions.fail("get unexpected property name: " + propertyName);
}
return value;
- }).when(environment).getProperty(anyString(), Matchers.eq(Object.class));
+ }).when(environment).getProperty(ArgumentMatchers.anyString(), ArgumentMatchers.eq(Object.class));
new ConfigurationSpringInitializer().setEnvironment(environment);
diff --git a/dependencies/default/pom.xml b/dependencies/default/pom.xml
index f93a3c56d..924db4cfe 100644
--- a/dependencies/default/pom.xml
+++ b/dependencies/default/pom.xml
@@ -74,13 +74,13 @@
<log4j.version>1.2.17</log4j.version>
<log4j2.version>2.17.2</log4j2.version>
<logback.version>1.2.3</logback.version>
- <mockito.version>1.10.19</mockito.version>
+ <mockito.version>3.3.3</mockito.version>
<mock-server.version>5.13.2</mock-server.version>
<narayana.version>5.3.2.Final</narayana.version>
<netflix-commons.version>0.3.0</netflix-commons.version>
<netty.version>4.1.74.Final</netty.version>
<okhttp3.version>3.14.2</okhttp3.version>
- <powermock.version>1.6.2</powermock.version>
+ <powermock.version>2.0.9</powermock.version>
<maven-model.version>3.8.5</maven-model.version>
<micrometer.version>1.8.5</micrometer.version>
<nacos-client.version>1.1.4</nacos-client.version>
@@ -710,6 +710,12 @@
<version>${mockito.version}</version>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-inline</artifactId>
+ <version>${mockito.version}</version>
+ <scope>test</scope>
+ </dependency>
<dependency>
<groupId>org.mock-server</groupId>
@@ -720,7 +726,7 @@
<dependency>
<groupId>org.powermock</groupId>
- <artifactId>powermock-api-mockito</artifactId>
+ <artifactId>powermock-api-mockito2</artifactId>
<version>${powermock.version}</version>
<scope>test</scope>
</dependency>
diff --git a/dynamic-config/config-apollo/src/test/java/org/apache/servicecomb/config/client/ApolloClientTest.java b/dynamic-config/config-apollo/src/test/java/org/apache/servicecomb/config/client/ApolloClientTest.java
index 774356caf..269050fa6 100644
--- a/dynamic-config/config-apollo/src/test/java/org/apache/servicecomb/config/client/ApolloClientTest.java
+++ b/dynamic-config/config-apollo/src/test/java/org/apache/servicecomb/config/client/ApolloClientTest.java
@@ -27,7 +27,7 @@ import org.apache.servicecomb.config.client.ApolloClient.ConfigRefresh;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
-import org.mockito.Matchers;
+import org.mockito.ArgumentMatchers;
import org.mockito.Mockito;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpMethod;
@@ -52,10 +52,10 @@ public class ApolloClientTest {
ResponseEntity<String> responseEntity = new ResponseEntity<>(
"{\"apollo\":\"mocked\", \"configurations\":{\"timeout\":1000}}", HttpStatus.OK);
Mockito.when(rest.exchange(
- Matchers.anyString(),
- Matchers.any(HttpMethod.class),
- Matchers.<HttpEntity<String>>any(),
- Matchers.<Class<String>>any())).thenReturn(responseEntity);
+ ArgumentMatchers.anyString(),
+ ArgumentMatchers.any(HttpMethod.class),
+ ArgumentMatchers.<HttpEntity<String>>any(),
+ ArgumentMatchers.<Class<String>>any())).thenReturn(responseEntity);
ApolloConfigurationSourceImpl impl = new ApolloConfigurationSourceImpl();
UpdateHandler updateHandler = impl.new UpdateHandler();
ApolloClient apolloClient = new ApolloClient(updateHandler);
diff --git a/foundations/foundation-common/src/test/java/org/apache/servicecomb/foundation/common/utils/TestJvmUtils.java b/foundations/foundation-common/src/test/java/org/apache/servicecomb/foundation/common/utils/TestJvmUtils.java
index 8f6bb1d0d..736c9ec70 100644
--- a/foundations/foundation-common/src/test/java/org/apache/servicecomb/foundation/common/utils/TestJvmUtils.java
+++ b/foundations/foundation-common/src/test/java/org/apache/servicecomb/foundation/common/utils/TestJvmUtils.java
@@ -97,7 +97,7 @@ public class TestJvmUtils {
String content = String.format("Manifest-Version: 1.0\nMain-Class: %s\n", TestJvmUtils.class.getName());
InputStream inputStream = new ByteArrayInputStream(content.getBytes());
- PowerMockito.when(url.openStream()).thenReturn(inputStream);
+ PowerMockito.when(url.openStream()).thenAnswer(invocation -> inputStream);
System.setProperty(JvmUtils.SUN_JAVA_COMMAND, command + " arg");
@@ -115,8 +115,8 @@ public class TestJvmUtils {
String manifestUri = "jar:file:/" + new File(command).getAbsolutePath() + "!/" + JarFile.MANIFEST_NAME;
PowerMockito.whenNew(URL.class).withParameterTypes(String.class)
- .withArguments(manifestUri).thenReturn(url);
- PowerMockito.when(url.openStream()).thenReturn(inputStream);
+ .withArguments(manifestUri).thenAnswer(invocation -> url);
+ PowerMockito.when(url.openStream()).thenAnswer(invocation -> inputStream);
System.setProperty(JvmUtils.SUN_JAVA_COMMAND, command + " arg");
diff --git a/handlers/handler-bizkeeper/src/test/java/org/apache/servicecomb/bizkeeper/TestBizkeeperHandler.java b/handlers/handler-bizkeeper/src/test/java/org/apache/servicecomb/bizkeeper/TestBizkeeperHandler.java
index 39414d536..f263dff1a 100644
--- a/handlers/handler-bizkeeper/src/test/java/org/apache/servicecomb/bizkeeper/TestBizkeeperHandler.java
+++ b/handlers/handler-bizkeeper/src/test/java/org/apache/servicecomb/bizkeeper/TestBizkeeperHandler.java
@@ -158,14 +158,14 @@ public class TestBizkeeperHandler extends BizkeeperHandler {
.thenReturn("testHandleInError");
FallbackPolicy policy = Mockito.mock(FallbackPolicy.class);
Mockito.when(policy.name()).thenReturn("throwException");
- Mockito.when(policy.getFallbackResponse(Mockito.any(Invocation.class), Mockito.any(null)))
+ Mockito.when(policy.getFallbackResponse(Mockito.any(Invocation.class), Mockito.isNull()))
.thenThrow(new RuntimeException());
FallbackPolicyManager.addPolicy(policy);
System.setProperty("servicecomb.fallbackpolicy.groupname.testHandleInError.policy", "throwException");
Mockito.doAnswer(new Answer<Void>() {
@Override
public Void answer(InvocationOnMock invocation) {
- AsyncResponse asyncRsp = invocation.getArgumentAt(0, AsyncResponse.class);
+ AsyncResponse asyncRsp = invocation.getArgument(0, AsyncResponse.class);
asyncRsp.fail(InvocationType.CONSUMER, new Exception("testHandleInError"));
return null;
}
@@ -196,7 +196,7 @@ public class TestBizkeeperHandler extends BizkeeperHandler {
Mockito.doAnswer(new Answer<Void>() {
@Override
public Void answer(InvocationOnMock invocation) {
- AsyncResponse asyncRsp = invocation.getArgumentAt(0, AsyncResponse.class);
+ AsyncResponse asyncRsp = invocation.getArgument(0, AsyncResponse.class);
asyncRsp.success("");
return null;
}
diff --git a/handlers/handler-tracing-zipkin/src/test/java/org/apache/servicecomb/tracing/zipkin/ZipkinTracingHandlerTest.java b/handlers/handler-tracing-zipkin/src/test/java/org/apache/servicecomb/tracing/zipkin/ZipkinTracingHandlerTest.java
index 5358bc8b8..05f3ad1fd 100644
--- a/handlers/handler-tracing-zipkin/src/test/java/org/apache/servicecomb/tracing/zipkin/ZipkinTracingHandlerTest.java
+++ b/handlers/handler-tracing-zipkin/src/test/java/org/apache/servicecomb/tracing/zipkin/ZipkinTracingHandlerTest.java
@@ -19,7 +19,6 @@ package org.apache.servicecomb.tracing.zipkin;
import static com.seanyinx.github.unit.scaffolding.AssertUtils.expectFailing;
import static org.hamcrest.core.Is.is;
-import static org.mockito.Matchers.any;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@@ -31,6 +30,7 @@ import org.hamcrest.MatcherAssert;
import org.junit.Before;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
+import org.mockito.ArgumentMatchers;
import org.mockito.Mockito;
import brave.Span;
@@ -96,7 +96,7 @@ public class ZipkinTracingHandlerTest {
@Test
public void delegatesErrorOnInvocationFailure() throws Exception {
- doThrow(exception).when(invocation).next(any(AsyncResponse.class));
+ doThrow(exception).when(invocation).next(ArgumentMatchers.any(AsyncResponse.class));
try {
tracingHandler.handle(invocation, asyncResponse);
diff --git a/parents/default/pom.xml b/parents/default/pom.xml
index 05c6dfbd2..efc13406e 100644
--- a/parents/default/pom.xml
+++ b/parents/default/pom.xml
@@ -62,7 +62,7 @@
</dependency>
<dependency>
<groupId>org.powermock</groupId>
- <artifactId>powermock-api-mockito</artifactId>
+ <artifactId>powermock-api-mockito2</artifactId>
<scope>test</scope>
</dependency>
<dependency>
diff --git a/service-registry/registry-lightweight/src/test/java/org/apache/servicecomb/registry/lightweight/StoreServiceTest.java b/service-registry/registry-lightweight/src/test/java/org/apache/servicecomb/registry/lightweight/StoreServiceTest.java
index 6da1304ef..f443ed5ea 100644
--- a/service-registry/registry-lightweight/src/test/java/org/apache/servicecomb/registry/lightweight/StoreServiceTest.java
+++ b/service-registry/registry-lightweight/src/test/java/org/apache/servicecomb/registry/lightweight/StoreServiceTest.java
@@ -19,7 +19,6 @@ package org.apache.servicecomb.registry.lightweight;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.catchThrowable;
-import static org.mockito.Matchers.any;
import java.util.concurrent.CompletableFuture;
@@ -31,6 +30,7 @@ import org.apache.servicecomb.registry.lightweight.store.MicroserviceStore;
import org.apache.servicecomb.registry.lightweight.store.Store;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
+import org.mockito.ArgumentMatchers;
import org.mockito.Mockito;
import com.google.common.eventbus.EventBus;
@@ -51,9 +51,9 @@ class StoreServiceTest extends TestBase {
@BeforeEach
void setUp() {
- Mockito.when(discoveryClient.getInfoAsync(any(), any()))
+ Mockito.when(discoveryClient.getInfoAsync(ArgumentMatchers.any(), ArgumentMatchers.any()))
.thenReturn(CompletableFuture.completedFuture(self.getMicroserviceInfo()));
- Mockito.when(discoveryClient.getInstanceAsync(any(), any()))
+ Mockito.when(discoveryClient.getInstanceAsync(ArgumentMatchers.any(), ArgumentMatchers.any()))
.thenReturn(CompletableFuture.completedFuture(self.getInstance()));
}
diff --git a/transports/transport-rest/transport-rest-client/src/test/java/org/apache/servicecomb/transport/rest/client/http/TestRestClientInvocation.java b/transports/transport-rest/transport-rest-client/src/test/java/org/apache/servicecomb/transport/rest/client/http/TestRestClientInvocation.java
index 797b4f7f2..5bfa5286c 100644
--- a/transports/transport-rest/transport-rest-client/src/test/java/org/apache/servicecomb/transport/rest/client/http/TestRestClientInvocation.java
+++ b/transports/transport-rest/transport-rest-client/src/test/java/org/apache/servicecomb/transport/rest/client/http/TestRestClientInvocation.java
@@ -17,7 +17,6 @@
package org.apache.servicecomb.transport.rest.client.http;
-import static org.mockito.Matchers.any;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -55,6 +54,7 @@ import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
+import org.mockito.ArgumentMatchers;
import org.mockito.Mockito;
import com.fasterxml.jackson.core.JsonProcessingException;
@@ -148,18 +148,18 @@ public class TestRestClientInvocation {
when(endpoint.getAddress()).thenReturn(address);
when(invocation.getHandlerContext()).then(answer -> handlerContext);
when(invocation.getInvocationStageTrace()).thenReturn(invocationStageTrace);
- when(httpClient.request(Mockito.any()))
+ when(httpClient.request(ArgumentMatchers.any()))
.thenReturn(Future.succeededFuture(request));
when(request.headers()).thenReturn(headers);
when(request.response()).thenReturn(Future.succeededFuture(httpClientResponse));
doAnswer(a -> {
- headers.add(a.getArgumentAt(0, String.class), a.getArgumentAt(1, String.class));
+ headers.add(a.getArgument(0, String.class), a.getArgument(1, String.class));
return request;
- }).when(request).putHeader(any(), (String) any());
+ }).when(request).putHeader(ArgumentMatchers.any(), ArgumentMatchers.anyString());
doAnswer(a -> {
((Handler<Void>) a.getArguments()[0]).handle(null);
return null;
- }).when(context).runOnContext(any());
+ }).when(context).runOnContext(ArgumentMatchers.any());
}
@Test
@@ -281,7 +281,7 @@ public class TestRestClientInvocation {
doAnswer(a -> {
bodyHandler = (Handler<Buffer>) a.getArguments()[0];
return httpClientResponse;
- }).when(httpClientResponse).bodyHandler(any());
+ }).when(httpClientResponse).bodyHandler(ArgumentMatchers.any());
Buffer buf = Buffer.buffer();
new MockUp<RestClientInvocation>(restClientInvocation) {
@@ -306,13 +306,13 @@ public class TestRestClientInvocation {
{
HttpClientFilter filter = mock(HttpClientFilter.class);
- when(filter.afterReceiveResponse(any(), any())).thenReturn(null);
+ when(filter.afterReceiveResponse(ArgumentMatchers.any(), ArgumentMatchers.any())).thenReturn(null);
when(filter.enabled()).thenReturn(true);
httpClientFilters.add(filter);
}
{
HttpClientFilter filter = mock(HttpClientFilter.class);
- when(filter.afterReceiveResponse(any(), any())).thenReturn(resp);
+ when(filter.afterReceiveResponse(ArgumentMatchers.any(), ArgumentMatchers.any())).thenReturn(resp);
when(filter.enabled()).thenReturn(true);
httpClientFilters.add(filter);
}
@@ -335,7 +335,7 @@ public class TestRestClientInvocation {
{
HttpClientFilter filter = mock(HttpClientFilter.class);
- when(filter.afterReceiveResponse(any(), any())).thenThrow(Error.class);
+ when(filter.afterReceiveResponse(ArgumentMatchers.any(), ArgumentMatchers.any())).thenThrow(Error.class);
when(filter.enabled()).thenReturn(true);
httpClientFilters.add(filter);
}
@@ -354,7 +354,7 @@ public class TestRestClientInvocation {
public void createRequestPath_NoUrlPrefixNoPath() throws Exception {
when(address.getFirst(DefinitionConst.URL_PREFIX)).thenReturn(null);
- when(urlPathBuilder.createRequestPath(any())).thenReturn("/path");
+ when(urlPathBuilder.createRequestPath(ArgumentMatchers.any())).thenReturn("/path");
String path = restClientInvocation.createRequestPath(swaggerRestOperation);
Assertions.assertEquals("/path", path);
@@ -373,7 +373,7 @@ public class TestRestClientInvocation {
public void createRequestPath_haveUrlPrefixNoPath() throws Exception {
when(address.getFirst(DefinitionConst.URL_PREFIX)).thenReturn("/prefix");
- when(urlPathBuilder.createRequestPath(any())).thenReturn("/path");
+ when(urlPathBuilder.createRequestPath(ArgumentMatchers.any())).thenReturn("/path");
String path = restClientInvocation.createRequestPath(swaggerRestOperation);
Assertions.assertEquals("/prefix/path", path);