google-cloud-firestore
@@ -131,8 +131,8 @@
org.mockito
- mockito-all
- 1.10.19
+ mockito-core
+ 4.11.0
test
diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/BulkWriter.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/BulkWriter.java
index 8c32e0da5c..df25e11918 100644
--- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/BulkWriter.java
+++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/BulkWriter.java
@@ -760,18 +760,20 @@ public void addWriteResultListener(WriteResultCallback writeResultCallback) {
*
* The executor cannot be changed once writes have been enqueued onto the BulkWriter.
*
- *
For example, see the sample code:
- * BulkWriter bulkWriter = firestore.bulkWriter();
- * bulkWriter.addWriteResultListener(
- * (DocumentReference documentReference, WriteResult result) -> {
- * System.out.println(
- * "Successfully executed write on document: "
- * + documentReference
- * + " at: "
- * + result.getUpdateTime());
- * }
- * );
- *
+ *
For example, see the sample code:
+ *
+ *
{@code
+ * BulkWriter bulkWriter = firestore.bulkWriter();
+ * bulkWriter.addWriteResultListener(
+ * (DocumentReference documentReference, WriteResult result) -> {
+ * System.out.println(
+ * "Successfully executed write on document: "
+ * + documentReference
+ * + " at: "
+ * + result.getUpdateTime());
+ * }
+ * );
+ * }
*
* @param executor The executor to run the provided callback on.
* @param writeResultCallback A callback to be called every time a BulkWriter operation
@@ -796,20 +798,22 @@ public void addWriteResultListener(
* maximum of 10 failed attempts. When an error handler is specified, the default error handler
* will be overwritten.
*
- * For example, see the sample code:
- * BulkWriter bulkWriter = firestore.bulkWriter();
- * bulkWriter.addWriteErrorListener(
- * (BulkWriterException error) -> {
- * if (error.getStatus() == Status.UNAVAILABLE
- * && error.getFailedAttempts() < MAX_RETRY_ATTEMPTS) {
- * return true;
- * } else {
- * System.out.println("Failed write at document: " + error.getDocumentReference());
- * return false;
- * }
+ * For example, see the sample code:
+ *
+ *
{@code
+ * BulkWriter bulkWriter = firestore.bulkWriter();
+ * bulkWriter.addWriteErrorListener(
+ * (BulkWriterException error) -> {
+ * if (error.getStatus() == Status.UNAVAILABLE
+ * && error.getFailedAttempts() < MAX_RETRY_ATTEMPTS) {
+ * return true;
+ * } else {
+ * System.out.println("Failed write at document: " + error.getDocumentReference());
+ * return false;
* }
- * );
- *
+ * }
+ * );
+ * }
*
* @param onError A callback to be called every time a BulkWriter operation fails. Returning
* `true` will retry the operation. Returning `false` will stop the retry loop.
@@ -829,20 +833,22 @@ public void addWriteErrorListener(WriteErrorCallback onError) {
* maximum of 10 failed attempts. When an error handler is specified, the default error handler
* will be overwritten.
*
- *
For example, see the sample code:
- * BulkWriter bulkWriter = firestore.bulkWriter();
- * bulkWriter.addWriteErrorListener(
- * (BulkWriterException error) -> {
- * if (error.getStatus() == Status.UNAVAILABLE
- * && error.getFailedAttempts() < MAX_RETRY_ATTEMPTS) {
- * return true;
- * } else {
- * System.out.println("Failed write at document: " + error.getDocumentReference());
- * return false;
- * }
+ * For example, see the sample code:
+ *
+ *
{@code
+ * BulkWriter bulkWriter = firestore.bulkWriter();
+ * bulkWriter.addWriteErrorListener(
+ * (BulkWriterException error) -> {
+ * if (error.getStatus() == Status.UNAVAILABLE
+ * && error.getFailedAttempts() < MAX_RETRY_ATTEMPTS) {
+ * return true;
+ * } else {
+ * System.out.println("Failed write at document: " + error.getDocumentReference());
+ * return false;
* }
- * );
- *
+ * }
+ * );
+ * }
*
* @param executor The executor to run the provided callback on.
* @param onError A callback to be called every time a BulkWriter operation fails. Returning
diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/FirestoreBundle.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/FirestoreBundle.java
index 2b4977aebc..07cdedfdf5 100644
--- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/FirestoreBundle.java
+++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/FirestoreBundle.java
@@ -70,7 +70,7 @@ public String getId() {
* read time will be included in the bundle.
*
* @param documentSnapshot A document snapshot to add.
- * @returns This instance.
+ * @return This instance.
*/
public Builder add(DocumentSnapshot documentSnapshot) {
return add(documentSnapshot, Optional.empty());
@@ -133,7 +133,7 @@ private Builder add(DocumentSnapshot documentSnapshot, Optional queryNam
*
* @param queryName The name of the query to add.
* @param querySnap The query snapshot to add.
- * @returns This instance.
+ * @return This instance.
*/
public Builder add(String queryName, QuerySnapshot querySnap) {
BundledQuery query = querySnap.getQuery().toBundledQuery();
diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/annotation/DocumentId.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/annotation/DocumentId.java
index f8463a87bf..07913f6c1c 100644
--- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/annotation/DocumentId.java
+++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/annotation/DocumentId.java
@@ -29,8 +29,9 @@
* the POJO is created from a Cloud Firestore document (for example, via {@link
* DocumentSnapshot#toObject}).
*
+ * Any of the following will throw a runtime exception:
+ *
*
- * Any of the following will throw a runtime exception:
* - This annotation is applied to a property of a type other than String or {@link
* DocumentReference}.
*
- This annotation is applied to a property that is not writable (for example, a Java Bean
diff --git a/google-cloud-firestore/src/test/java/com/google/cloud/firestore/AggregateQuerySnapshotTest.java b/google-cloud-firestore/src/test/java/com/google/cloud/firestore/AggregateQuerySnapshotTest.java
index d500cad2f9..a7f5864285 100644
--- a/google-cloud-firestore/src/test/java/com/google/cloud/firestore/AggregateQuerySnapshotTest.java
+++ b/google-cloud-firestore/src/test/java/com/google/cloud/firestore/AggregateQuerySnapshotTest.java
@@ -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 {
diff --git a/google-cloud-firestore/src/test/java/com/google/cloud/firestore/AggregateQueryTest.java b/google-cloud-firestore/src/test/java/com/google/cloud/firestore/AggregateQueryTest.java
index e8baa9e0d8..d7e5134740 100644
--- a/google-cloud-firestore/src/test/java/com/google/cloud/firestore/AggregateQueryTest.java
+++ b/google-cloud-firestore/src/test/java/com/google/cloud/firestore/AggregateQueryTest.java
@@ -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 {
diff --git a/google-cloud-firestore/src/test/java/com/google/cloud/firestore/BulkWriterTest.java b/google-cloud-firestore/src/test/java/com/google/cloud/firestore/BulkWriterTest.java
index 202809188b..c8f8875f92 100644
--- a/google-cloud-firestore/src/test/java/com/google/cloud/firestore/BulkWriterTest.java
+++ b/google-cloud-firestore/src/test/java/com/google/cloud/firestore/BulkWriterTest.java
@@ -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;
@@ -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 {
@@ -153,7 +152,7 @@ public static ApiFuture mergeResponses(
@Before
public void before() {
- doReturn(immediateExecutor).when(firestoreRpc).getExecutor();
+ lenient().doReturn(immediateExecutor).when(firestoreRpc).getExecutor();
testExecutor = Executors.newSingleThreadScheduledExecutor();
final ScheduledExecutorService timeoutExecutor =
@@ -1011,7 +1010,7 @@ public void flushSucceedsEvenIfBulkCommitFails() throws Exception {
.when(firestoreMock)
.sendRequest(
batchWriteCapture.capture(),
- Matchers.>any());
+ ArgumentMatchers.>any());
bulkWriter.set(doc1, LocalFirestoreHelper.SINGLE_FIELD_MAP);
bulkWriter.set(doc2, LocalFirestoreHelper.SINGLE_FIELD_MAP);
bulkWriter.flush().get();
@@ -1023,7 +1022,7 @@ public void closeSucceedsEvenIfBulkCommitFails() throws Exception {
.when(firestoreMock)
.sendRequest(
batchWriteCapture.capture(),
- Matchers.>any());
+ ArgumentMatchers.>any());
bulkWriter.set(doc1, LocalFirestoreHelper.SINGLE_FIELD_MAP);
bulkWriter.set(doc2, LocalFirestoreHelper.SINGLE_FIELD_MAP);
bulkWriter.close();
@@ -1035,7 +1034,7 @@ public void individualWritesErrorIfBulkCommitFails() throws Exception {
.when(firestoreMock)
.sendRequest(
batchWriteCapture.capture(),
- Matchers.>any());
+ ArgumentMatchers.>any());
int opCount = 0;
ApiFuture result1 = bulkWriter.set(doc1, LocalFirestoreHelper.SINGLE_FIELD_MAP);
ApiFuture result2 = bulkWriter.set(doc2, LocalFirestoreHelper.SINGLE_FIELD_MAP);
@@ -1058,7 +1057,7 @@ public void individualWritesErrorIfBulkCommitFailsWithNonFirestoreException() th
.when(firestoreMock)
.sendRequest(
batchWriteCapture.capture(),
- Matchers.>any());
+ ArgumentMatchers.>any());
int opCount = 0;
ApiFuture result1 = bulkWriter.set(doc1, LocalFirestoreHelper.SINGLE_FIELD_MAP);
ApiFuture result2 = bulkWriter.set(doc2, LocalFirestoreHelper.SINGLE_FIELD_MAP);
@@ -1086,7 +1085,7 @@ public void retriesWritesWhenBatchWriteFailsWithRetryableError() throws Exceptio
.when(firestoreMock)
.sendRequest(
batchWriteCapture.capture(),
- Matchers.>any());
+ ArgumentMatchers.>any());
ApiFuture result = bulkWriter.set(doc1, LocalFirestoreHelper.SINGLE_FIELD_MAP);
bulkWriter.close();
@@ -1125,7 +1124,7 @@ public ScheduledFuture> schedule(Runnable command, long delay, TimeUnit unit)
.when(firestoreMock)
.sendRequest(
batchWriteCapture.capture(),
- Matchers.>any());
+ ArgumentMatchers.>any());
bulkWriter =
firestoreMock.bulkWriter(BulkWriterOptions.builder().setExecutor(timeoutExecutor).build());
@@ -1175,7 +1174,7 @@ public ScheduledFuture> schedule(Runnable command, long delay, TimeUnit unit)
.when(firestoreMock)
.sendRequest(
batchWriteCapture.capture(),
- Matchers.>any());
+ ArgumentMatchers.>any());
bulkWriter =
firestoreMock.bulkWriter(BulkWriterOptions.builder().setExecutor(timeoutExecutor).build());
@@ -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 {
@@ -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.");
}
}
diff --git a/google-cloud-firestore/src/test/java/com/google/cloud/firestore/CollectionReferenceTest.java b/google-cloud-firestore/src/test/java/com/google/cloud/firestore/CollectionReferenceTest.java
index 0ede445461..9e22b40a74 100644
--- a/google-cloud-firestore/src/test/java/com/google/cloud/firestore/CollectionReferenceTest.java
+++ b/google-cloud-firestore/src/test/java/com/google/cloud/firestore/CollectionReferenceTest.java
@@ -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 {
@@ -94,7 +94,8 @@ public void addDocument() throws Exception {
doReturn(LocalFirestoreHelper.SINGLE_WRITE_COMMIT_RESPONSE)
.when(firestoreMock)
.sendRequest(
- argCaptor.capture(), Matchers.>any());
+ argCaptor.capture(),
+ ArgumentMatchers.>any());
ApiFuture future =
collectionReference.add(LocalFirestoreHelper.SINGLE_FIELD_MAP);
diff --git a/google-cloud-firestore/src/test/java/com/google/cloud/firestore/ConformanceTest.java b/google-cloud-firestore/src/test/java/com/google/cloud/firestore/ConformanceTest.java
index dd5b215950..8b759e10da 100644
--- a/google-cloud-firestore/src/test/java/com/google/cloud/firestore/ConformanceTest.java
+++ b/google-cloud-firestore/src/test/java/com/google/cloud/firestore/ConformanceTest.java
@@ -25,6 +25,7 @@
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;
@@ -32,11 +33,8 @@
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;
@@ -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;
@@ -123,9 +120,7 @@ private static List 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;
@@ -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);
}
@@ -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.any());
+ .streamRequest(getAllCapture.capture(), streamObserverCapture.capture(), any());
document(testParameters.getDocRefPath()).get().get();
@@ -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.>any());
+ .sendRequest(commitCapture.capture(), any());
try {
ApiFuture apiCall =
@@ -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.>any());
+ .sendRequest(commitCapture.capture(), any());
ApiFuture apiCall;
try {
@@ -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.>any());
+ .sendRequest(commitCapture.capture(), any());
try {
ApiFuture apiCall;
@@ -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.>any());
+ .sendRequest(commitCapture.capture(), any());
try {
ApiFuture apiCall;
@@ -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.>any());
+ .sendRequest(commitCapture.capture(), any());
if (!testParameters.hasPrecondition()) {
document(testParameters.getDocRefPath()).delete().get();
@@ -491,10 +485,7 @@ private ConformanceQueryTestRunner(
public void runTest() {
doAnswer(queryResponse())
.when(firestore)
- .streamRequest(
- runQueryCapture.capture(),
- streamObserverCapture.capture(),
- Matchers.any());
+ .streamRequest(runQueryCapture.capture(), streamObserverCapture.capture(), any());
Query query = collection(testParameters.getCollPath());
@@ -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 expectedSnapshots = new ArrayList<>(testParameters.getSnapshotsList());
diff --git a/google-cloud-firestore/src/test/java/com/google/cloud/firestore/DocumentReferenceTest.java b/google-cloud-firestore/src/test/java/com/google/cloud/firestore/DocumentReferenceTest.java
index aecc8b6bea..7d982b86c6 100644
--- a/google-cloud-firestore/src/test/java/com/google/cloud/firestore/DocumentReferenceTest.java
+++ b/google-cloud-firestore/src/test/java/com/google/cloud/firestore/DocumentReferenceTest.java
@@ -92,11 +92,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 DocumentReferenceTest {
@@ -149,7 +149,8 @@ public void serializeBasicTypes() throws Exception {
doReturn(SINGLE_WRITE_COMMIT_RESPONSE)
.when(firestoreMock)
.sendRequest(
- commitCapture.capture(), Matchers.>any());
+ commitCapture.capture(),
+ ArgumentMatchers.>any());
documentReference.set(ALL_SUPPORTED_TYPES_MAP).get();
documentReference.set(ALL_SUPPORTED_TYPES_OBJECT).get();
@@ -164,7 +165,8 @@ public void serializeDocumentReference() throws Exception {
doReturn(SINGLE_WRITE_COMMIT_RESPONSE)
.when(firestoreMock)
.sendRequest(
- commitCapture.capture(), Matchers.>any());
+ commitCapture.capture(),
+ ArgumentMatchers.>any());
documentReference.set(map("docRef", documentReference)).get();
@@ -183,19 +185,22 @@ public void doesNotSerializeAdvancedNumberTypes() {
pojo.bigIntegerValue = new BigInteger("0");
expectedErrorMessages.put(
pojo,
- "Could not serialize object. Numbers of type BigInteger are not supported, please use an int, long, float, double or BigDecimal (found in field 'bigIntegerValue')");
+ "Could not serialize object. Numbers of type BigInteger are not supported, please use an"
+ + " int, long, float, double or BigDecimal (found in field 'bigIntegerValue')");
pojo = new InvalidPOJO();
pojo.byteValue = 0;
expectedErrorMessages.put(
pojo,
- "Could not serialize object. Numbers of type Byte are not supported, please use an int, long, float, double or BigDecimal (found in field 'byteValue')");
+ "Could not serialize object. Numbers of type Byte are not supported, please use an int,"
+ + " long, float, double or BigDecimal (found in field 'byteValue')");
pojo = new InvalidPOJO();
pojo.shortValue = 0;
expectedErrorMessages.put(
pojo,
- "Could not serialize object. Numbers of type Short are not supported, please use an int, long, float, double or BigDecimal (found in field 'shortValue')");
+ "Could not serialize object. Numbers of type Short are not supported, please use an int,"
+ + " long, float, double or BigDecimal (found in field 'shortValue')");
for (Map.Entry testCase : expectedErrorMessages.entrySet()) {
try {
@@ -214,7 +219,7 @@ public void deserializeBasicTypes() throws Exception {
.streamRequest(
getAllCapture.capture(),
streamObserverCapture.capture(),
- Matchers.any());
+ ArgumentMatchers.any());
DocumentSnapshot snapshot = documentReference.get().get();
assertEquals(snapshot.getData(), ALL_SUPPORTED_TYPES_MAP);
@@ -271,7 +276,7 @@ public void deserializeDocumentReference() throws Exception {
.streamRequest(
getAllCapture.capture(),
streamObserverCapture.capture(),
- Matchers.any());
+ ArgumentMatchers.any());
DocumentSnapshot snapshot = documentReference.get().get();
assertEquals(documentReference, snapshot.getData().get("docRef"));
@@ -285,7 +290,7 @@ public void getFieldWithFieldMask() throws Exception {
.streamRequest(
getAllCapture.capture(),
streamObserverCapture.capture(),
- Matchers.any());
+ ArgumentMatchers.any());
DocumentSnapshot snapshot = documentReference.get(FieldMask.of(FieldPath.of("foo"))).get();
assertEquals("foo", getAllCapture.getValue().getMask().getFieldPaths(0));
assertEquals("bar", snapshot.get("foo"));
@@ -298,7 +303,7 @@ public void deserializesDates() throws Exception {
.streamRequest(
getAllCapture.capture(),
streamObserverCapture.capture(),
- Matchers.any());
+ ArgumentMatchers.any());
DocumentSnapshot snapshot = documentReference.get().get();
@@ -323,7 +328,7 @@ public void doesNotDeserializeAdvancedNumberTypes() throws Exception {
.streamRequest(
getAllCapture.capture(),
streamObserverCapture.capture(),
- Matchers.any());
+ ArgumentMatchers.any());
DocumentSnapshot snapshot = documentReference.get().get();
try {
@@ -332,7 +337,8 @@ public void doesNotDeserializeAdvancedNumberTypes() throws Exception {
} catch (RuntimeException e) {
assertEquals(
String.format(
- "Could not deserialize object. Deserializing values to %s is not supported (found in field '%s')",
+ "Could not deserialize object. Deserializing values to %s is not supported (found"
+ + " in field '%s')",
typeName, fieldName),
e.getMessage());
}
@@ -355,7 +361,7 @@ public void notFound() throws Exception {
.streamRequest(
getAllCapture.capture(),
streamObserverCapture.capture(),
- Matchers.any());
+ ArgumentMatchers.any());
DocumentSnapshot snapshot = documentReference.get().get();
assertEquals(documentReference, snapshot.getReference());
@@ -369,7 +375,8 @@ public void deleteDocument() throws Exception {
doReturn(SINGLE_DELETE_COMMIT_RESPONSE)
.when(firestoreMock)
.sendRequest(
- commitCapture.capture(), Matchers.>any());
+ commitCapture.capture(),
+ ArgumentMatchers.>any());
documentReference.delete().get();
documentReference
@@ -390,7 +397,8 @@ public void createDocument() throws Exception {
doReturn(SINGLE_WRITE_COMMIT_RESPONSE)
.when(firestoreMock)
.sendRequest(
- commitCapture.capture(), Matchers.>any());
+ commitCapture.capture(),
+ ArgumentMatchers.>any());
documentReference.create(SINGLE_FIELD_MAP).get();
documentReference.create(SINGLE_FIELD_OBJECT).get();
@@ -407,7 +415,8 @@ public void createWithServerTimestamp() throws Exception {
doReturn(SINGLE_WRITE_COMMIT_RESPONSE)
.when(firestoreMock)
.sendRequest(
- commitCapture.capture(), Matchers.>any());
+ commitCapture.capture(),
+ ArgumentMatchers.>any());
documentReference.create(LocalFirestoreHelper.SERVER_TIMESTAMP_MAP).get();
documentReference.create(LocalFirestoreHelper.SERVER_TIMESTAMP_OBJECT).get();
@@ -427,7 +436,8 @@ public void setWithServerTimestamp() throws Exception {
doReturn(FIELD_TRANSFORM_COMMIT_RESPONSE)
.when(firestoreMock)
.sendRequest(
- commitCapture.capture(), Matchers.>any());
+ commitCapture.capture(),
+ ArgumentMatchers.>any());
documentReference.set(LocalFirestoreHelper.SERVER_TIMESTAMP_MAP).get();
documentReference.set(LocalFirestoreHelper.SERVER_TIMESTAMP_OBJECT).get();
@@ -447,7 +457,8 @@ public void updateWithServerTimestamp() throws Exception {
doReturn(FIELD_TRANSFORM_COMMIT_RESPONSE)
.when(firestoreMock)
.sendRequest(
- commitCapture.capture(), Matchers.>any());
+ commitCapture.capture(),
+ ArgumentMatchers.>any());
documentReference.update(LocalFirestoreHelper.SERVER_TIMESTAMP_MAP).get();
@@ -474,7 +485,8 @@ public void mergeWithServerTimestamps() throws Exception {
doReturn(SINGLE_WRITE_COMMIT_RESPONSE)
.when(firestoreMock)
.sendRequest(
- commitCapture.capture(), Matchers.>any());
+ commitCapture.capture(),
+ ArgumentMatchers.>any());
documentReference
.set(LocalFirestoreHelper.SERVER_TIMESTAMP_MAP, SetOptions.mergeFields("inner.bar"))
@@ -498,7 +510,8 @@ public void setWithIncrement() throws Exception {
doReturn(FIELD_TRANSFORM_COMMIT_RESPONSE)
.when(firestoreMock)
.sendRequest(
- commitCapture.capture(), Matchers.>any());
+ commitCapture.capture(),
+ ArgumentMatchers.>any());
documentReference
.set(map("integer", FieldValue.increment(1), "double", FieldValue.increment(1.1)))
@@ -522,7 +535,8 @@ public void setWithArrayUnion() throws Exception {
doReturn(FIELD_TRANSFORM_COMMIT_RESPONSE)
.when(firestoreMock)
.sendRequest(
- commitCapture.capture(), Matchers.>any());
+ commitCapture.capture(),
+ ArgumentMatchers.>any());
documentReference.set(map("foo", FieldValue.arrayUnion("bar", map("foo", "baz")))).get();
@@ -540,7 +554,8 @@ public void setWithArrayRemove() throws Exception {
doReturn(FIELD_TRANSFORM_COMMIT_RESPONSE)
.when(firestoreMock)
.sendRequest(
- commitCapture.capture(), Matchers.>any());
+ commitCapture.capture(),
+ ArgumentMatchers.>any());
documentReference.set(map("foo", FieldValue.arrayRemove("bar", map("foo", "baz")))).get();
@@ -688,7 +703,8 @@ public void setDocumentWithMerge() throws Exception {
doReturn(SINGLE_WRITE_COMMIT_RESPONSE)
.when(firestoreMock)
.sendRequest(
- commitCapture.capture(), Matchers.>any());
+ commitCapture.capture(),
+ ArgumentMatchers.>any());
documentReference.set(SINGLE_FIELD_MAP, SetOptions.merge()).get();
documentReference.set(SINGLE_FIELD_OBJECT, SetOptions.merge()).get();
@@ -714,7 +730,8 @@ public void setDocumentWithEmptyMerge() throws Exception {
doReturn(SINGLE_WRITE_COMMIT_RESPONSE)
.when(firestoreMock)
.sendRequest(
- commitCapture.capture(), Matchers.>any());
+ commitCapture.capture(),
+ ArgumentMatchers.>any());
documentReference.set(map(), SetOptions.merge()).get();
@@ -727,7 +744,8 @@ public void setDocumentWithNestedMerge() throws Exception {
doReturn(SINGLE_WRITE_COMMIT_RESPONSE)
.when(firestoreMock)
.sendRequest(
- commitCapture.capture(), Matchers.>any());
+ commitCapture.capture(),
+ ArgumentMatchers.>any());
documentReference.set(NESTED_CLASS_OBJECT, SetOptions.mergeFields("first.foo")).get();
documentReference
@@ -756,7 +774,8 @@ public void setMultipleFieldsWithMerge() throws Exception {
doReturn(SINGLE_WRITE_COMMIT_RESPONSE)
.when(firestoreMock)
.sendRequest(
- commitCapture.capture(), Matchers.>any());
+ commitCapture.capture(),
+ ArgumentMatchers.>any());
documentReference
.set(
@@ -784,7 +803,8 @@ public void setNestedMapWithMerge() throws Exception {
doReturn(SINGLE_WRITE_COMMIT_RESPONSE)
.when(firestoreMock)
.sendRequest(
- commitCapture.capture(), Matchers.>any());
+ commitCapture.capture(),
+ ArgumentMatchers.>any());
documentReference.set(NESTED_CLASS_OBJECT, SetOptions.mergeFields("first", "second")).get();
@@ -804,7 +824,8 @@ public void mergeWithDotsInFieldName() throws Exception {
doReturn(SINGLE_WRITE_COMMIT_RESPONSE)
.when(firestoreMock)
.sendRequest(
- commitCapture.capture(), Matchers.>any());
+ commitCapture.capture(),
+ ArgumentMatchers.>any());
documentReference
.set(
@@ -828,7 +849,8 @@ public void extractFieldMaskFromMerge() throws Exception {
doReturn(SINGLE_WRITE_COMMIT_RESPONSE)
.when(firestoreMock)
.sendRequest(
- commitCapture.capture(), Matchers.>any());
+ commitCapture.capture(),
+ ArgumentMatchers.>any());
documentReference.set(NESTED_CLASS_OBJECT, SetOptions.merge()).get();
@@ -868,7 +890,8 @@ public void updateDocument() throws Exception {
doReturn(SINGLE_WRITE_COMMIT_RESPONSE)
.when(firestoreMock)
.sendRequest(
- commitCapture.capture(), Matchers.>any());
+ commitCapture.capture(),
+ ArgumentMatchers.>any());
documentReference.update(SINGLE_FIELD_MAP);
documentReference.update("foo", "bar").get();
@@ -886,7 +909,8 @@ public void updateWithDotsInFieldName() throws Exception {
doReturn(SINGLE_WRITE_COMMIT_RESPONSE)
.when(firestoreMock)
.sendRequest(
- commitCapture.capture(), Matchers.>any());
+ commitCapture.capture(),
+ ArgumentMatchers.>any());
documentReference.update(map("a.b.c", map("d.e", "foo"))).get();
@@ -910,7 +934,8 @@ public void updateNestedMap() throws Exception {
doReturn(SINGLE_WRITE_COMMIT_RESPONSE)
.when(firestoreMock)
.sendRequest(
- commitCapture.capture(), Matchers.>any());
+ commitCapture.capture(),
+ ArgumentMatchers.>any());
documentReference.update("a.b", "foo", "a.c", FieldValue.delete()).get();
@@ -961,7 +986,8 @@ public void deleteField() throws Exception {
doReturn(SINGLE_WRITE_COMMIT_RESPONSE)
.when(firestoreMock)
.sendRequest(
- commitCapture.capture(), Matchers.>any());
+ commitCapture.capture(),
+ ArgumentMatchers.>any());
documentReference.update("foo", "bar", "bar.foo", FieldValue.delete()).get();
@@ -981,7 +1007,8 @@ public void updateNestedDocument() throws Exception {
doReturn(SINGLE_WRITE_COMMIT_RESPONSE)
.when(firestoreMock)
.sendRequest(
- commitCapture.capture(), Matchers.>any());
+ commitCapture.capture(),
+ ArgumentMatchers.>any());
Map nestedObject = new HashMap<>();
nestedObject.put("a", "b");
@@ -1005,7 +1032,8 @@ public void updateDocumentWithTwoFields() throws Exception {
doReturn(SINGLE_WRITE_COMMIT_RESPONSE)
.when(firestoreMock)
.sendRequest(
- commitCapture.capture(), Matchers.>any());
+ commitCapture.capture(),
+ ArgumentMatchers.>any());
documentReference.update("a", "b", "c", "d").get();
@@ -1027,7 +1055,8 @@ public void updateDocumentWithPreconditions() throws Exception {
doReturn(SINGLE_WRITE_COMMIT_RESPONSE)
.when(firestoreMock)
.sendRequest(
- commitCapture.capture(), Matchers.>any());
+ commitCapture.capture(),
+ ArgumentMatchers.>any());
Precondition options =
Precondition.updatedAt(Timestamp.ofTimeSecondsAndNanos(479978400, 123000000));
@@ -1052,7 +1081,8 @@ public void updateIndividualPojo() throws ExecutionException, InterruptedExcepti
doReturn(SINGLE_WRITE_COMMIT_RESPONSE)
.when(firestoreMock)
.sendRequest(
- commitCapture.capture(), Matchers.>any());
+ commitCapture.capture(),
+ ArgumentMatchers.>any());
documentReference.update(UPDATED_POJO);
documentReference.update(UPDATED_POJO).get();
CommitRequest expectedCommit =
@@ -1068,7 +1098,8 @@ public void deleteNestedFieldUsingFieldPath() throws Exception {
doReturn(SINGLE_WRITE_COMMIT_RESPONSE)
.when(firestoreMock)
.sendRequest(
- commitCapture.capture(), Matchers.>any());
+ commitCapture.capture(),
+ ArgumentMatchers.>any());
FieldPath path = FieldPath.of("a.b", "c.d");
documentReference.update(path, FieldValue.delete()).get();
CommitRequest expectedCommit =
@@ -1097,7 +1128,7 @@ public void deserializeCustomList() throws ExecutionException, InterruptedExcept
.streamRequest(
getAllCapture.capture(),
streamObserverCapture.capture(),
- Matchers.any());
+ ArgumentMatchers.any());
DocumentSnapshot snapshot = documentReference.get().get();
LocalFirestoreHelper.CustomList customList =
snapshot.toObject(LocalFirestoreHelper.CustomList.class);
@@ -1129,7 +1160,7 @@ public void deserializeCustomMap() throws ExecutionException, InterruptedExcepti
.streamRequest(
getAllCapture.capture(),
streamObserverCapture.capture(),
- Matchers.any());
+ ArgumentMatchers.any());
DocumentSnapshot snapshot = documentReference.get().get();
LocalFirestoreHelper.CustomMap customMap =
snapshot.toObject(LocalFirestoreHelper.CustomMap.class);
diff --git a/google-cloud-firestore/src/test/java/com/google/cloud/firestore/FirestoreBundleTest.java b/google-cloud-firestore/src/test/java/com/google/cloud/firestore/FirestoreBundleTest.java
index 28ff1d7105..780bbd6981 100644
--- a/google-cloud-firestore/src/test/java/com/google/cloud/firestore/FirestoreBundleTest.java
+++ b/google-cloud-firestore/src/test/java/com/google/cloud/firestore/FirestoreBundleTest.java
@@ -46,7 +46,7 @@
import org.junit.runner.RunWith;
import org.mockito.Mockito;
import org.mockito.Spy;
-import org.mockito.runners.MockitoJUnitRunner;
+import org.mockito.junit.MockitoJUnitRunner;
@RunWith(MockitoJUnitRunner.class)
public class FirestoreBundleTest {
diff --git a/google-cloud-firestore/src/test/java/com/google/cloud/firestore/FirestoreTest.java b/google-cloud-firestore/src/test/java/com/google/cloud/firestore/FirestoreTest.java
index 9d685022d9..d4df6220b4 100644
--- a/google-cloud-firestore/src/test/java/com/google/cloud/firestore/FirestoreTest.java
+++ b/google-cloud-firestore/src/test/java/com/google/cloud/firestore/FirestoreTest.java
@@ -47,11 +47,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 FirestoreTest {
@@ -85,7 +85,7 @@ public void illegalFieldPath() throws Exception {
.streamRequest(
getAllCapture.capture(),
streamObserverCapture.capture(),
- Matchers.any());
+ ArgumentMatchers.any());
DocumentReference doc = firestoreMock.document("coll/doc");
DocumentSnapshot snapshot = doc.get().get();
@@ -116,7 +116,7 @@ public void getAll() throws Exception {
.streamRequest(
getAllCapture.capture(),
streamObserverCapture.capture(),
- Matchers.any());
+ ArgumentMatchers.any());
DocumentReference doc1 = firestoreMock.document("coll/doc1");
DocumentReference doc2 = firestoreMock.document("coll/doc2");
@@ -137,7 +137,7 @@ public void getAllWithFieldMask() throws Exception {
.streamRequest(
getAllCapture.capture(),
streamObserverCapture.capture(),
- Matchers.any());
+ ArgumentMatchers.any());
DocumentReference doc1 = firestoreMock.document("coll/doc1");
FieldMask fieldMask = FieldMask.of(FieldPath.of("foo", "bar"));
@@ -190,7 +190,8 @@ public void arrayUnionWithPojo() throws ExecutionException, InterruptedException
doReturn(commitResponse(1, 0))
.when(firestoreMock)
.sendRequest(
- commitCapture.capture(), Matchers.>any());
+ commitCapture.capture(),
+ ArgumentMatchers.>any());
DocumentReference doc = firestoreMock.document("coll/doc");
doc.update("array", FieldValue.arrayUnion(SINGLE_FIELD_OBJECT)).get();
@@ -208,7 +209,8 @@ public void arrayRemoveWithPojo() throws ExecutionException, InterruptedExceptio
doReturn(commitResponse(1, 0))
.when(firestoreMock)
.sendRequest(
- commitCapture.capture(), Matchers.>any());
+ commitCapture.capture(),
+ ArgumentMatchers.>any());
DocumentReference doc = firestoreMock.document("coll/doc");
doc.update("array", FieldValue.arrayRemove(SINGLE_FIELD_OBJECT)).get();
diff --git a/google-cloud-firestore/src/test/java/com/google/cloud/firestore/LocalFirestoreHelper.java b/google-cloud-firestore/src/test/java/com/google/cloud/firestore/LocalFirestoreHelper.java
index b3774224e4..896a51e3af 100644
--- a/google-cloud-firestore/src/test/java/com/google/cloud/firestore/LocalFirestoreHelper.java
+++ b/google-cloud-firestore/src/test/java/com/google/cloud/firestore/LocalFirestoreHelper.java
@@ -86,7 +86,7 @@
import java.util.concurrent.TimeUnit;
import javax.annotation.Nullable;
import org.mockito.ArgumentCaptor;
-import org.mockito.Matchers;
+import org.mockito.ArgumentMatchers;
import org.mockito.stubbing.Answer;
import org.mockito.stubbing.Stubber;
import org.threeten.bp.Duration;
@@ -1203,7 +1203,8 @@ void initializeStub(
Preconditions.checkNotNull(stubber, "Stubber should not be null");
stubber
.when(firestoreMock)
- .sendRequest(argumentCaptor.capture(), Matchers.>any());
+ .sendRequest(
+ argumentCaptor.capture(), ArgumentMatchers.>any());
}
public void verifyAllRequestsSent() {
diff --git a/google-cloud-firestore/src/test/java/com/google/cloud/firestore/MapperTest.java b/google-cloud-firestore/src/test/java/com/google/cloud/firestore/MapperTest.java
index e3725127e0..5ea6cd84f9 100644
--- a/google-cloud-firestore/src/test/java/com/google/cloud/firestore/MapperTest.java
+++ b/google-cloud-firestore/src/test/java/com/google/cloud/firestore/MapperTest.java
@@ -48,7 +48,7 @@
import org.junit.runner.RunWith;
import org.mockito.Mockito;
import org.mockito.Spy;
-import org.mockito.runners.MockitoJUnitRunner;
+import org.mockito.junit.MockitoJUnitRunner;
@SuppressWarnings({"unused", "WeakerAccess", "SpellCheckingInspection"})
@RunWith(MockitoJUnitRunner.class)
@@ -1850,7 +1850,8 @@ public void shortsCantBeSerialized() {
final ShortBean bean = new ShortBean();
bean.value = 1;
assertExceptionContains(
- "Numbers of type Short are not supported, please use an int, long, float, double or BigDecimal (found in field 'value')",
+ "Numbers of type Short are not supported, please use an int, long, float, double or"
+ + " BigDecimal (found in field 'value')",
() -> serialize(bean));
}
@@ -1859,7 +1860,8 @@ public void bytesCantBeSerialized() {
final ByteBean bean = new ByteBean();
bean.value = 1;
assertExceptionContains(
- "Numbers of type Byte are not supported, please use an int, long, float, double or BigDecimal (found in field 'value')",
+ "Numbers of type Byte are not supported, please use an int, long, float, double or"
+ + " BigDecimal (found in field 'value')",
() -> serialize(bean));
}
@@ -2193,14 +2195,16 @@ public void enumsAreSerialized() {
bean.pathologicalEnum = PathologicalEnum.One;
bean.setEnumValue(SimpleEnum.Foo);
assertJson(
- "{'enumField': 'Bar', 'enumValue': 'Foo', 'complexEnum': 'One', 'enumUsingPropertyName': 'Three', 'pathologicalEnum': 'Two'}",
+ "{'enumField': 'Bar', 'enumValue': 'Foo', 'complexEnum': 'One', 'enumUsingPropertyName':"
+ + " 'Three', 'pathologicalEnum': 'Two'}",
serialize(bean));
}
@Test
public void enumsAreParsed() {
String json =
- "{'enumField': 'Bar', 'enumValue': 'Foo', 'complexEnum': 'One', 'enumUsingPropertyName': 'Three', 'pathologicalEnum': 'Two'}";
+ "{'enumField': 'Bar', 'enumValue': 'Foo', 'complexEnum': 'One', 'enumUsingPropertyName':"
+ + " 'Three', 'pathologicalEnum': 'Two'}";
EnumBean bean = deserialize(json, EnumBean.class);
assertEquals(bean.enumField, SimpleEnum.Bar);
assertEquals(bean.enumValue, SimpleEnum.Foo);
diff --git a/google-cloud-firestore/src/test/java/com/google/cloud/firestore/PartitionQuery.java b/google-cloud-firestore/src/test/java/com/google/cloud/firestore/PartitionQuery.java
index 04203313be..4478ea9c97 100644
--- a/google-cloud-firestore/src/test/java/com/google/cloud/firestore/PartitionQuery.java
+++ b/google-cloud-firestore/src/test/java/com/google/cloud/firestore/PartitionQuery.java
@@ -43,12 +43,12 @@
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.Mock;
import org.mockito.Mockito;
import org.mockito.Spy;
-import org.mockito.runners.MockitoJUnitRunner;
+import org.mockito.junit.MockitoJUnitRunner;
@RunWith(MockitoJUnitRunner.class)
public class PartitionQuery {
@@ -109,7 +109,8 @@ public void requestsOneLessThanDesired() throws Exception {
.when(firestoreMock)
.sendRequest(
requestCaptor.capture(),
- Matchers.>any());
+ ArgumentMatchers
+ .>any());
firestoreMock.collectionGroup("collectionId").getPartitions(desiredPartitionsCount).get();
@@ -153,14 +154,15 @@ public void convertsPartitionsToQueries() throws Exception {
.when(firestoreMock)
.sendRequest(
requestCaptor.capture(),
- Matchers.>any());
+ ArgumentMatchers
+ .>any());
doAnswer(queryResponse())
.when(firestoreMock)
.streamRequest(
runQuery.capture(),
streamObserverCapture.capture(),
- Matchers.any());
+ ArgumentMatchers.any());
List partitions =
firestoreMock.collectionGroup("collectionId").getPartitions(desiredPartitionsCount).get();
@@ -193,7 +195,8 @@ public void sortsPartitions() throws Exception {
.when(firestoreMock)
.sendRequest(
requestCaptor.capture(),
- Matchers.>any());
+ ArgumentMatchers
+ .>any());
List partitions =
firestoreMock.collectionGroup("collectionId").getPartitions(desiredPartitionsCount).get();
diff --git a/google-cloud-firestore/src/test/java/com/google/cloud/firestore/QueryCountTest.java b/google-cloud-firestore/src/test/java/com/google/cloud/firestore/QueryCountTest.java
index ea9dad975f..3cf05648e3 100644
--- a/google-cloud-firestore/src/test/java/com/google/cloud/firestore/QueryCountTest.java
+++ b/google-cloud-firestore/src/test/java/com/google/cloud/firestore/QueryCountTest.java
@@ -28,6 +28,7 @@
import static com.google.cloud.firestore.LocalFirestoreHelper.string;
import static com.google.common.truth.Truth.assertThat;
import static org.junit.Assert.assertThrows;
+import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
@@ -35,7 +36,6 @@
import com.google.api.core.ApiClock;
import com.google.api.core.ApiFuture;
import com.google.api.gax.rpc.ResponseObserver;
-import com.google.api.gax.rpc.ServerStreamingCallable;
import com.google.cloud.Timestamp;
import com.google.cloud.firestore.spi.v1.FirestoreRpc;
import com.google.firestore.v1.RunAggregationQueryRequest;
@@ -49,9 +49,8 @@
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Captor;
-import org.mockito.Matchers;
import org.mockito.Spy;
-import org.mockito.runners.MockitoJUnitRunner;
+import org.mockito.junit.MockitoJUnitRunner;
import org.threeten.bp.Duration;
@RunWith(MockitoJUnitRunner.class)
@@ -80,10 +79,7 @@ public void before() {
public void countShouldBeZeroForEmptyCollection() throws Exception {
doAnswer(aggregationQueryResponse(0))
.when(firestoreMock)
- .streamRequest(
- runAggregationQuery.capture(),
- streamObserverCapture.capture(),
- Matchers.any());
+ .streamRequest(runAggregationQuery.capture(), streamObserverCapture.capture(), any());
AggregateQuerySnapshot snapshot = query.count().get().get();
@@ -94,10 +90,7 @@ public void countShouldBeZeroForEmptyCollection() throws Exception {
public void countShouldBe99ForCollectionWith99Documents() throws Exception {
doAnswer(aggregationQueryResponse(99))
.when(firestoreMock)
- .streamRequest(
- runAggregationQuery.capture(),
- streamObserverCapture.capture(),
- Matchers.any());
+ .streamRequest(runAggregationQuery.capture(), streamObserverCapture.capture(), any());
AggregateQuerySnapshot snapshot = query.count().get().get();
@@ -108,10 +101,7 @@ public void countShouldBe99ForCollectionWith99Documents() throws Exception {
public void countShouldMakeCorrectRequestForACollection() throws Exception {
doAnswer(aggregationQueryResponse(0))
.when(firestoreMock)
- .streamRequest(
- runAggregationQuery.capture(),
- streamObserverCapture.capture(),
- Matchers.any());
+ .streamRequest(runAggregationQuery.capture(), streamObserverCapture.capture(), any());
CollectionReference collection = firestoreMock.collection(COLLECTION_ID);
collection.count().get();
@@ -123,10 +113,7 @@ public void countShouldMakeCorrectRequestForACollection() throws Exception {
public void countShouldMakeCorrectRequestForAComplexQuery() throws Exception {
doAnswer(aggregationQueryResponse(0))
.when(firestoreMock)
- .streamRequest(
- runAggregationQuery.capture(),
- streamObserverCapture.capture(),
- Matchers.any());
+ .streamRequest(runAggregationQuery.capture(), streamObserverCapture.capture(), any());
query.orderBy("foo").startAt("foo").endAt("bar").limitToLast(42).count().get().get();
@@ -144,10 +131,7 @@ public void countShouldMakeCorrectRequestForAComplexQuery() throws Exception {
public void shouldReturnReadTimeFromResponse() throws Exception {
doAnswer(aggregationQueryResponse(99, Timestamp.ofTimeSecondsAndNanos(123, 456)))
.when(firestoreMock)
- .streamRequest(
- runAggregationQuery.capture(),
- streamObserverCapture.capture(),
- Matchers.any());
+ .streamRequest(runAggregationQuery.capture(), streamObserverCapture.capture(), any());
AggregateQuerySnapshot snapshot = query.count().get().get();
@@ -158,10 +142,7 @@ public void shouldReturnReadTimeFromResponse() throws Exception {
public void shouldIgnoreExtraRunAggregationQueryResponses() throws Exception {
doAnswer(aggregationQueryResponses(123, 456))
.when(firestoreMock)
- .streamRequest(
- runAggregationQuery.capture(),
- streamObserverCapture.capture(),
- Matchers.any());
+ .streamRequest(runAggregationQuery.capture(), streamObserverCapture.capture(), any());
AggregateQuerySnapshot snapshot = query.count().get().get();
@@ -172,10 +153,7 @@ public void shouldIgnoreExtraRunAggregationQueryResponses() throws Exception {
public void shouldIgnoreExtraErrors() throws Exception {
doAnswer(aggregationQueryResponses(123, new Exception()))
.when(firestoreMock)
- .streamRequest(
- runAggregationQuery.capture(),
- streamObserverCapture.capture(),
- Matchers.any());
+ .streamRequest(runAggregationQuery.capture(), streamObserverCapture.capture(), any());
AggregateQuerySnapshot snapshot = query.count().get().get();
@@ -187,10 +165,7 @@ public void shouldPropagateErrors() throws Exception {
Exception exception = new Exception();
doAnswer(aggregationQueryResponse(exception))
.when(firestoreMock)
- .streamRequest(
- runAggregationQuery.capture(),
- streamObserverCapture.capture(),
- Matchers.any());
+ .streamRequest(runAggregationQuery.capture(), streamObserverCapture.capture(), any());
ApiFuture future = query.count().get();
ExecutionException executionException = assertThrows(ExecutionException.class, future::get);
@@ -207,10 +182,7 @@ public void aggregateQueryGetQueryShouldReturnCorrectValue() throws Exception {
public void aggregateQuerySnapshotGetQueryShouldReturnCorrectValue() throws Exception {
doAnswer(aggregationQueryResponse())
.when(firestoreMock)
- .streamRequest(
- runAggregationQuery.capture(),
- streamObserverCapture.capture(),
- Matchers.any());
+ .streamRequest(runAggregationQuery.capture(), streamObserverCapture.capture(), any());
AggregateQuery aggregateQuery = query.count();
AggregateQuerySnapshot snapshot = aggregateQuery.get().get();
@@ -223,10 +195,7 @@ public void shouldNotRetryIfExceptionIsNotFirestoreException() {
doAnswer(aggregationQueryResponse(new NotFirestoreException()))
.doAnswer(aggregationQueryResponse())
.when(firestoreMock)
- .streamRequest(
- runAggregationQuery.capture(),
- streamObserverCapture.capture(),
- Matchers.any());
+ .streamRequest(runAggregationQuery.capture(), streamObserverCapture.capture(), any());
ApiFuture future = query.count().get();
@@ -238,10 +207,7 @@ public void shouldRetryIfExceptionIsFirestoreExceptionWithRetryableStatus() thro
doAnswer(aggregationQueryResponse(new FirestoreException("reason", Status.INTERNAL)))
.doAnswer(aggregationQueryResponse(42))
.when(firestoreMock)
- .streamRequest(
- runAggregationQuery.capture(),
- streamObserverCapture.capture(),
- Matchers.any());
+ .streamRequest(runAggregationQuery.capture(), streamObserverCapture.capture(), any());
ApiFuture future = query.count().get();
AggregateQuerySnapshot snapshot = future.get();
@@ -251,14 +217,10 @@ public void shouldRetryIfExceptionIsFirestoreExceptionWithRetryableStatus() thro
@Test
public void shouldNotRetryIfExceptionIsFirestoreExceptionWithNonRetryableStatus() {
- doReturn(Duration.ZERO).when(firestoreMock).getTotalRequestTimeout();
doAnswer(aggregationQueryResponse(new FirestoreException("reason", Status.INVALID_ARGUMENT)))
.doAnswer(aggregationQueryResponse())
.when(firestoreMock)
- .streamRequest(
- runAggregationQuery.capture(),
- streamObserverCapture.capture(),
- Matchers.any());
+ .streamRequest(runAggregationQuery.capture(), streamObserverCapture.capture(), any());
ApiFuture future = query.count().get();
@@ -273,10 +235,7 @@ public void shouldNotRetryIfExceptionIsFirestoreExceptionWithNonRetryableStatus(
doAnswer(aggregationQueryResponse(new FirestoreException("reason", Status.INTERNAL)))
.doAnswer(aggregationQueryResponse(42))
.when(firestoreMock)
- .streamRequest(
- runAggregationQuery.capture(),
- streamObserverCapture.capture(),
- Matchers.any());
+ .streamRequest(runAggregationQuery.capture(), streamObserverCapture.capture(), any());
ApiFuture future = query.count().get();
AggregateQuerySnapshot snapshot = future.get();
@@ -291,10 +250,7 @@ public void shouldRetryIfExceptionIsFirestoreExceptionWithRetryableStatusWithinT
doAnswer(aggregationQueryResponse(new FirestoreException("reason", Status.INTERNAL)))
.doAnswer(aggregationQueryResponse(42))
.when(firestoreMock)
- .streamRequest(
- runAggregationQuery.capture(),
- streamObserverCapture.capture(),
- Matchers.any());
+ .streamRequest(runAggregationQuery.capture(), streamObserverCapture.capture(), any());
ApiFuture future = query.count().get();
AggregateQuerySnapshot snapshot = future.get();
@@ -316,10 +272,7 @@ public void shouldRetryIfExceptionIsFirestoreExceptionWithRetryableStatusWithinT
doAnswer(aggregationQueryResponse(new FirestoreException("reason", Status.INTERNAL)))
.doAnswer(aggregationQueryResponse(42))
.when(firestoreMock)
- .streamRequest(
- runAggregationQuery.capture(),
- streamObserverCapture.capture(),
- Matchers.any());
+ .streamRequest(runAggregationQuery.capture(), streamObserverCapture.capture(), any());
ApiFuture future = query.count().get();
diff --git a/google-cloud-firestore/src/test/java/com/google/cloud/firestore/QueryTest.java b/google-cloud-firestore/src/test/java/com/google/cloud/firestore/QueryTest.java
index f1591c400f..f862b37f16 100644
--- a/google-cloud-firestore/src/test/java/com/google/cloud/firestore/QueryTest.java
+++ b/google-cloud-firestore/src/test/java/com/google/cloud/firestore/QueryTest.java
@@ -42,13 +42,13 @@
import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
+import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.doReturn;
import com.google.api.core.ApiClock;
import com.google.api.gax.rpc.ApiStreamObserver;
import com.google.api.gax.rpc.ResponseObserver;
-import com.google.api.gax.rpc.ServerStreamingCallable;
import com.google.cloud.Timestamp;
import com.google.cloud.firestore.Query.ComparisonFilterInternal;
import com.google.cloud.firestore.Query.FilterInternal;
@@ -77,10 +77,9 @@
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
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;
import org.threeten.bp.Duration;
@RunWith(MockitoJUnitRunner.class)
@@ -131,10 +130,7 @@ public void before() {
public void withLimit() throws Exception {
doAnswer(queryResponse())
.when(firestoreMock)
- .streamRequest(
- runQuery.capture(),
- streamObserverCapture.capture(),
- Matchers.any());
+ .streamRequest(runQuery.capture(), streamObserverCapture.capture(), any());
query.limit(42).get().get();
@@ -145,10 +141,7 @@ public void withLimit() throws Exception {
public void limitToLastReversesOrderingConstraints() throws Exception {
doAnswer(queryResponse())
.when(firestoreMock)
- .streamRequest(
- runQuery.capture(),
- streamObserverCapture.capture(),
- Matchers.any());
+ .streamRequest(runQuery.capture(), streamObserverCapture.capture(), any());
query.orderBy("foo").limitToLast(42).get().get();
@@ -160,10 +153,7 @@ public void limitToLastReversesOrderingConstraints() throws Exception {
public void limitToLastReversesCursors() throws Exception {
doAnswer(queryResponse())
.when(firestoreMock)
- .streamRequest(
- runQuery.capture(),
- streamObserverCapture.capture(),
- Matchers.any());
+ .streamRequest(runQuery.capture(), streamObserverCapture.capture(), any());
query.orderBy("foo").startAt("foo").endAt("bar").limitToLast(42).get().get();
@@ -180,10 +170,7 @@ public void limitToLastReversesCursors() throws Exception {
public void limitToLastReversesResults() throws Exception {
doAnswer(queryResponse(DOCUMENT_NAME + "2", DOCUMENT_NAME + "1"))
.when(firestoreMock)
- .streamRequest(
- runQuery.capture(),
- streamObserverCapture.capture(),
- Matchers.any());
+ .streamRequest(runQuery.capture(), streamObserverCapture.capture(), any());
QuerySnapshot querySnapshot = query.orderBy("foo").limitToLast(2).get().get();
@@ -194,13 +181,6 @@ public void limitToLastReversesResults() throws Exception {
@Test
public void limitToLastRequiresAtLeastOneOrderingConstraint() throws Exception {
- doAnswer(queryResponse())
- .when(firestoreMock)
- .streamRequest(
- runQuery.capture(),
- streamObserverCapture.capture(),
- Matchers.any());
-
try {
query.limitToLast(1).get().get();
fail("Expected exception");
@@ -213,13 +193,6 @@ public void limitToLastRequiresAtLeastOneOrderingConstraint() throws Exception {
@Test
public void limitToLastRejectsStream() {
- doAnswer(queryResponse())
- .when(firestoreMock)
- .streamRequest(
- runQuery.capture(),
- streamObserverCapture.capture(),
- Matchers.any());
-
try {
query.orderBy("foo").limitToLast(1).stream(null);
fail("Expected exception");
@@ -235,10 +208,7 @@ public void limitToLastRejectsStream() {
public void withOffset() throws Exception {
doAnswer(queryResponse())
.when(firestoreMock)
- .streamRequest(
- runQuery.capture(),
- streamObserverCapture.capture(),
- Matchers.any());
+ .streamRequest(runQuery.capture(), streamObserverCapture.capture(), any());
query.offset(42).get().get();
@@ -249,10 +219,7 @@ public void withOffset() throws Exception {
public void withFilter() throws Exception {
doAnswer(queryResponse())
.when(firestoreMock)
- .streamRequest(
- runQuery.capture(),
- streamObserverCapture.capture(),
- Matchers.any());
+ .streamRequest(runQuery.capture(), streamObserverCapture.capture(), any());
query.whereEqualTo("foo", "bar").get().get();
query.whereEqualTo("foo", null).get().get();
@@ -300,10 +267,7 @@ public void withFilter() throws Exception {
public void withFieldPathFilter() throws Exception {
doAnswer(queryResponse())
.when(firestoreMock)
- .streamRequest(
- runQuery.capture(),
- streamObserverCapture.capture(),
- Matchers.any());
+ .streamRequest(runQuery.capture(), streamObserverCapture.capture(), any());
query.whereEqualTo(FieldPath.of("foo"), "bar").get().get();
query.whereNotEqualTo(FieldPath.of("foo"), "bar").get().get();
@@ -339,10 +303,7 @@ public void withFieldPathFilter() throws Exception {
public void withCompositeFilter() throws Exception {
doAnswer(queryResponse())
.when(firestoreMock)
- .streamRequest(
- runQuery.capture(),
- streamObserverCapture.capture(),
- Matchers.any());
+ .streamRequest(runQuery.capture(), streamObserverCapture.capture(), any());
// a == 10 && (b==20 || c==30 || (d==40 && e>50) || f==60)
query
@@ -375,10 +336,7 @@ public void withCompositeFilter() throws Exception {
public void inQueriesWithReferenceArray() throws Exception {
doAnswer(queryResponse())
.when(firestoreMock)
- .streamRequest(
- runQuery.capture(),
- streamObserverCapture.capture(),
- Matchers.any());
+ .streamRequest(runQuery.capture(), streamObserverCapture.capture(), any());
query
.whereIn(FieldPath.documentId(), Arrays.asList("doc", firestoreMock.document("coll/doc")))
@@ -402,10 +360,7 @@ public void inQueriesWithReferenceArray() throws Exception {
public void inQueriesFieldsNotUsedInOrderBy() throws Exception {
doAnswer(queryResponse())
.when(firestoreMock)
- .streamRequest(
- runQuery.capture(),
- streamObserverCapture.capture(),
- Matchers.any());
+ .streamRequest(runQuery.capture(), streamObserverCapture.capture(), any());
// Field "foo" used in `whereIn` should not appear in implicit orderBys in the resulting query.
query
@@ -456,10 +411,7 @@ public void validatesInQueries() {
public void notInQueriesWithReferenceArray() throws Exception {
doAnswer(queryResponse())
.when(firestoreMock)
- .streamRequest(
- runQuery.capture(),
- streamObserverCapture.capture(),
- Matchers.any());
+ .streamRequest(runQuery.capture(), streamObserverCapture.capture(), any());
query
.whereNotIn(
@@ -517,7 +469,8 @@ public void validatesQueryOperatorForFieldPathDocumentId() {
fail();
} catch (IllegalArgumentException e) {
assertEquals(
- "Invalid query. You cannot perform 'ARRAY_CONTAINS_ANY' queries on FieldPath.documentId().",
+ "Invalid query. You cannot perform 'ARRAY_CONTAINS_ANY' queries on"
+ + " FieldPath.documentId().",
e.getMessage());
}
}
@@ -526,10 +479,7 @@ public void validatesQueryOperatorForFieldPathDocumentId() {
public void withDocumentIdFilter() throws Exception {
doAnswer(queryResponse())
.when(firestoreMock)
- .streamRequest(
- runQuery.capture(),
- streamObserverCapture.capture(),
- Matchers.any());
+ .streamRequest(runQuery.capture(), streamObserverCapture.capture(), any());
query.whereEqualTo(FieldPath.documentId(), "doc").get().get();
@@ -543,10 +493,7 @@ public void withDocumentIdFilter() throws Exception {
public void withOrderBy() throws Exception {
doAnswer(queryResponse())
.when(firestoreMock)
- .streamRequest(
- runQuery.capture(),
- streamObserverCapture.capture(),
- Matchers.any());
+ .streamRequest(runQuery.capture(), streamObserverCapture.capture(), any());
query.orderBy("foo").orderBy("foo.bar", Query.Direction.DESCENDING).get().get();
@@ -561,10 +508,7 @@ public void withOrderBy() throws Exception {
public void withFieldPathOrderBy() throws Exception {
doAnswer(queryResponse())
.when(firestoreMock)
- .streamRequest(
- runQuery.capture(),
- streamObserverCapture.capture(),
- Matchers.any());
+ .streamRequest(runQuery.capture(), streamObserverCapture.capture(), any());
query
.orderBy(FieldPath.of("foo"))
@@ -583,10 +527,7 @@ public void withFieldPathOrderBy() throws Exception {
public void withSelect() throws Exception {
doAnswer(queryResponse())
.when(firestoreMock)
- .streamRequest(
- runQuery.capture(),
- streamObserverCapture.capture(),
- Matchers.any());
+ .streamRequest(runQuery.capture(), streamObserverCapture.capture(), any());
query.select(new String[] {}).get().get();
query.select("foo", "foo.bar").get().get();
@@ -605,10 +546,7 @@ public void withSelect() throws Exception {
public void withFieldPathSelect() throws Exception {
doAnswer(queryResponse())
.when(firestoreMock)
- .streamRequest(
- runQuery.capture(),
- streamObserverCapture.capture(),
- Matchers.any());
+ .streamRequest(runQuery.capture(), streamObserverCapture.capture(), any());
query.select(new FieldPath[] {}).get().get();
query.select(FieldPath.of("foo"), FieldPath.of("foo", "bar")).get().get();
@@ -627,10 +565,7 @@ public void withFieldPathSelect() throws Exception {
public void withDocumentSnapshotCursor() {
doAnswer(queryResponse())
.when(firestoreMock)
- .streamRequest(
- runQuery.capture(),
- streamObserverCapture.capture(),
- Matchers.any());
+ .streamRequest(runQuery.capture(), streamObserverCapture.capture(), any());
query.startAt(SINGLE_FIELD_SNAPSHOT).get();
@@ -648,10 +583,7 @@ public void withDocumentSnapshotCursor() {
public void withDocumentIdAndDocumentSnapshotCursor() {
doAnswer(queryResponse())
.when(firestoreMock)
- .streamRequest(
- runQuery.capture(),
- streamObserverCapture.capture(),
- Matchers.any());
+ .streamRequest(runQuery.capture(), streamObserverCapture.capture(), any());
query.orderBy(FieldPath.documentId()).startAt(SINGLE_FIELD_SNAPSHOT).get();
@@ -669,10 +601,7 @@ public void withDocumentIdAndDocumentSnapshotCursor() {
public void withDocumentReferenceCursor() {
doAnswer(queryResponse())
.when(firestoreMock)
- .streamRequest(
- runQuery.capture(),
- streamObserverCapture.capture(),
- Matchers.any());
+ .streamRequest(runQuery.capture(), streamObserverCapture.capture(), any());
DocumentReference documentCursor = firestoreMock.document(DOCUMENT_PATH);
Value documentValue = reference(DOCUMENT_NAME);
@@ -689,10 +618,7 @@ public void withDocumentReferenceCursor() {
public void withExtractedDirectionForDocumentSnapshotCursor() {
doAnswer(queryResponse())
.when(firestoreMock)
- .streamRequest(
- runQuery.capture(),
- streamObserverCapture.capture(),
- Matchers.any());
+ .streamRequest(runQuery.capture(), streamObserverCapture.capture(), any());
query.orderBy("foo", Query.Direction.DESCENDING).startAt(SINGLE_FIELD_SNAPSHOT).get();
@@ -712,10 +638,7 @@ public void withExtractedDirectionForDocumentSnapshotCursor() {
public void withInequalityFilterForDocumentSnapshotCursor() {
doAnswer(queryResponse())
.when(firestoreMock)
- .streamRequest(
- runQuery.capture(),
- streamObserverCapture.capture(),
- Matchers.any());
+ .streamRequest(runQuery.capture(), streamObserverCapture.capture(), any());
query
.whereEqualTo("a", "b")
@@ -743,10 +666,7 @@ public void withInequalityFilterForDocumentSnapshotCursor() {
public void withEqualityFilterForDocumentSnapshotCursor() {
doAnswer(queryResponse())
.when(firestoreMock)
- .streamRequest(
- runQuery.capture(),
- streamObserverCapture.capture(),
- Matchers.any());
+ .streamRequest(runQuery.capture(), streamObserverCapture.capture(), any());
query.whereEqualTo("foo", "bar").startAt(SINGLE_FIELD_SNAPSHOT).get();
@@ -765,10 +685,7 @@ public void withEqualityFilterForDocumentSnapshotCursor() {
public void withStartAt() throws Exception {
doAnswer(queryResponse())
.when(firestoreMock)
- .streamRequest(
- runQuery.capture(),
- streamObserverCapture.capture(),
- Matchers.any());
+ .streamRequest(runQuery.capture(), streamObserverCapture.capture(), any());
query.orderBy("foo").orderBy(FieldPath.documentId()).startAt("bar", "doc").get().get();
@@ -819,10 +736,7 @@ public void withInvalidStartAt() {
public void withStartAfter() throws Exception {
doAnswer(queryResponse())
.when(firestoreMock)
- .streamRequest(
- runQuery.capture(),
- streamObserverCapture.capture(),
- Matchers.any());
+ .streamRequest(runQuery.capture(), streamObserverCapture.capture(), any());
query.orderBy("foo").startAfter("bar").get().get();
@@ -836,10 +750,7 @@ public void withStartAfter() throws Exception {
public void withEndBefore() throws Exception {
doAnswer(queryResponse())
.when(firestoreMock)
- .streamRequest(
- runQuery.capture(),
- streamObserverCapture.capture(),
- Matchers.any());
+ .streamRequest(runQuery.capture(), streamObserverCapture.capture(), any());
query.orderBy("foo").endBefore("bar").get().get();
@@ -853,10 +764,7 @@ public void withEndBefore() throws Exception {
public void withEndAt() throws Exception {
doAnswer(queryResponse())
.when(firestoreMock)
- .streamRequest(
- runQuery.capture(),
- streamObserverCapture.capture(),
- Matchers.any());
+ .streamRequest(runQuery.capture(), streamObserverCapture.capture(), any());
query.orderBy("foo").endAt("bar").get().get();
@@ -870,10 +778,7 @@ public void withEndAt() throws Exception {
public void withCollectionGroup() {
doAnswer(queryResponse())
.when(firestoreMock)
- .streamRequest(
- runQuery.capture(),
- streamObserverCapture.capture(),
- Matchers.any());
+ .streamRequest(runQuery.capture(), streamObserverCapture.capture(), any());
Query query = firestoreMock.collectionGroup(COLLECTION_ID);
query = query.whereGreaterThan(FieldPath.documentId(), "coll/doc");
@@ -917,10 +822,7 @@ public void orderByWithCursor() {
public void getResult() throws Exception {
doAnswer(queryResponse(DOCUMENT_NAME + "1", DOCUMENT_NAME + "2"))
.when(firestoreMock)
- .streamRequest(
- runQuery.capture(),
- streamObserverCapture.capture(),
- Matchers.any());
+ .streamRequest(runQuery.capture(), streamObserverCapture.capture(), any());
QuerySnapshot result = query.get().get();
@@ -965,10 +867,7 @@ public void getResult() throws Exception {
public void streamResult() throws Exception {
doAnswer(queryResponse(DOCUMENT_NAME + "1", DOCUMENT_NAME + "2"))
.when(firestoreMock)
- .streamRequest(
- runQuery.capture(),
- streamObserverCapture.capture(),
- Matchers.any());
+ .streamRequest(runQuery.capture(), streamObserverCapture.capture(), any());
final Semaphore semaphore = new Semaphore(0);
final Iterator iterator = Arrays.asList("doc1", "doc2").iterator();
@@ -1000,10 +899,7 @@ public void successfulReturnWithoutOnComplete() throws Exception {
queryResponseWithDone(
/* callWithoutOnComplete */ true, DOCUMENT_NAME + "1", DOCUMENT_NAME + "2"))
.when(firestoreMock)
- .streamRequest(
- runQuery.capture(),
- streamObserverCapture.capture(),
- Matchers.any());
+ .streamRequest(runQuery.capture(), streamObserverCapture.capture(), any());
final Semaphore semaphore = new Semaphore(0);
final Iterator iterator = Arrays.asList("doc1", "doc2").iterator();
@@ -1039,10 +935,7 @@ public void successfulReturnCallsOnCompleteTwice() throws Exception {
queryResponseWithDone(
/* callWithoutOnComplete */ false, DOCUMENT_NAME + "1", DOCUMENT_NAME + "2"))
.when(firestoreMock)
- .streamRequest(
- runQuery.capture(),
- streamObserverCapture.capture(),
- Matchers.any());
+ .streamRequest(runQuery.capture(), streamObserverCapture.capture(), any());
final Semaphore semaphore = new Semaphore(0);
final Iterator iterator = Arrays.asList("doc1", "doc2").iterator();
@@ -1093,10 +986,7 @@ public void retriesAfterRetryableError() throws Exception {
}
})
.when(firestoreMock)
- .streamRequest(
- runQuery.capture(),
- streamObserverCapture.capture(),
- Matchers.any());
+ .streamRequest(runQuery.capture(), streamObserverCapture.capture(), any());
// Verify the responses
final Semaphore semaphore = new Semaphore(0);
@@ -1147,10 +1037,7 @@ public void doesNotRetryAfterNonRetryableError() throws Exception {
DOCUMENT_NAME + "1",
DOCUMENT_NAME + "2"))
.when(firestoreMock)
- .streamRequest(
- runQuery.capture(),
- streamObserverCapture.capture(),
- Matchers.any());
+ .streamRequest(runQuery.capture(), streamObserverCapture.capture(), any());
// Verify the responses
final Semaphore semaphore = new Semaphore(0);
@@ -1185,10 +1072,7 @@ public void onlyRetriesWhenResultSent() throws Exception {
FirestoreException.forServerRejection(
Status.DEADLINE_EXCEEDED, "Simulated test failure")))
.when(firestoreMock)
- .streamRequest(
- runQuery.capture(),
- streamObserverCapture.capture(),
- Matchers.any());
+ .streamRequest(runQuery.capture(), streamObserverCapture.capture(), any());
assertThrows(ExecutionException.class, () -> query.get().get());
@@ -1217,10 +1101,7 @@ public void retriesWithoutTimeout() throws Exception {
}
})
.when(firestoreMock)
- .streamRequest(
- runQuery.capture(),
- streamObserverCapture.capture(),
- Matchers.any());
+ .streamRequest(runQuery.capture(), streamObserverCapture.capture(), any());
query.get().get();
@@ -1245,10 +1126,7 @@ public void doesNotRetryWithTimeout() {
.answer(invocation);
})
.when(firestoreMock)
- .streamRequest(
- runQuery.capture(),
- streamObserverCapture.capture(),
- Matchers.any());
+ .streamRequest(runQuery.capture(), streamObserverCapture.capture(), any());
assertThrows(ExecutionException.class, () -> query.get().get());
diff --git a/google-cloud-firestore/src/test/java/com/google/cloud/firestore/RateLimiterTest.java b/google-cloud-firestore/src/test/java/com/google/cloud/firestore/RateLimiterTest.java
index baf1423000..afc4874353 100644
--- a/google-cloud-firestore/src/test/java/com/google/cloud/firestore/RateLimiterTest.java
+++ b/google-cloud-firestore/src/test/java/com/google/cloud/firestore/RateLimiterTest.java
@@ -25,7 +25,7 @@
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
-import org.mockito.runners.MockitoJUnitRunner;
+import org.mockito.junit.MockitoJUnitRunner;
@RunWith(MockitoJUnitRunner.class)
public class RateLimiterTest {
diff --git a/google-cloud-firestore/src/test/java/com/google/cloud/firestore/RecursiveDeleteTest.java b/google-cloud-firestore/src/test/java/com/google/cloud/firestore/RecursiveDeleteTest.java
index 84713a679c..5d485c32b3 100644
--- a/google-cloud-firestore/src/test/java/com/google/cloud/firestore/RecursiveDeleteTest.java
+++ b/google-cloud-firestore/src/test/java/com/google/cloud/firestore/RecursiveDeleteTest.java
@@ -39,6 +39,7 @@
import static org.junit.Assert.fail;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.lenient;
import com.google.api.core.ApiAsyncFunction;
import com.google.api.core.ApiFuture;
@@ -76,11 +77,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;
import org.mockito.stubbing.Answer;
@RunWith(MockitoJUnitRunner.class)
@@ -113,7 +114,7 @@ public ScheduledFuture> schedule(Runnable command, long delay, TimeUnit unit)
@Before
public void before() {
- doReturn(immediateExecutor).when(firestoreRpc).getExecutor();
+ lenient().doReturn(immediateExecutor).when(firestoreRpc).getExecutor();
final ScheduledExecutorService timeoutExecutor =
new ScheduledThreadPoolExecutor(1) {
@@ -167,7 +168,7 @@ private void setupMocks(
.streamRequest(
runQueryCapture.capture(),
streamObserverCapture.capture(),
- Matchers.any());
+ ArgumentMatchers.any());
if (!deleteDocRef.equals("")) {
childrenDocuments = new ArrayList<>(childrenDocuments);
@@ -202,7 +203,7 @@ public void getAllDescendantsRootLevelCollection() throws Exception {
.streamRequest(
runQueryCapture.capture(),
streamObserverCapture.capture(),
- Matchers.any());
+ ArgumentMatchers.any());
RunQueryRequest expectedRequest =
query(
@@ -231,7 +232,7 @@ public void getAllDescendantsNestedCollection() throws Exception {
.streamRequest(
runQueryCapture.capture(),
streamObserverCapture.capture(),
- Matchers.any());
+ ArgumentMatchers.any());
RunQueryRequest expectedRequest =
query(
@@ -261,14 +262,14 @@ public void getAllDescendantsDocument() throws Exception {
.streamRequest(
runQueryCapture.capture(),
streamObserverCapture.capture(),
- Matchers.any());
+ ArgumentMatchers.any());
// Include dummy response for the deleted fullDocumentPath reference.
doAnswer((Answer>) mock -> successResponse(1))
.when(firestoreMock)
.sendRequest(
batchWriteCapture.capture(),
- Matchers.>any());
+ ArgumentMatchers.>any());
RunQueryRequest expectedRequest =
query(
@@ -294,13 +295,13 @@ public void createsRetryQueryAfterStreamExceptionWithLastReceivedDoc() throws Ex
.streamRequest(
runQueryCapture.capture(),
streamObserverCapture.capture(),
- Matchers.any());
+ ArgumentMatchers.any());
doAnswer(mock -> successResponse(1))
.when(firestoreMock)
.sendRequest(
batchWriteCapture.capture(),
- Matchers.>any());
+ ArgumentMatchers.>any());
RunQueryRequest expectedRequest =
query(
@@ -368,7 +369,7 @@ public void createsSecondQueryWithCorrectStartAfter() throws Exception {
.streamRequest(
runQueryCapture.capture(),
streamObserverCapture.capture(),
- Matchers.any());
+ ArgumentMatchers.any());
doAnswer(
mock -> {
@@ -399,7 +400,7 @@ public void createsSecondQueryWithCorrectStartAfter() throws Exception {
.when(firestoreMock)
.sendRequest(
batchWriteCapture.capture(),
- Matchers.>any());
+ ArgumentMatchers.>any());
BulkWriter bulkWriter = firestoreMock.bulkWriter();
bulkWriter.setMaxBatchSize(maxBatchSize);
@@ -564,12 +565,12 @@ public void exceptionThrownIfProvidedReferenceWasNotDeleted() throws Exception {
.streamRequest(
runQueryCapture.capture(),
streamObserverCapture.capture(),
- Matchers.any());
+ ArgumentMatchers.any());
doReturn(BulkWriterTest.FAILED_FUTURE)
.when(firestoreMock)
.sendRequest(
batchWriteCapture.capture(),
- Matchers.>any());
+ ArgumentMatchers.>any());
ApiFuture future = firestoreMock.recursiveDelete(firestoreMock.document("root/doc"));
try {
@@ -604,7 +605,7 @@ public void handlesSuccessfulStreamErrorRetries() throws Exception {
.streamRequest(
runQueryCapture.capture(),
streamObserverCapture.capture(),
- Matchers.any());
+ ArgumentMatchers.any());
ResponseStubber responseStubber =
new ResponseStubber() {
@@ -646,7 +647,7 @@ public void handlesMultipleCallsToRecursiveDelete() throws Exception {
.streamRequest(
runQueryCapture.capture(),
streamObserverCapture.capture(),
- Matchers.any());
+ ArgumentMatchers.any());
ResponseStubber responseStubber =
new ResponseStubber() {
@@ -671,7 +672,7 @@ public void usesSameBulkWriterInstanceAcrossCalls() throws Exception {
.streamRequest(
runQueryCapture.capture(),
streamObserverCapture.capture(),
- Matchers.any());
+ ArgumentMatchers.any());
final int[] callCount = {0};
final BulkWriter bulkWriter = firestoreMock.bulkWriter();
diff --git a/google-cloud-firestore/src/test/java/com/google/cloud/firestore/ToStringTest.java b/google-cloud-firestore/src/test/java/com/google/cloud/firestore/ToStringTest.java
index db0843f836..9dca2518e7 100644
--- a/google-cloud-firestore/src/test/java/com/google/cloud/firestore/ToStringTest.java
+++ b/google-cloud-firestore/src/test/java/com/google/cloud/firestore/ToStringTest.java
@@ -28,7 +28,7 @@
import org.junit.runner.RunWith;
import org.mockito.Mockito;
import org.mockito.Spy;
-import org.mockito.runners.MockitoJUnitRunner;
+import org.mockito.junit.MockitoJUnitRunner;
/** @author Eran Leshem */
@RunWith(MockitoJUnitRunner.class)
diff --git a/google-cloud-firestore/src/test/java/com/google/cloud/firestore/TransactionTest.java b/google-cloud-firestore/src/test/java/com/google/cloud/firestore/TransactionTest.java
index 7f9200222b..4c559486bc 100644
--- a/google-cloud-firestore/src/test/java/com/google/cloud/firestore/TransactionTest.java
+++ b/google-cloud-firestore/src/test/java/com/google/cloud/firestore/TransactionTest.java
@@ -77,10 +77,10 @@
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.Spy;
-import org.mockito.runners.MockitoJUnitRunner;
+import org.mockito.junit.MockitoJUnitRunner;
@SuppressWarnings("deprecation")
@RunWith(MockitoJUnitRunner.class)
@@ -132,7 +132,8 @@ public void returnsValue() throws Exception {
doReturn(beginResponse())
.doReturn(commitResponse(0, 0))
.when(firestoreMock)
- .sendRequest(requestCapture.capture(), Matchers.>any());
+ .sendRequest(
+ requestCapture.capture(), ArgumentMatchers.>any());
ApiFuture transaction =
firestoreMock.runTransaction(
@@ -156,7 +157,8 @@ public void returnsValueAsync() throws Exception {
doReturn(beginResponse())
.doReturn(commitResponse(0, 0))
.when(firestoreMock)
- .sendRequest(requestCapture.capture(), Matchers.>any());
+ .sendRequest(
+ requestCapture.capture(), ArgumentMatchers.>any());
ApiFuture transaction =
firestoreMock.runAsyncTransaction(
@@ -180,7 +182,8 @@ public void canReturnNull() throws Exception {
doReturn(beginResponse())
.doReturn(commitResponse(0, 0))
.when(firestoreMock)
- .sendRequest(requestCapture.capture(), Matchers.>any());
+ .sendRequest(
+ requestCapture.capture(), ArgumentMatchers.>any());
ApiFuture transaction = firestoreMock.runTransaction(transaction1 -> null, options);
@@ -192,7 +195,8 @@ public void canReturnNullAsync() throws Exception {
doReturn(beginResponse())
.doReturn(commitResponse(0, 0))
.when(firestoreMock)
- .sendRequest(requestCapture.capture(), Matchers.>any());
+ .sendRequest(
+ requestCapture.capture(), ArgumentMatchers.>any());
ApiFuture transaction =
firestoreMock.runAsyncTransaction(t -> ApiFutures.immediateFuture(null), options);
@@ -205,7 +209,8 @@ public void rollbackOnCallbackError() {
doReturn(beginResponse())
.doReturn(rollbackResponse())
.when(firestoreMock)
- .sendRequest(requestCapture.capture(), Matchers.>any());
+ .sendRequest(
+ requestCapture.capture(), ArgumentMatchers.>any());
ApiFuture transaction =
firestoreMock.runTransaction(
@@ -233,7 +238,8 @@ public void rollbackOnCallbackApiFutureErrorAsync() {
doReturn(beginResponse())
.doReturn(rollbackResponse())
.when(firestoreMock)
- .sendRequest(requestCapture.capture(), Matchers.>any());
+ .sendRequest(
+ requestCapture.capture(), ArgumentMatchers.>any());
ApiFuture transaction =
firestoreMock.runAsyncTransaction(
@@ -257,7 +263,8 @@ public void rollbackOnCallbackApiFutureErrorAsync() {
public void noRollbackOnBeginFailure() {
doReturn(ApiFutures.immediateFailedFuture(new Exception("Expected exception")))
.when(firestoreMock)
- .sendRequest(requestCapture.capture(), Matchers.>any());
+ .sendRequest(
+ requestCapture.capture(), ArgumentMatchers.>any());
ApiFuture transaction =
firestoreMock.runTransaction(
@@ -282,7 +289,8 @@ public void noRollbackOnBeginFailure() {
public void noRollbackOnBeginFailureAsync() {
doReturn(ApiFutures.immediateFailedFuture(new Exception("Expected exception")))
.when(firestoreMock)
- .sendRequest(requestCapture.capture(), Matchers.>any());
+ .sendRequest(
+ requestCapture.capture(), ArgumentMatchers.>any());
ApiFuture transaction =
firestoreMock.runAsyncTransaction(
@@ -308,7 +316,8 @@ public void noRollbackOnThrownExceptionAsync() {
doReturn(beginResponse())
.doReturn(rollbackResponse())
.when(firestoreMock)
- .sendRequest(requestCapture.capture(), Matchers.>any());
+ .sendRequest(
+ requestCapture.capture(), ArgumentMatchers.