Skip to content
This repository was archived by the owner on Aug 30, 2026. It is now read-only.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,20 +50,20 @@ If you are using Maven without the BOM, add this to your dependencies:
If you are using Gradle 5.x or later, add this to your dependencies:

```Groovy
implementation platform('com.google.cloud:libraries-bom:26.15.0')
implementation platform('com.google.cloud:libraries-bom:26.16.0')

implementation 'com.google.cloud:google-cloud-firestore'
```
If you are using Gradle without BOM, add this to your dependencies:

```Groovy
implementation 'com.google.cloud:google-cloud-firestore:3.11.0'
implementation 'com.google.cloud:google-cloud-firestore:3.12.1'
```

If you are using SBT, add this to your dependencies:

```Scala
libraryDependencies += "com.google.cloud" % "google-cloud-firestore" % "3.11.0"
libraryDependencies += "com.google.cloud" % "google-cloud-firestore" % "3.12.1"
```
<!-- {x-version-update-end} -->

Expand Down Expand Up @@ -222,7 +222,7 @@ Java is a registered trademark of Oracle and/or its affiliates.
[kokoro-badge-link-5]: http://storage.googleapis.com/cloud-devrel-public/java/badges/java-firestore/java11.html
[stability-image]: https://img.shields.io/badge/stability-stable-green
[maven-version-image]: https://img.shields.io/maven-central/v/com.google.cloud/google-cloud-firestore.svg
[maven-version-link]: https://central.sonatype.com/artifact/com.google.cloud/google-cloud-firestore/3.11.0
[maven-version-link]: https://central.sonatype.com/artifact/com.google.cloud/google-cloud-firestore/3.12.1
[authentication]: https://github.com/googleapis/google-cloud-java#authentication
[auth-scopes]: https://developers.google.com/identity/protocols/oauth2/scopes
[predefined-iam-roles]: https://cloud.google.com/iam/docs/understanding-roles#predefined_roles
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -448,4 +448,11 @@ public boolean equals(Object obj) {
public int hashCode() {
return Objects.hash(rpcContext, docRef, fields);
}

@Override
public String toString() {
return String.format(
"%s{doc=%s, fields=%s, readTime=%s, updateTime=%s, createTime=%s}",
getClass().getSimpleName(), docRef, fields, readTime, updateTime, createTime);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ static class WriteOperation {
this.documentReference = documentReference;
this.write = write;
}

@Override
public String toString() {
return String.format("WriteOperation{write=%s, doc=%s}", write, documentReference);
}
}

final FirestoreImpl firestore;
Expand Down Expand Up @@ -646,4 +651,10 @@ List<WriteOperation> getWrites() {
public int getMutationsSize() {
return writes.size();
}

@Override
public String toString() {
return String.format(
"%s{writes=%s, committed=%s}", getClass().getSimpleName(), writes, committed);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
/*
* Copyright 2023 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License 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.google.cloud.firestore;

import static com.google.common.truth.Truth.assertThat;

import com.google.cloud.Timestamp;
import com.google.cloud.firestore.spi.v1.FirestoreRpc;
import com.google.firestore.v1.Value;
import java.util.Collections;
import java.util.Map;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mockito;
import org.mockito.Spy;
import org.mockito.runners.MockitoJUnitRunner;

/** @author Eran Leshem */
@RunWith(MockitoJUnitRunner.class)
public class ToStringTest {

@Spy
private final FirestoreImpl firestoreMock =
new FirestoreImpl(
FirestoreOptions.newBuilder().setProjectId("test-project").build(),
Mockito.mock(FirestoreRpc.class));

private WriteBatch batch;
private DocumentReference documentReference;

@Before
public void before() {
batch = firestoreMock.batch();
documentReference = firestoreMock.document("coll/doc");
}

@Test
public void testDocumentSnapshot() {
Map<String, Value> fields =
Collections.singletonMap(
"key123",
UserDataConverter.encodeValue(
FieldPath.of("key456"),
CustomClassMapper.convertToPlainJavaTypes("value789"),
UserDataConverter.NO_DELETES));
String toStringResult =
new DocumentSnapshot(
null,
documentReference,
fields,
Timestamp.ofTimeMicroseconds(1),
Timestamp.ofTimeMicroseconds(2),
Timestamp.ofTimeMicroseconds(3))
.toString();
assertThat(toStringResult).startsWith("DocumentSnapshot{");
assertThat(toStringResult).containsMatch("doc=DocumentReference\\{path=.*/documents/coll/doc}");
assertThat(toStringResult).containsMatch("(?s)fields=\\{key123=string_value:.*value789.*}");
assertThat(toStringResult).contains("readTime=1970-01-01T00:00:00.000001000Z");
assertThat(toStringResult).contains("updateTime=1970-01-01T00:00:00.000002000Z");
assertThat(toStringResult).contains("createTime=1970-01-01T00:00:00.000003000Z");
assertThat(toStringResult).endsWith("}");
}

@Test
public void testWriteOperation() {
String toStringResult =
new UpdateBuilder.WriteOperation(
documentReference,
DocumentSnapshot.fromObject(
null,
documentReference,
Collections.singletonMap("key", "value"),
UserDataConverter.NO_DELETES)
.toPb())
.toString();
assertThat(toStringResult).startsWith("WriteOperation{");
assertThat(toStringResult)
.containsMatch("(?s)write=update\\s*\\{\\s*name:.*/documents/coll/doc.*}");
assertThat(toStringResult).containsMatch("doc=DocumentReference\\{path=.*/documents/coll/doc}");
assertThat(toStringResult).endsWith("}");
}

@Test
public void testWriteBatch() {
batch.update(documentReference, Collections.singletonMap("key", "value"));
String toStringResult = batch.toString();
assertThat(toStringResult).startsWith("WriteBatch{");
assertThat(toStringResult)
.containsMatch("(?s)writes=\\[WriteOperation\\{write=update.*/documents/coll/doc.*}]");
assertThat(toStringResult).contains("committed=false");
assertThat(toStringResult).endsWith("}");
}
}