Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on May 8, 2026. It is now read-only.
Merged
4 changes: 2 additions & 2 deletions google-cloud-firestore/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,8 @@
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>1.10.19</version>
<artifactId>mockito-core</artifactId>
<version>4.11.0</version>
<scope>test</scope>
</dependency>
<!-- Need testing utility classes for generated gRPC clients tests -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import org.mockito.junit.MockitoJUnitRunner;

@RunWith(MockitoJUnitRunner.class)
public class AggregateQuerySnapshotTest {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import org.mockito.junit.MockitoJUnitRunner;

@RunWith(MockitoJUnitRunner.class)
public class AggregateQueryTest {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.*;

import com.google.api.core.ApiFuture;
import com.google.api.core.ApiFutures;
Expand Down Expand Up @@ -65,11 +64,11 @@
import org.junit.rules.Timeout;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.ArgumentMatchers;
import org.mockito.Captor;
import org.mockito.Matchers;
import org.mockito.Mockito;
import org.mockito.Spy;
import org.mockito.runners.MockitoJUnitRunner;
import org.mockito.junit.MockitoJUnitRunner;

@RunWith(MockitoJUnitRunner.class)
public class BulkWriterTest {
Expand Down Expand Up @@ -153,7 +152,7 @@ public static ApiFuture<BatchWriteResponse> mergeResponses(

@Before
public void before() {
doReturn(immediateExecutor).when(firestoreRpc).getExecutor();
lenient().doReturn(immediateExecutor).when(firestoreRpc).getExecutor();
testExecutor = Executors.newSingleThreadScheduledExecutor();

final ScheduledExecutorService timeoutExecutor =
Expand Down Expand Up @@ -1011,7 +1010,7 @@ public void flushSucceedsEvenIfBulkCommitFails() throws Exception {
.when(firestoreMock)
.sendRequest(
batchWriteCapture.capture(),
Matchers.<UnaryCallable<BatchWriteRequest, BatchWriteResponse>>any());
ArgumentMatchers.<UnaryCallable<BatchWriteRequest, BatchWriteResponse>>any());
bulkWriter.set(doc1, LocalFirestoreHelper.SINGLE_FIELD_MAP);
bulkWriter.set(doc2, LocalFirestoreHelper.SINGLE_FIELD_MAP);
bulkWriter.flush().get();
Expand All @@ -1023,7 +1022,7 @@ public void closeSucceedsEvenIfBulkCommitFails() throws Exception {
.when(firestoreMock)
.sendRequest(
batchWriteCapture.capture(),
Matchers.<UnaryCallable<BatchWriteRequest, BatchWriteResponse>>any());
ArgumentMatchers.<UnaryCallable<BatchWriteRequest, BatchWriteResponse>>any());
bulkWriter.set(doc1, LocalFirestoreHelper.SINGLE_FIELD_MAP);
bulkWriter.set(doc2, LocalFirestoreHelper.SINGLE_FIELD_MAP);
bulkWriter.close();
Expand All @@ -1035,7 +1034,7 @@ public void individualWritesErrorIfBulkCommitFails() throws Exception {
.when(firestoreMock)
.sendRequest(
batchWriteCapture.capture(),
Matchers.<UnaryCallable<BatchWriteRequest, BatchWriteResponse>>any());
ArgumentMatchers.<UnaryCallable<BatchWriteRequest, BatchWriteResponse>>any());
int opCount = 0;
ApiFuture<WriteResult> result1 = bulkWriter.set(doc1, LocalFirestoreHelper.SINGLE_FIELD_MAP);
ApiFuture<WriteResult> result2 = bulkWriter.set(doc2, LocalFirestoreHelper.SINGLE_FIELD_MAP);
Expand All @@ -1058,7 +1057,7 @@ public void individualWritesErrorIfBulkCommitFailsWithNonFirestoreException() th
.when(firestoreMock)
.sendRequest(
batchWriteCapture.capture(),
Matchers.<UnaryCallable<BatchWriteRequest, BatchWriteResponse>>any());
ArgumentMatchers.<UnaryCallable<BatchWriteRequest, BatchWriteResponse>>any());
int opCount = 0;
ApiFuture<WriteResult> result1 = bulkWriter.set(doc1, LocalFirestoreHelper.SINGLE_FIELD_MAP);
ApiFuture<WriteResult> result2 = bulkWriter.set(doc2, LocalFirestoreHelper.SINGLE_FIELD_MAP);
Expand Down Expand Up @@ -1086,7 +1085,7 @@ public void retriesWritesWhenBatchWriteFailsWithRetryableError() throws Exceptio
.when(firestoreMock)
.sendRequest(
batchWriteCapture.capture(),
Matchers.<UnaryCallable<BatchWriteRequest, BatchWriteResponse>>any());
ArgumentMatchers.<UnaryCallable<BatchWriteRequest, BatchWriteResponse>>any());

ApiFuture<WriteResult> result = bulkWriter.set(doc1, LocalFirestoreHelper.SINGLE_FIELD_MAP);
bulkWriter.close();
Expand Down Expand Up @@ -1125,7 +1124,7 @@ public ScheduledFuture<?> schedule(Runnable command, long delay, TimeUnit unit)
.when(firestoreMock)
.sendRequest(
batchWriteCapture.capture(),
Matchers.<UnaryCallable<BatchWriteRequest, BatchWriteResponse>>any());
ArgumentMatchers.<UnaryCallable<BatchWriteRequest, BatchWriteResponse>>any());

bulkWriter =
firestoreMock.bulkWriter(BulkWriterOptions.builder().setExecutor(timeoutExecutor).build());
Expand Down Expand Up @@ -1175,7 +1174,7 @@ public ScheduledFuture<?> schedule(Runnable command, long delay, TimeUnit unit)
.when(firestoreMock)
.sendRequest(
batchWriteCapture.capture(),
Matchers.<UnaryCallable<BatchWriteRequest, BatchWriteResponse>>any());
ArgumentMatchers.<UnaryCallable<BatchWriteRequest, BatchWriteResponse>>any());

bulkWriter =
firestoreMock.bulkWriter(BulkWriterOptions.builder().setExecutor(timeoutExecutor).build());
Expand Down Expand Up @@ -1325,7 +1324,8 @@ public void cannotSetThrottlingOptionsWithThrottlingDisabled() throws Exception
} catch (Exception e) {
assertEquals(
e.getMessage(),
"Cannot set 'initialOpsPerSecond' or 'maxOpsPerSecond' when 'throttlingEnabled' is set to false.");
"Cannot set 'initialOpsPerSecond' or 'maxOpsPerSecond' when 'throttlingEnabled' is set to"
+ " false.");
}

try {
Expand All @@ -1335,7 +1335,8 @@ public void cannotSetThrottlingOptionsWithThrottlingDisabled() throws Exception
} catch (Exception e) {
assertEquals(
e.getMessage(),
"Cannot set 'initialOpsPerSecond' or 'maxOpsPerSecond' when 'throttlingEnabled' is set to false.");
"Cannot set 'initialOpsPerSecond' or 'maxOpsPerSecond' when 'throttlingEnabled' is set to"
+ " false.");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.ArgumentMatchers;
import org.mockito.Captor;
import org.mockito.Matchers;
import org.mockito.Mockito;
import org.mockito.Spy;
import org.mockito.runners.MockitoJUnitRunner;
import org.mockito.junit.MockitoJUnitRunner;

@RunWith(MockitoJUnitRunner.class)
public class CollectionReferenceTest {
Expand Down Expand Up @@ -94,7 +94,8 @@ public void addDocument() throws Exception {
doReturn(LocalFirestoreHelper.SINGLE_WRITE_COMMIT_RESPONSE)
.when(firestoreMock)
.sendRequest(
argCaptor.capture(), Matchers.<UnaryCallable<CommitRequest, CommitResponse>>any());
argCaptor.capture(),
ArgumentMatchers.<UnaryCallable<CommitRequest, CommitResponse>>any());

ApiFuture<DocumentReference> future =
collectionReference.add(LocalFirestoreHelper.SINGLE_FIELD_MAP);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,16 @@
import static com.google.cloud.firestore.LocalFirestoreHelper.getAllResponse;
import static com.google.cloud.firestore.LocalFirestoreHelper.queryResponse;
import static com.google.cloud.firestore.UserDataConverter.NO_DELETES;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.when;

import com.google.api.core.ApiFuture;
import com.google.api.core.SettableApiFuture;
import com.google.api.gax.rpc.BidiStreamObserver;
import com.google.api.gax.rpc.BidiStreamingCallable;
import com.google.api.gax.rpc.ClientStream;
import com.google.api.gax.rpc.ResponseObserver;
import com.google.api.gax.rpc.ServerStreamingCallable;
import com.google.api.gax.rpc.UnaryCallable;
import com.google.cloud.Timestamp;
import com.google.cloud.conformance.ConformanceTestLocator;
import com.google.cloud.conformance.ConformanceTestLocator.MatchPattern;
Expand Down Expand Up @@ -87,7 +85,6 @@
import org.junit.runners.AllTests;
import org.mockito.ArgumentCaptor;
import org.mockito.Captor;
import org.mockito.Matchers;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
Expand Down Expand Up @@ -123,9 +120,7 @@ private static List<Test> initTests(TestDefinition.TestFile testSuite) {
|| excludedTests.contains(testDefinition.getDescription())) {
continue;
}
final Test test = buildTest(testDefinition);
MockitoAnnotations.initMocks(test);
tests.add(test);
tests.add(buildTest(testDefinition));
}

return tests;
Expand Down Expand Up @@ -223,7 +218,9 @@ public final void run(TestResult testResult) {
if (DEBUG_MODE) {
System.out.printf(DEBUG_MESSAGE_FORMAT, description, testParameters);
}
runTest();
try (AutoCloseable mocks = MockitoAnnotations.openMocks(this)) {
runTest();
}
});
testResult.endTest(this);
}
Expand Down Expand Up @@ -261,10 +258,7 @@ private ConformanceGetTestRunner(String description, GetTest testParameters) {
public void runTest() throws Throwable {
doAnswer(getAllResponse(Collections.emptyMap()))
.when(firestore)
.streamRequest(
getAllCapture.capture(),
streamObserverCapture.capture(),
Matchers.<ServerStreamingCallable>any());
.streamRequest(getAllCapture.capture(), streamObserverCapture.capture(), any());

document(testParameters.getDocRefPath()).get().get();

Expand All @@ -288,7 +282,7 @@ private ConformanceCreateTestRunner(String description, CreateTest testParameter
public void runTest() {
doReturn(commitResponse(testParameters.getRequest().getWritesCount(), 0))
.when(firestore)
.sendRequest(commitCapture.capture(), Matchers.<UnaryCallable<Message, Message>>any());
.sendRequest(commitCapture.capture(), any());

try {
ApiFuture<WriteResult> apiCall =
Expand Down Expand Up @@ -319,7 +313,7 @@ private ConformanceSetTestRunner(String description, SetTest testParameters) {
public void runTest() {
doReturn(commitResponse(testParameters.getRequest().getWritesCount(), 0))
.when(firestore)
.sendRequest(commitCapture.capture(), Matchers.<UnaryCallable<Message, Message>>any());
.sendRequest(commitCapture.capture(), any());
ApiFuture<WriteResult> apiCall;

try {
Expand Down Expand Up @@ -364,7 +358,7 @@ private ConformanceUpdateTestRunner(String description, UpdateTest testParameter
public void runTest() {
doReturn(commitResponse(testParameters.getRequest().getWritesCount(), 0))
.when(firestore)
.sendRequest(commitCapture.capture(), Matchers.<UnaryCallable<Message, Message>>any());
.sendRequest(commitCapture.capture(), any());

try {
ApiFuture<WriteResult> apiCall;
Expand Down Expand Up @@ -405,7 +399,7 @@ private ConformanceUpdatePathsTestRunner(String description, UpdatePathsTest tes
public void runTest() {
doReturn(commitResponse(testParameters.getRequest().getWritesCount(), 0))
.when(firestore)
.sendRequest(commitCapture.capture(), Matchers.<UnaryCallable<Message, Message>>any());
.sendRequest(commitCapture.capture(), any());

try {
ApiFuture<WriteResult> apiCall;
Expand Down Expand Up @@ -461,7 +455,7 @@ private ConformanceDeleteTestRunner(String description, DeleteTest testParameter
public void runTest() throws Throwable {
doReturn(commitResponse(0, testParameters.getRequest().getWritesCount()))
.when(firestore)
.sendRequest(commitCapture.capture(), Matchers.<UnaryCallable<Message, Message>>any());
.sendRequest(commitCapture.capture(), any());

if (!testParameters.hasPrecondition()) {
document(testParameters.getDocRefPath()).delete().get();
Expand Down Expand Up @@ -491,10 +485,7 @@ private ConformanceQueryTestRunner(
public void runTest() {
doAnswer(queryResponse())
.when(firestore)
.streamRequest(
runQueryCapture.capture(),
streamObserverCapture.capture(),
Matchers.<ServerStreamingCallable>any());
.streamRequest(runQueryCapture.capture(), streamObserverCapture.capture(), any());

Query query = collection(testParameters.getCollPath());

Expand Down Expand Up @@ -646,8 +637,7 @@ public void runTest() throws Throwable {
return noOpRequestObserver;
})
.when(firestore)
.streamRequest(
streamObserverCapture.capture(), Matchers.any(BidiStreamingCallable.class));
.streamRequest(streamObserverCapture.capture(), any());

final List<Snapshot> expectedSnapshots = new ArrayList<>(testParameters.getSnapshotsList());

Expand Down
Loading