Skip to content

Commit

Permalink
upgrade mockito to 4.5.1 (#929)
Browse files Browse the repository at this point in the history
What changed?
version upgrade

Why?
1.x version cannot mock final classes
  • Loading branch information
shijiesheng authored Oct 28, 2024
1 parent cecf223 commit dc0f0c4
Show file tree
Hide file tree
Showing 26 changed files with 78 additions and 61 deletions.
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ dependencies {
testCompile group: 'ch.qos.logback', name: 'logback-classic', version: '1.2.3'
testCompile group: 'io.grpc', name: 'grpc-testing', version: '1.54.2'
testImplementation 'io.opentracing:opentracing-mock:0.33.0'
testImplementation group: 'org.mockito', name: 'mockito-core', version: '4.5.1'
}

license {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,7 @@
import java.util.Map;
import java.util.Optional;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.runners.MockitoJUnitRunner;

@RunWith(MockitoJUnitRunner.class)
public class LocalActivityContextPropagationTest {

private static final String LOCAL_ACTIVITY_CP_TASK_LIST = "LOCAL_ACTIVITY_CP_TASK_LIST";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
/**
* Copyright 2012-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* <p>Modifications copyright (C) 2017 Uber Technologies, Inc.
*
* <p>Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file
* except in compliance with the License. A copy of the License is located at
*
* <p>http://aws.amazon.com/apache2.0
*
* <p>or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/
package com.uber.cadence.internal.compatibility;

import com.google.common.collect.ImmutableList;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.mockito.Matchers.any;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doAnswer;

import com.uber.cadence.SignalWithStartWorkflowExecutionAsyncRequest;
Expand Down Expand Up @@ -157,9 +157,10 @@ private void assertTracingHeaders(Header header) {
.toString());
}

@SuppressWarnings("CheckReturnValue")
private <REQ, RES> ArgumentCaptor<REQ> mockRpc(
BiConsumer<REQ, StreamObserver<RES>> method, RES value) {
ArgumentCaptor<REQ> captor = new ArgumentCaptor<>();
ArgumentCaptor<REQ> captor = ArgumentCaptor.forClass(null);
doAnswer(
invocation -> {
@SuppressWarnings("unchecked")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
/**
* Copyright 2012-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* <p>Modifications copyright (C) 2017 Uber Technologies, Inc.
*
* <p>Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file
* except in compliance with the License. A copy of the License is located at
*
* <p>http://aws.amazon.com/apache2.0
*
* <p>or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/
package com.uber.cadence.internal.compatibility;

import com.google.common.collect.ImmutableList;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
/**
* Copyright 2012-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* <p>Modifications copyright (C) 2017 Uber Technologies, Inc.
*
* <p>Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file
* except in compliance with the License. A copy of the License is located at
*
* <p>http://aws.amazon.com/apache2.0
*
* <p>or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/
package com.uber.cadence.internal.compatibility.proto;

import static com.uber.cadence.internal.compatibility.MapperTestUtil.assertMissingFields;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@

import static junit.framework.TestCase.assertEquals;
import static org.junit.Assert.*;
import static org.mockito.Matchers.anyInt;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.*;

import com.uber.cadence.HistoryEvent;
Expand Down Expand Up @@ -211,7 +209,7 @@ public void evictAnyWillInvalidateAnEntryRandomlyFromTheCache() throws Exception
// Wait for reporter
Thread.sleep(600);
verify(reporter, atLeastOnce())
.reportCounter(eq(MetricsType.STICKY_CACHE_TOTAL_FORCED_EVICTION), eq(tags), anyInt());
.reportCounter(eq(MetricsType.STICKY_CACHE_TOTAL_FORCED_EVICTION), eq(tags), anyLong());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import static junit.framework.TestCase.assertEquals;
import static junit.framework.TestCase.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.mockito.Matchers.any;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.Matchers.any;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.eq;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -779,7 +779,7 @@ public void workflowThreadsWillEvictCacheWhenMaxThreadCountIsHit() throws Throwa
// Wait for reporter
Thread.sleep(600);
verify(reporter, atLeastOnce())
.reportCounter(eq(MetricsType.STICKY_CACHE_THREAD_FORCED_EVICTION), eq(tags), anyInt());
.reportCounter(eq(MetricsType.STICKY_CACHE_THREAD_FORCED_EVICTION), eq(tags), anyLong());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.eq;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.mockito.Matchers.any;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
package com.uber.cadence.internal.testing;

import static org.junit.Assert.*;
import static org.mockito.Matchers.anyString;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
package com.uber.cadence.internal.worker;

import static junit.framework.TestCase.*;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.*;

import ch.qos.logback.classic.Level;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package com.uber.cadence.internal.worker;

import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

import com.uber.cadence.client.WorkflowClient;
Expand All @@ -28,11 +29,8 @@
import com.uber.m3.tally.NoopScope;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;

@RunWith(MockitoJUnitRunner.class)
public class WorkerShutDownHandlerTest {

@Mock private WorkflowClient mockClient;
Expand All @@ -41,6 +39,8 @@ public class WorkerShutDownHandlerTest {

@Before
public void setup() {
mockClient = mock(WorkflowClient.class);
mockService = mock(IWorkflowService.class);
WorkflowClientOptions clientOptions =
WorkflowClientOptions.newBuilder().setMetricsScope(new NoopScope()).build();
when(mockClient.getOptions()).thenReturn(clientOptions);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,7 @@

import java.time.Duration;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.runners.MockitoJUnitRunner;

@RunWith(MockitoJUnitRunner.class)
public class PollerAutoScalerTest {

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,7 @@
import java.util.ArrayList;
import java.util.List;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.runners.MockitoJUnitRunner;

@RunWith(MockitoJUnitRunner.class)
public class PollerUsageEstimatorTest {

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,7 @@
import static org.junit.Assert.*;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.runners.MockitoJUnitRunner;

@RunWith(MockitoJUnitRunner.class)
public class RecommenderTest {

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,7 @@
import static org.junit.Assert.*;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.runners.MockitoJUnitRunner;

@RunWith(MockitoJUnitRunner.class)
public class ResizableSemaphoreTest {

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;

public class MigrationIWorkflowServiceTest {

Expand All @@ -38,7 +37,8 @@ public class MigrationIWorkflowServiceTest {

@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
serviceOld = mock(IWorkflowService.class);
serviceNew = mock(IWorkflowService.class);
migrationService =
new MigrationIWorkflowService(serviceOld, "domainOld", serviceNew, "domainNew");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
*/
package com.uber.cadence.testing;

import static org.mockito.Matchers.any;
import static org.mockito.Matchers.argThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.argThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
Expand Down Expand Up @@ -87,15 +87,15 @@ public void testRun_CallReplay_ThrowsException() throws Throwable {
}

private class ScanWorkflowActivityParamsMatcher
extends ArgumentMatcher<ScanWorkflowActivityParams> {
implements ArgumentMatcher<ScanWorkflowActivityParams> {
ScanWorkflowActivityParams params;

public ScanWorkflowActivityParamsMatcher(ScanWorkflowActivityParams params) {
this.params = params;
}

@Override
public boolean matches(Object argument) {
public boolean matches(ScanWorkflowActivityParams argument) {
ScanWorkflowActivityParams newParams = (ScanWorkflowActivityParams) argument;
return params.getDomain().equals(newParams.getDomain())
&& params.getWorkflowQuery().equals(newParams.getWorkflowQuery())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
*/
package com.uber.cadence.worker;

import static org.mockito.Matchers.any;
import static org.mockito.Matchers.argThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.argThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
Expand Down Expand Up @@ -103,15 +103,15 @@ public void testStartShadowingWorkflow_ReceiveExpectedRequest() throws Exception
}

private class StartWorkflowExecutionRequestMatcher
extends ArgumentMatcher<StartWorkflowExecutionRequest> {
implements ArgumentMatcher<StartWorkflowExecutionRequest> {
StartWorkflowExecutionRequest request;

public StartWorkflowExecutionRequestMatcher(StartWorkflowExecutionRequest request) {
this.request = request;
}

@Override
public boolean matches(Object argument) {
public boolean matches(StartWorkflowExecutionRequest argument) {
StartWorkflowExecutionRequest newRequest = (StartWorkflowExecutionRequest) argument;
return request.getDomain().equals(newRequest.getDomain())
&& request.getTaskList().equals(newRequest.getTaskList())
Expand Down
19 changes: 9 additions & 10 deletions src/test/java/com/uber/cadence/worker/StickyWorkerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.mockito.Matchers.anyInt;
import static org.mockito.Matchers.eq;
import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.atLeastOnce;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
Expand Down Expand Up @@ -156,8 +155,8 @@ public void whenStickyIsEnabledThenTheWorkflowIsCachedSignals() throws Exception
.build();
Thread.sleep(600);
verify(reporter, atLeastOnce())
.reportCounter(eq(MetricsType.STICKY_CACHE_HIT), eq(tags), anyInt());
verify(reporter, never()).reportCounter(eq(MetricsType.STICKY_CACHE_MISS), eq(tags), anyInt());
.reportCounter(eq(MetricsType.STICKY_CACHE_HIT), eq(tags), anyLong());
verify(reporter, never()).reportCounter(eq(MetricsType.STICKY_CACHE_MISS), eq(tags), anyLong());

// Finish Workflow
wrapper.close();
Expand Down Expand Up @@ -269,8 +268,8 @@ public void whenStickyIsEnabledThenTheWorkflowIsCachedActivities() throws Except
.put(MetricsTag.TASK_LIST, STICKY_TASK_LIST_METRIC_TAG)
.build();
verify(reporter, atLeastOnce())
.reportCounter(eq(MetricsType.STICKY_CACHE_HIT), eq(tags), anyInt());
verify(reporter, never()).reportCounter(eq(MetricsType.STICKY_CACHE_MISS), eq(tags), anyInt());
.reportCounter(eq(MetricsType.STICKY_CACHE_HIT), eq(tags), anyLong());
verify(reporter, never()).reportCounter(eq(MetricsType.STICKY_CACHE_MISS), eq(tags), anyLong());

// Finish Workflow
wrapper.close();
Expand Down Expand Up @@ -318,8 +317,8 @@ public void whenStickyIsEnabledThenTheWorkflowIsCachedChildWorkflows() throws Ex
.put(MetricsTag.TASK_LIST, STICKY_TASK_LIST_METRIC_TAG)
.build();
verify(reporter, atLeastOnce())
.reportCounter(eq(MetricsType.STICKY_CACHE_HIT), eq(tags), anyInt());
verify(reporter, never()).reportCounter(eq(MetricsType.STICKY_CACHE_MISS), eq(tags), anyInt());
.reportCounter(eq(MetricsType.STICKY_CACHE_HIT), eq(tags), anyLong());
verify(reporter, never()).reportCounter(eq(MetricsType.STICKY_CACHE_MISS), eq(tags), anyLong());
// Finish Workflow
wrapper.close();
}
Expand Down Expand Up @@ -374,8 +373,8 @@ public void whenStickyIsEnabledThenTheWorkflowIsCachedMutableSideEffect() throws
.put(MetricsTag.TASK_LIST, STICKY_TASK_LIST_METRIC_TAG)
.build();
verify(reporter, atLeastOnce())
.reportCounter(eq(MetricsType.STICKY_CACHE_HIT), eq(tags), anyInt());
verify(reporter, never()).reportCounter(eq(MetricsType.STICKY_CACHE_MISS), eq(tags), anyInt());
.reportCounter(eq(MetricsType.STICKY_CACHE_HIT), eq(tags), anyLong());
verify(reporter, never()).reportCounter(eq(MetricsType.STICKY_CACHE_MISS), eq(tags), anyLong());
// Finish Workflow
wrapper.close();
}
Expand Down
2 changes: 0 additions & 2 deletions src/test/java/com/uber/cadence/workflow/MetricsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@

import static com.uber.cadence.testUtils.TestEnvironment.DOMAIN;
import static org.junit.Assert.assertTrue;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.*;

import com.uber.cadence.activity.ActivityOptions;
Expand Down
Loading

0 comments on commit dc0f0c4

Please sign in to comment.