From ae4648662f8c108b338dbf36b6534907cc119ea7 Mon Sep 17 00:00:00 2001
From: eranl <1707552+eranl@users.noreply.github.com>
Date: Sat, 23 Sep 2023 21:10:30 +0300
Subject: [PATCH 02/51] Add support for java record serialization - use field
annotations
---
google-cloud-firestore-jdk17/pom.xml | 4 +-
.../jdk17/annotation/DocumentId.java | 46 ------------
.../jdk17/annotation/PropertyName.java | 30 --------
.../jdk17/annotation/ServerTimestamp.java | 31 --------
.../cloud/firestore/RecordMapperTest.java | 6 +-
.../firestore/jdk17/LocalFirestoreHelper.java | 4 +-
.../google/cloud/firestore/BeanMapper.java | 52 +++++++++++++
.../cloud/firestore/CustomClassMapper.java | 53 +-------------
.../google/cloud/firestore/RecordMapper.java | 73 +++----------------
9 files changed, 73 insertions(+), 226 deletions(-)
delete mode 100644 google-cloud-firestore-jdk17/src/main/java/com/google/cloud/firestore/jdk17/annotation/DocumentId.java
delete mode 100644 google-cloud-firestore-jdk17/src/main/java/com/google/cloud/firestore/jdk17/annotation/PropertyName.java
delete mode 100644 google-cloud-firestore-jdk17/src/main/java/com/google/cloud/firestore/jdk17/annotation/ServerTimestamp.java
diff --git a/google-cloud-firestore-jdk17/pom.xml b/google-cloud-firestore-jdk17/pom.xml
index e1b7cf5a2..060de6b89 100644
--- a/google-cloud-firestore-jdk17/pom.xml
+++ b/google-cloud-firestore-jdk17/pom.xml
@@ -64,8 +64,8 @@
org.mockito
- mockito-all
- 1.10.19
+ mockito-core
+ 2.25.0
test
diff --git a/google-cloud-firestore-jdk17/src/main/java/com/google/cloud/firestore/jdk17/annotation/DocumentId.java b/google-cloud-firestore-jdk17/src/main/java/com/google/cloud/firestore/jdk17/annotation/DocumentId.java
deleted file mode 100644
index 16729b7af..000000000
--- a/google-cloud-firestore-jdk17/src/main/java/com/google/cloud/firestore/jdk17/annotation/DocumentId.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * Copyright 2019 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.jdk17.annotation;
-
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-
-/**
- * Annotation used to mark a record component to be automatically populated with the document's ID
- * when the record is created from a Cloud Firestore document (for example, via
- * DocumentSnapshot#toObject).
- *
- *
- * Any of the following will throw a runtime exception:
- * This annotation is applied to a property of a type other than String or DocumentReference.
- * This annotation is applied to a property with a name that conflicts with a read document
- * component. For example, if a record has a component `firstName` annotated by @DocumentId,
- * and there is a property from the document named `firstName` as well, an exception is thrown
- * when you try to read the document into the record via DocumentSnapshot#toObject or
- * DocumentReference#get.
- *
- *
- *
- * When using a record to write to a document (via DocumentReference#set or WriteBatch#set), the
- * property annotated by @DocumentId is ignored, which allows writing the record back to any
- * document, even if it's not the origin of the record.
- */
-@Retention(RetentionPolicy.RUNTIME)
-@Target(ElementType.RECORD_COMPONENT)
-public @interface DocumentId {}
diff --git a/google-cloud-firestore-jdk17/src/main/java/com/google/cloud/firestore/jdk17/annotation/PropertyName.java b/google-cloud-firestore-jdk17/src/main/java/com/google/cloud/firestore/jdk17/annotation/PropertyName.java
deleted file mode 100644
index b453701c3..000000000
--- a/google-cloud-firestore-jdk17/src/main/java/com/google/cloud/firestore/jdk17/annotation/PropertyName.java
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- * Copyright 2017 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.jdk17.annotation;
-
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-
-/** Marks a component to be renamed when serialized. */
-@Retention(RetentionPolicy.RUNTIME)
-@Target(ElementType.RECORD_COMPONENT)
-public @interface PropertyName {
-
- String value();
-}
diff --git a/google-cloud-firestore-jdk17/src/main/java/com/google/cloud/firestore/jdk17/annotation/ServerTimestamp.java b/google-cloud-firestore-jdk17/src/main/java/com/google/cloud/firestore/jdk17/annotation/ServerTimestamp.java
deleted file mode 100644
index f94f84389..000000000
--- a/google-cloud-firestore-jdk17/src/main/java/com/google/cloud/firestore/jdk17/annotation/ServerTimestamp.java
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
- * Copyright 2017 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.jdk17.annotation;
-
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-
-/**
- * Annotation used to mark a timestamp component as being populated via Server Timestamps. If a
- * record being written contains null for a @ServerTimestamp annotated component, it will be
- * replaced with a server-generated timestamp.
- */
-@Retention(RetentionPolicy.RUNTIME)
-@Target(ElementType.RECORD_COMPONENT)
-public @interface ServerTimestamp {}
diff --git a/google-cloud-firestore-jdk17/src/test/java/com/google/cloud/firestore/RecordMapperTest.java b/google-cloud-firestore-jdk17/src/test/java/com/google/cloud/firestore/RecordMapperTest.java
index af5e742d3..19c261a6b 100644
--- a/google-cloud-firestore-jdk17/src/test/java/com/google/cloud/firestore/RecordMapperTest.java
+++ b/google-cloud-firestore-jdk17/src/test/java/com/google/cloud/firestore/RecordMapperTest.java
@@ -28,18 +28,18 @@
import java.util.Map;
import java.util.Set;
+import com.google.cloud.firestore.annotation.DocumentId;
+import com.google.cloud.firestore.annotation.PropertyName;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mockito;
import org.mockito.Spy;
-import org.mockito.runners.MockitoJUnitRunner;
import com.google.cloud.firestore.annotation.ThrowOnExtraProperties;
-import com.google.cloud.firestore.jdk17.annotation.DocumentId;
-import com.google.cloud.firestore.jdk17.annotation.PropertyName;
import com.google.cloud.firestore.spi.v1.FirestoreRpc;
import com.google.common.collect.ImmutableList;
import com.google.firestore.v1.DatabaseRootName;
+import org.mockito.junit.MockitoJUnitRunner;
import static com.google.cloud.firestore.jdk17.LocalFirestoreHelper.fromSingleQuotedString;
import static com.google.cloud.firestore.jdk17.LocalFirestoreHelper.mapAnyType;
diff --git a/google-cloud-firestore-jdk17/src/test/java/com/google/cloud/firestore/jdk17/LocalFirestoreHelper.java b/google-cloud-firestore-jdk17/src/test/java/com/google/cloud/firestore/jdk17/LocalFirestoreHelper.java
index adeeb0cf9..bf34b1ecb 100644
--- a/google-cloud-firestore-jdk17/src/test/java/com/google/cloud/firestore/jdk17/LocalFirestoreHelper.java
+++ b/google-cloud-firestore-jdk17/src/test/java/com/google/cloud/firestore/jdk17/LocalFirestoreHelper.java
@@ -101,13 +101,13 @@ public record NestedRecord(
public record ServerTimestamp (
- @com.google.cloud.firestore.jdk17.annotation.ServerTimestamp Date foo,
+ @com.google.cloud.firestore.annotation.ServerTimestamp Date foo,
Inner inner
){
record Inner (
- @com.google.cloud.firestore.jdk17.annotation.ServerTimestamp Date bar
+ @com.google.cloud.firestore.annotation.ServerTimestamp Date bar
){}
}
diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/BeanMapper.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/BeanMapper.java
index 7f49d1b6a..dc804a640 100644
--- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/BeanMapper.java
+++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/BeanMapper.java
@@ -16,12 +16,21 @@
package com.google.cloud.firestore;
+import com.google.cloud.Timestamp;
+import com.google.cloud.firestore.annotation.DocumentId;
import com.google.cloud.firestore.annotation.IgnoreExtraProperties;
+import com.google.cloud.firestore.annotation.PropertyName;
+import com.google.cloud.firestore.annotation.ServerTimestamp;
import com.google.cloud.firestore.annotation.ThrowOnExtraProperties;
+
+import java.lang.reflect.AccessibleObject;
+import java.lang.reflect.Field;
import java.lang.reflect.Type;
import java.lang.reflect.TypeVariable;
import java.util.Collection;
import java.util.Collections;
+import java.util.Date;
+import java.util.HashSet;
import java.util.Map;
/** Base bean mapper class, providing common functionality for class and record serialization. */
@@ -33,11 +42,19 @@ abstract class BeanMapper {
// Whether to log a message if there are properties we don't know how to set to
// custom object fields/setters or record components during deserialization.
private final boolean warnOnUnknownProperties;
+ // A set of property names that were annotated with @ServerTimestamp.
+ final HashSet serverTimestamps;
+ // A set of property names that were annotated with @DocumentId. These properties will be
+ // populated with document ID values during deserialization, and be skipped during
+ // serialization.
+ final HashSet documentIdPropertyNames;
BeanMapper(Class clazz) {
this.clazz = clazz;
throwOnUnknownProperties = clazz.isAnnotationPresent(ThrowOnExtraProperties.class);
warnOnUnknownProperties = !clazz.isAnnotationPresent(IgnoreExtraProperties.class);
+ serverTimestamps = new HashSet<>();
+ documentIdPropertyNames = new HashSet<>();
}
Class getClazz() {
@@ -128,4 +145,39 @@ void checkForDocIdConflict(
T deserialize(Map values, DeserializeContext context) {
return deserialize(values, Collections.emptyMap(), context);
}
+
+ void applyFieldAnnotations(Field field) {
+ if (field.isAnnotationPresent(ServerTimestamp.class)) {
+ Class> fieldType = field.getType();
+ if (fieldType != Date.class && fieldType != Timestamp.class) {
+ throw new IllegalArgumentException(
+ "Field "
+ + field.getName()
+ + " is annotated with @ServerTimestamp but is "
+ + fieldType
+ + " instead of Date or Timestamp.");
+ }
+ serverTimestamps.add(propertyName(field));
+ }
+
+ if (field.isAnnotationPresent(DocumentId.class)) {
+ Class> fieldType = field.getType();
+ ensureValidDocumentIdType("Field", "is", fieldType);
+ documentIdPropertyNames.add(propertyName(field));
+ }
+ }
+
+ static String propertyName(Field field) {
+ String annotatedName = annotatedName(field);
+ return annotatedName != null ? annotatedName : field.getName();
+ }
+
+ static String annotatedName(AccessibleObject obj) {
+ if (obj.isAnnotationPresent(PropertyName.class)) {
+ PropertyName annotation = obj.getAnnotation(PropertyName.class);
+ return annotation.value();
+ }
+
+ return null;
+ }
}
diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/CustomClassMapper.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/CustomClassMapper.java
index a864b9ad1..17fea2d12 100644
--- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/CustomClassMapper.java
+++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/CustomClassMapper.java
@@ -19,10 +19,9 @@
import com.google.cloud.Timestamp;
import com.google.cloud.firestore.annotation.DocumentId;
import com.google.cloud.firestore.annotation.Exclude;
-import com.google.cloud.firestore.annotation.PropertyName;
import com.google.cloud.firestore.annotation.ServerTimestamp;
import com.google.firestore.v1.Value;
-import java.lang.reflect.AccessibleObject;
+
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.GenericArrayType;
@@ -161,7 +160,7 @@ static Object serialize(T o, DeserializeContext.ErrorPath path) {
String enumName = ((Enum>) o).name();
try {
Field enumField = o.getClass().getField(enumName);
- return PojoBeanMapper.propertyName(enumField);
+ return BeanMapper.propertyName(enumField);
} catch (NoSuchFieldException ex) {
return enumName;
}
@@ -376,7 +375,7 @@ private static T deserializeToEnum(
Field[] enumFields = clazz.getFields();
for (Field field : enumFields) {
if (field.isEnumConstant()) {
- String propertyName = PojoBeanMapper.propertyName(field);
+ String propertyName = BeanMapper.propertyName(field);
if (value.equals(propertyName)) {
value = field.getName();
break;
@@ -638,14 +637,6 @@ private static class PojoBeanMapper extends BeanMapper {
private final Map setters;
private final Map fields;
- // A set of property names that were annotated with @ServerTimestamp.
- private final HashSet serverTimestamps;
-
- // A set of property names that were annotated with @DocumentId. These properties will be
- // populated with document ID values during deserialization, and be skipped during
- // serialization.
- private final HashSet documentIdPropertyNames;
-
PojoBeanMapper(Class clazz) {
super(clazz);
properties = new HashMap<>();
@@ -654,9 +645,6 @@ private static class PojoBeanMapper extends BeanMapper {
getters = new HashMap<>();
fields = new HashMap<>();
- serverTimestamps = new HashSet<>();
- documentIdPropertyNames = new HashSet<>();
-
Constructor constructor;
try {
constructor = clazz.getDeclaredConstructor();
@@ -943,27 +931,6 @@ Map serialize(T object, DeserializeContext.ErrorPath path) {
return result;
}
- private void applyFieldAnnotations(Field field) {
- if (field.isAnnotationPresent(ServerTimestamp.class)) {
- Class> fieldType = field.getType();
- if (fieldType != Date.class && fieldType != Timestamp.class) {
- throw new IllegalArgumentException(
- "Field "
- + field.getName()
- + " is annotated with @ServerTimestamp but is "
- + fieldType
- + " instead of Date or Timestamp.");
- }
- serverTimestamps.add(propertyName(field));
- }
-
- if (field.isAnnotationPresent(DocumentId.class)) {
- Class> fieldType = field.getType();
- ensureValidDocumentIdType("Field", "is", fieldType);
- documentIdPropertyNames.add(propertyName(field));
- }
- }
-
private void applyGetterAnnotations(Method method) {
if (method.isAnnotationPresent(ServerTimestamp.class)) {
Class> returnType = method.getReturnType();
@@ -1101,25 +1068,11 @@ private static boolean isSetterOverride(Method base, Method override) {
&& baseParameterTypes[0].equals(overrideParameterTypes[0]);
}
- private static String propertyName(Field field) {
- String annotatedName = annotatedName(field);
- return annotatedName != null ? annotatedName : field.getName();
- }
-
private static String propertyName(Method method) {
String annotatedName = annotatedName(method);
return annotatedName != null ? annotatedName : serializedName(method.getName());
}
- private static String annotatedName(AccessibleObject obj) {
- if (obj.isAnnotationPresent(PropertyName.class)) {
- PropertyName annotation = obj.getAnnotation(PropertyName.class);
- return annotation.value();
- }
-
- return null;
- }
-
private static String serializedName(String methodName) {
String[] prefixes = new String[] {"get", "set", "is"};
String methodPrefix = null;
diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/RecordMapper.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/RecordMapper.java
index 114e220bc..138d67330 100644
--- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/RecordMapper.java
+++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/RecordMapper.java
@@ -16,20 +16,17 @@
package com.google.cloud.firestore;
-import com.google.cloud.Timestamp;
-import java.lang.annotation.Annotation;
import java.lang.reflect.AnnotatedElement;
import java.lang.reflect.Constructor;
+import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Type;
import java.lang.reflect.TypeVariable;
import java.util.Arrays;
-import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
-import java.util.Optional;
import java.util.Set;
import java.util.logging.Logger;
@@ -54,12 +51,6 @@ class RecordMapper extends BeanMapper {
private final Map accessors = new HashMap<>();
private final Constructor constructor;
private final Map constructorParamIndexes = new HashMap<>();
- // A set of property names that were annotated with @ServerTimestamp.
- private final Set serverTimestamps = new HashSet<>();
- // A set of property names that were annotated with @DocumentId. These properties will be
- // populated with document ID values during deserialization, and be skipped during
- // serialization.
- private final Set documentIdPropertyNames = new HashSet<>();
RecordMapper(Class clazz) {
super(clazz);
@@ -71,12 +62,16 @@ class RecordMapper extends BeanMapper {
throw new RuntimeException("No properties to serialize found on class " + clazz.getName());
}
- for (int i = 0; i < recordComponents.length; i++) {
- AnnotatedElement recordComponent = recordComponents[i];
- String propertyName = propertyName(recordComponent);
- constructorParamIndexes.put(propertyName, i);
- accessors.put(propertyName, RECORD_INSPECTOR.getAccessor(recordComponent));
- applyComponentAnnotations(recordComponent);
+ try {
+ for (int i = 0; i < recordComponents.length; i++) {
+ Field field = clazz.getDeclaredField(RECORD_INSPECTOR.getName(recordComponents[i]));
+ String propertyName = propertyName(field);
+ constructorParamIndexes.put(propertyName, i);
+ accessors.put(propertyName, RECORD_INSPECTOR.getAccessor(recordComponents[i]));
+ applyFieldAnnotations(field);
+ }
+ } catch (NoSuchFieldException e) {
+ throw new RuntimeException(e);
}
}
@@ -151,52 +146,6 @@ T deserialize(
}
}
- private void applyComponentAnnotations(AnnotatedElement component) {
- if (isAnnotationPresent(component, "ServerTimestamp")) {
- Class> componentType = RECORD_INSPECTOR.getType(component);
- if (componentType != Date.class && componentType != Timestamp.class) {
- throw new IllegalArgumentException(
- "Component "
- + RECORD_INSPECTOR.getName(component)
- + " is annotated with @ServerTimestamp but is "
- + componentType
- + " instead of Date or Timestamp.");
- }
- serverTimestamps.add(propertyName(component));
- }
-
- if (isAnnotationPresent(component, "DocumentId")) {
- Class> type = RECORD_INSPECTOR.getType(component);
- ensureValidDocumentIdType("Component", "is", type);
- documentIdPropertyNames.add(propertyName(component));
- }
- }
-
- private static String propertyName(AnnotatedElement component) {
- Optional propertyName = getAnnotation(component, "PropertyName");
- if (propertyName.isPresent()) {
- Annotation annotation = propertyName.get();
- try {
- return (String) annotation.getClass().getMethod("value").invoke(annotation);
- } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
- throw new IllegalArgumentException("Failed to get PropertyName annotation value", e);
- }
- }
-
- return RECORD_INSPECTOR.getName(component);
- }
-
- private static boolean isAnnotationPresent(AnnotatedElement element, String annotationName) {
- return getAnnotation(element, annotationName).isPresent();
- }
-
- private static Optional getAnnotation(
- AnnotatedElement element, String annotationName) {
- return Arrays.stream(element.getAnnotations())
- .filter(annotation -> annotation.annotationType().getSimpleName().equals(annotationName))
- .findAny();
- }
-
// Populate @DocumentId annotated components. If there is a conflict (@DocumentId annotation is
// applied to a property that is already deserialized from the firestore document)
// a runtime exception will be thrown.
From b50fc2549c1e3d7310b719eec7069d95e122ef36 Mon Sep 17 00:00:00 2001
From: eranl <1707552+eranl@users.noreply.github.com>
Date: Sat, 23 Sep 2023 22:45:00 +0300
Subject: [PATCH 03/51] Add support for java record serialization - update doc
---
.../main/java/com/google/cloud/firestore/RecordMapper.java | 7 ++-----
1 file changed, 2 insertions(+), 5 deletions(-)
diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/RecordMapper.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/RecordMapper.java
index 138d67330..d315bbaf5 100644
--- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/RecordMapper.java
+++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/RecordMapper.java
@@ -33,11 +33,8 @@
/**
* Serializes java records. Uses automatic record constructors and accessors only. Therefore,
* exclusion of fields is not supported. Supports DocumentId, PropertyName, and ServerTimestamp
- * annotations on record components. However, those annotations have to
- * include @Target(ElementType.RECORD_COMPONENT), so the ones defined in the
- * google-cloud-firestore-jdk17 module should be used, rather than the ones defined in this module.
- * Since records are not supported in JDK8, reflection is used for inspecting record metadata. This
- * class will fail to load on java versions that don't support records.
+ * annotations on record components.
+ * Since records are not supported in JDK versions < 16, reflection is used for inspecting record metadata.
*
* @author Eran Leshem
*/
From d050e2425d46b817dc5908a0dd6146c338dc03ae Mon Sep 17 00:00:00 2001
From: eranl <1707552+eranl@users.noreply.github.com>
Date: Sat, 28 Oct 2023 04:08:42 +0300
Subject: [PATCH 04/51] Add support for java record serialization - fix
formatting
---
.../src/main/java/com/google/cloud/firestore/BeanMapper.java | 1 -
.../java/com/google/cloud/firestore/CustomClassMapper.java | 1 -
.../main/java/com/google/cloud/firestore/RecordMapper.java | 4 ++--
3 files changed, 2 insertions(+), 4 deletions(-)
diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/BeanMapper.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/BeanMapper.java
index dc804a640..ef25554bc 100644
--- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/BeanMapper.java
+++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/BeanMapper.java
@@ -22,7 +22,6 @@
import com.google.cloud.firestore.annotation.PropertyName;
import com.google.cloud.firestore.annotation.ServerTimestamp;
import com.google.cloud.firestore.annotation.ThrowOnExtraProperties;
-
import java.lang.reflect.AccessibleObject;
import java.lang.reflect.Field;
import java.lang.reflect.Type;
diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/CustomClassMapper.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/CustomClassMapper.java
index 17fea2d12..0011555c6 100644
--- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/CustomClassMapper.java
+++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/CustomClassMapper.java
@@ -21,7 +21,6 @@
import com.google.cloud.firestore.annotation.Exclude;
import com.google.cloud.firestore.annotation.ServerTimestamp;
import com.google.firestore.v1.Value;
-
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.GenericArrayType;
diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/RecordMapper.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/RecordMapper.java
index d315bbaf5..0dd4ae909 100644
--- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/RecordMapper.java
+++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/RecordMapper.java
@@ -33,8 +33,8 @@
/**
* Serializes java records. Uses automatic record constructors and accessors only. Therefore,
* exclusion of fields is not supported. Supports DocumentId, PropertyName, and ServerTimestamp
- * annotations on record components.
- * Since records are not supported in JDK versions < 16, reflection is used for inspecting record metadata.
+ * annotations on record components. Since records are not supported in JDK versions < 16,
+ * reflection is used for inspecting record metadata.
*
* @author Eran Leshem
*/
From 53aabf50517d8b4006917c69b86ba8ecac67b68c Mon Sep 17 00:00:00 2001
From: eranl <1707552+eranl@users.noreply.github.com>
Date: Fri, 3 Nov 2023 20:23:58 +0200
Subject: [PATCH 05/51] Add support for java record serialization - move test
code to google-cloud-firestore module by adding a test-jdk17 directory and a
java17 profile, and eliminate google-cloud-firestore-jdk17 module
---
google-cloud-firestore-jdk17/pom.xml | 121 ------------------
google-cloud-firestore/pom.xml | 44 +++++++
.../RecordDocumentReferenceTest.java | 51 ++++----
.../cloud/firestore/RecordMapperTest.java | 34 ++---
.../record}/LocalFirestoreHelper.java | 34 +++--
pom.xml | 1 -
6 files changed, 104 insertions(+), 181 deletions(-)
delete mode 100644 google-cloud-firestore-jdk17/pom.xml
rename {google-cloud-firestore-jdk17/src/test => google-cloud-firestore/src/test-jdk17}/java/com/google/cloud/firestore/RecordDocumentReferenceTest.java (88%)
rename {google-cloud-firestore-jdk17/src/test => google-cloud-firestore/src/test-jdk17}/java/com/google/cloud/firestore/RecordMapperTest.java (98%)
rename {google-cloud-firestore-jdk17/src/test/java/com/google/cloud/firestore/jdk17 => google-cloud-firestore/src/test-jdk17/java/com/google/cloud/firestore/record}/LocalFirestoreHelper.java (99%)
diff --git a/google-cloud-firestore-jdk17/pom.xml b/google-cloud-firestore-jdk17/pom.xml
deleted file mode 100644
index 060de6b89..000000000
--- a/google-cloud-firestore-jdk17/pom.xml
+++ /dev/null
@@ -1,121 +0,0 @@
-
-
- 4.0.0
- google-cloud-firestore-jdk17
- 3.8.3-SNAPSHOT
- jar
- Google Cloud Firestore JDK17 extension
- https://github.com/googleapis/java-firestore
-
- Java idiomatic client for Google Cloud Firestore.
-
-
- com.google.cloud
- google-cloud-firestore-parent
- 3.8.3-SNAPSHOT
-
-
- google-cloud-firestore-jdk17
- 17
- 17
-
-
-
-
-
- javax.annotation
- javax.annotation-api
- test
-
-
- com.google.api
- api-common
- test
-
-
- com.google.cloud
- google-cloud-core
- test
-
-
- com.google.cloud
- google-cloud-firestore
- test
-
-
- com.google.api.grpc
- proto-google-cloud-firestore-v1
- test
-
-
- com.google.guava
- guava
- test
-
-
- com.google.code.gson
- gson
- test
-
-
- junit
- junit
- test
-
-
- org.mockito
- mockito-core
- 2.25.0
- test
-
-
-
-
- com.google.api
- gax
- testlib
- test
-
-
-
-
-
-
- org.apache.maven.plugins
- maven-javadoc-plugin
- 3.5.0
-
- protected
- true
- none
- true
-
-
-
-
-
-
-
-
-
- maven-compiler-plugin
- 3.10.1
-
- 17
- 17
- UTF-8
- -Xlint:unchecked
- -Xlint:deprecation
- true
-
-
-
-
-
-
- org.codehaus.mojo
- flatten-maven-plugin
-
-
-
-
diff --git a/google-cloud-firestore/pom.xml b/google-cloud-firestore/pom.xml
index 395a4025d..492786304 100644
--- a/google-cloud-firestore/pom.xml
+++ b/google-cloud-firestore/pom.xml
@@ -230,5 +230,49 @@
+
+
+ java17
+
+ 17
+
+
+
+
+ org.codehaus.mojo
+ build-helper-maven-plugin
+
+
+ add-test-source
+ generate-test-sources
+
+ add-test-source
+
+
+
+ src/test-jdk17/java
+
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+ true
+
+
+ 17
+ 17
+
+ -parameters
+ --add-opens=java.base/java.lang=ALL-UNNAMED
+ --add-opens=java.base/java.util=ALL-UNNAMED
+
+
+
+
+
+
diff --git a/google-cloud-firestore-jdk17/src/test/java/com/google/cloud/firestore/RecordDocumentReferenceTest.java b/google-cloud-firestore/src/test-jdk17/java/com/google/cloud/firestore/RecordDocumentReferenceTest.java
similarity index 88%
rename from google-cloud-firestore-jdk17/src/test/java/com/google/cloud/firestore/RecordDocumentReferenceTest.java
rename to google-cloud-firestore/src/test-jdk17/java/com/google/cloud/firestore/RecordDocumentReferenceTest.java
index 52f6e590f..405ca2dc4 100644
--- a/google-cloud-firestore-jdk17/src/test/java/com/google/cloud/firestore/RecordDocumentReferenceTest.java
+++ b/google-cloud-firestore/src/test-jdk17/java/com/google/cloud/firestore/RecordDocumentReferenceTest.java
@@ -16,7 +16,7 @@
package com.google.cloud.firestore;
-import static com.google.cloud.firestore.jdk17.LocalFirestoreHelper.*;
+import static com.google.cloud.firestore.record.LocalFirestoreHelper.*;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import static org.mockito.Mockito.doAnswer;
@@ -25,28 +25,29 @@
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.firestore.jdk17.LocalFirestoreHelper;
import com.google.cloud.firestore.spi.v1.FirestoreRpc;
import com.google.firestore.v1.BatchGetDocumentsRequest;
import com.google.firestore.v1.CommitRequest;
import com.google.firestore.v1.CommitResponse;
import com.google.firestore.v1.Value;
-import java.math.BigInteger;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
import org.junit.Before;
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;
+
+import java.math.BigInteger;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
@RunWith(MockitoJUnitRunner.class)
public class RecordDocumentReferenceTest {
@@ -75,7 +76,7 @@ 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_OBJECT).get();
@@ -127,7 +128,7 @@ public void doesNotDeserializeAdvancedNumberTypes() throws Exception {
.streamRequest(
getAllCapture.capture(),
streamObserverCapture.capture(),
- Matchers.any());
+ ArgumentMatchers.any());
var snapshot = documentReference.get().get();
try {
@@ -148,7 +149,7 @@ public void createDocument() throws Exception {
doReturn(SINGLE_WRITE_COMMIT_RESPONSE)
.when(firestoreMock)
.sendRequest(
- commitCapture.capture(), Matchers.>any());
+ commitCapture.capture(), ArgumentMatchers.>any());
documentReference.create(SINGLE_COMPONENT_OBJECT).get();
@@ -163,9 +164,9 @@ 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_OBJECT).get();
+ documentReference.create(SERVER_TIMESTAMP_OBJECT).get();
var create =
commit(
@@ -181,9 +182,9 @@ 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_OBJECT).get();
+ documentReference.set(SERVER_TIMESTAMP_OBJECT).get();
var set =
commit(
@@ -199,10 +200,10 @@ 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_OBJECT, SetOptions.mergeFields("inner.bar"))
+ .set(SERVER_TIMESTAMP_OBJECT, SetOptions.mergeFields("inner.bar"))
.get();
var set =
@@ -219,7 +220,7 @@ public void setDocumentWithMerge() throws Exception {
doReturn(SINGLE_WRITE_COMMIT_RESPONSE)
.when(firestoreMock)
.sendRequest(
- commitCapture.capture(), Matchers.>any());
+ commitCapture.capture(), ArgumentMatchers.>any());
documentReference.set(SINGLE_COMPONENT_OBJECT, SetOptions.merge()).get();
documentReference.set(ALL_SUPPORTED_TYPES_OBJECT, SetOptions.mergeFields("foo")).get();
@@ -244,7 +245,7 @@ public void setDocumentWithNestedMerge() throws Exception {
doReturn(SINGLE_WRITE_COMMIT_RESPONSE)
.when(firestoreMock)
.sendRequest(
- commitCapture.capture(), Matchers.>any());
+ commitCapture.capture(), ArgumentMatchers.>any());
documentReference.set(NESTED_RECORD_OBJECT, SetOptions.mergeFields("first.foo")).get();
documentReference
@@ -273,7 +274,7 @@ public void setMultipleFieldsWithMerge() throws Exception {
doReturn(SINGLE_WRITE_COMMIT_RESPONSE)
.when(firestoreMock)
.sendRequest(
- commitCapture.capture(), Matchers.>any());
+ commitCapture.capture(), ArgumentMatchers.>any());
documentReference
.set(
@@ -301,7 +302,7 @@ public void setNestedMapWithMerge() throws Exception {
doReturn(SINGLE_WRITE_COMMIT_RESPONSE)
.when(firestoreMock)
.sendRequest(
- commitCapture.capture(), Matchers.>any());
+ commitCapture.capture(), ArgumentMatchers.>any());
documentReference.set(NESTED_RECORD_OBJECT, SetOptions.mergeFields("first", "second")).get();
@@ -321,7 +322,7 @@ public void extractFieldMaskFromMerge() throws Exception {
doReturn(SINGLE_WRITE_COMMIT_RESPONSE)
.when(firestoreMock)
.sendRequest(
- commitCapture.capture(), Matchers.>any());
+ commitCapture.capture(), ArgumentMatchers.>any());
documentReference.set(NESTED_RECORD_OBJECT, SetOptions.merge()).get();
diff --git a/google-cloud-firestore-jdk17/src/test/java/com/google/cloud/firestore/RecordMapperTest.java b/google-cloud-firestore/src/test-jdk17/java/com/google/cloud/firestore/RecordMapperTest.java
similarity index 98%
rename from google-cloud-firestore-jdk17/src/test/java/com/google/cloud/firestore/RecordMapperTest.java
rename to google-cloud-firestore/src/test-jdk17/java/com/google/cloud/firestore/RecordMapperTest.java
index 19c261a6b..dc256e1ba 100644
--- a/google-cloud-firestore-jdk17/src/test/java/com/google/cloud/firestore/RecordMapperTest.java
+++ b/google-cloud-firestore/src/test-jdk17/java/com/google/cloud/firestore/RecordMapperTest.java
@@ -16,6 +16,18 @@
package com.google.cloud.firestore;
+import com.google.cloud.firestore.annotation.DocumentId;
+import com.google.cloud.firestore.annotation.PropertyName;
+import com.google.cloud.firestore.annotation.ThrowOnExtraProperties;
+import com.google.cloud.firestore.spi.v1.FirestoreRpc;
+import com.google.common.collect.ImmutableList;
+import com.google.firestore.v1.DatabaseRootName;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mockito;
+import org.mockito.Spy;
+import org.mockito.junit.MockitoJUnitRunner;
+
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.ArrayList;
@@ -28,22 +40,12 @@
import java.util.Map;
import java.util.Set;
-import com.google.cloud.firestore.annotation.DocumentId;
-import com.google.cloud.firestore.annotation.PropertyName;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.Mockito;
-import org.mockito.Spy;
-
-import com.google.cloud.firestore.annotation.ThrowOnExtraProperties;
-import com.google.cloud.firestore.spi.v1.FirestoreRpc;
-import com.google.common.collect.ImmutableList;
-import com.google.firestore.v1.DatabaseRootName;
-import org.mockito.junit.MockitoJUnitRunner;
-
-import static com.google.cloud.firestore.jdk17.LocalFirestoreHelper.fromSingleQuotedString;
-import static com.google.cloud.firestore.jdk17.LocalFirestoreHelper.mapAnyType;
-import static org.junit.Assert.*;
+import static com.google.cloud.firestore.record.LocalFirestoreHelper.fromSingleQuotedString;
+import static com.google.cloud.firestore.record.LocalFirestoreHelper.mapAnyType;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertThrows;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
@SuppressWarnings({"unused", "WeakerAccess", "SpellCheckingInspection"})
@RunWith(MockitoJUnitRunner.class)
diff --git a/google-cloud-firestore-jdk17/src/test/java/com/google/cloud/firestore/jdk17/LocalFirestoreHelper.java b/google-cloud-firestore/src/test-jdk17/java/com/google/cloud/firestore/record/LocalFirestoreHelper.java
similarity index 99%
rename from google-cloud-firestore-jdk17/src/test/java/com/google/cloud/firestore/jdk17/LocalFirestoreHelper.java
rename to google-cloud-firestore/src/test-jdk17/java/com/google/cloud/firestore/record/LocalFirestoreHelper.java
index bf34b1ecb..ccb30f64e 100644
--- a/google-cloud-firestore-jdk17/src/test/java/com/google/cloud/firestore/jdk17/LocalFirestoreHelper.java
+++ b/google-cloud-firestore/src/test-jdk17/java/com/google/cloud/firestore/record/LocalFirestoreHelper.java
@@ -14,24 +14,7 @@
* limitations under the License.
*/
-package com.google.cloud.firestore.jdk17;
-
-import java.math.BigInteger;
-import java.text.ParseException;
-import java.text.SimpleDateFormat;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.concurrent.TimeUnit;
-
-import javax.annotation.Nullable;
-
-import org.mockito.stubbing.Answer;
+package com.google.cloud.firestore.record;
import com.google.api.core.ApiFuture;
import com.google.api.core.ApiFutures;
@@ -56,6 +39,21 @@
import com.google.protobuf.ByteString;
import com.google.protobuf.NullValue;
import com.google.type.LatLng;
+import org.mockito.stubbing.Answer;
+
+import javax.annotation.Nullable;
+import java.math.BigInteger;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.TimeUnit;
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.mock;
diff --git a/pom.xml b/pom.xml
index 52092d70d..e5347ba5b 100644
--- a/pom.xml
+++ b/pom.xml
@@ -216,7 +216,6 @@
proto-google-cloud-firestore-bundle-v1
google-cloud-firestore-admin
google-cloud-firestore-bom
- google-cloud-firestore-jdk17
From 3fc7a23fb5b54e3bb7d4aa0e494f5376a4b68440 Mon Sep 17 00:00:00 2001
From: milaGGL <107142260+milaGGL@users.noreply.github.com>
Date: Wed, 28 Aug 2024 13:53:04 -0400
Subject: [PATCH 06/51] check if CI running the new tests
---
.../com/google/cloud/firestore/RecordDocumentReferenceTest.java | 1 +
1 file changed, 1 insertion(+)
diff --git a/google-cloud-firestore/src/test-jdk17/java/com/google/cloud/firestore/RecordDocumentReferenceTest.java b/google-cloud-firestore/src/test-jdk17/java/com/google/cloud/firestore/RecordDocumentReferenceTest.java
index 405ca2dc4..a70d58560 100644
--- a/google-cloud-firestore/src/test-jdk17/java/com/google/cloud/firestore/RecordDocumentReferenceTest.java
+++ b/google-cloud-firestore/src/test-jdk17/java/com/google/cloud/firestore/RecordDocumentReferenceTest.java
@@ -86,6 +86,7 @@ public void serializeBasicTypes() throws Exception {
@Test
public void doesNotSerializeAdvancedNumberTypes() {
+ System.out.println("========================== Record tests run on CI");
Map expectedErrorMessages = new HashMap<>();
var record = new InvalidRecord(new BigInteger("0"), null, null);
From b6197d5c070ae160ccebfd69103fb8a8eb523b33 Mon Sep 17 00:00:00 2001
From: milaGGL <107142260+milaGGL@users.noreply.github.com>
Date: Wed, 28 Aug 2024 14:03:18 -0400
Subject: [PATCH 07/51] check if new pom setup leads to units(8) failure
---
google-cloud-firestore/pom.xml | 44 ----------------------------------
1 file changed, 44 deletions(-)
diff --git a/google-cloud-firestore/pom.xml b/google-cloud-firestore/pom.xml
index 869bd7afe..2516b9165 100644
--- a/google-cloud-firestore/pom.xml
+++ b/google-cloud-firestore/pom.xml
@@ -321,49 +321,5 @@
-
-
- java17
-
- 17
-
-
-
-
- org.codehaus.mojo
- build-helper-maven-plugin
-
-
- add-test-source
- generate-test-sources
-
- add-test-source
-
-
-
- src/test-jdk17/java
-
-
-
-
-
-
- org.apache.maven.plugins
- maven-compiler-plugin
- true
-
-
- 17
- 17
-
- -parameters
- --add-opens=java.base/java.lang=ALL-UNNAMED
- --add-opens=java.base/java.util=ALL-UNNAMED
-
-
-
-
-
-
From b155bee1c2783faa9dac2e93843145e6bb5123b1 Mon Sep 17 00:00:00 2001
From: milaGGL <107142260+milaGGL@users.noreply.github.com>
Date: Wed, 28 Aug 2024 14:10:13 -0400
Subject: [PATCH 08/51] try ignoring the ToStringTest
---
.kokoro/build.sh | 1 +
google-cloud-firestore/pom.xml | 44 ++++++++++++++++++++++++++++++++++
2 files changed, 45 insertions(+)
diff --git a/.kokoro/build.sh b/.kokoro/build.sh
index 205347243..0b620a739 100755
--- a/.kokoro/build.sh
+++ b/.kokoro/build.sh
@@ -49,6 +49,7 @@ case ${JOB_TYPE} in
test)
echo "SUREFIRE_JVM_OPT: ${SUREFIRE_JVM_OPT}"
mvn test -B -ntp -Dclirr.skip=true -Denforcer.skip=true ${SUREFIRE_JVM_OPT}
+ javap -verbose -cp google-cloud-firestore/target/test-classes com/google/cloud/firestore/ToStringTest
RETURN_CODE=$?
;;
lint)
diff --git a/google-cloud-firestore/pom.xml b/google-cloud-firestore/pom.xml
index 2516b9165..869bd7afe 100644
--- a/google-cloud-firestore/pom.xml
+++ b/google-cloud-firestore/pom.xml
@@ -321,5 +321,49 @@
+
+
+ java17
+
+ 17
+
+
+
+
+ org.codehaus.mojo
+ build-helper-maven-plugin
+
+
+ add-test-source
+ generate-test-sources
+
+ add-test-source
+
+
+
+ src/test-jdk17/java
+
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+ true
+
+
+ 17
+ 17
+
+ -parameters
+ --add-opens=java.base/java.lang=ALL-UNNAMED
+ --add-opens=java.base/java.util=ALL-UNNAMED
+
+
+
+
+
+
From 0bea0231d8359507fee7941245d6216a61981a1e Mon Sep 17 00:00:00 2001
From: milaGGL <107142260+milaGGL@users.noreply.github.com>
Date: Wed, 28 Aug 2024 15:17:55 -0400
Subject: [PATCH 09/51] remove var
---
.../RecordDocumentReferenceTest.java | 54 ++---
.../cloud/firestore/RecordMapperTest.java | 220 +++++++++---------
.../record/LocalFirestoreHelper.java | 54 ++---
3 files changed, 164 insertions(+), 164 deletions(-)
diff --git a/google-cloud-firestore/src/test-jdk17/java/com/google/cloud/firestore/RecordDocumentReferenceTest.java b/google-cloud-firestore/src/test-jdk17/java/com/google/cloud/firestore/RecordDocumentReferenceTest.java
index a70d58560..c18f50357 100644
--- a/google-cloud-firestore/src/test-jdk17/java/com/google/cloud/firestore/RecordDocumentReferenceTest.java
+++ b/google-cloud-firestore/src/test-jdk17/java/com/google/cloud/firestore/RecordDocumentReferenceTest.java
@@ -80,7 +80,7 @@ public void serializeBasicTypes() throws Exception {
documentReference.set(ALL_SUPPORTED_TYPES_OBJECT).get();
- var expectedCommit = commit(set(ALL_SUPPORTED_TYPES_PROTO));
+ CommitRequest expectedCommit = commit(set(ALL_SUPPORTED_TYPES_PROTO));
assertCommitEquals(expectedCommit, commitCapture.getAllValues().get(0));
}
@@ -89,7 +89,7 @@ public void doesNotSerializeAdvancedNumberTypes() {
System.out.println("========================== Record tests run on CI");
Map expectedErrorMessages = new HashMap<>();
- var record = new InvalidRecord(new BigInteger("0"), null, null);
+ InvalidRecord record = new InvalidRecord(new BigInteger("0"), null, null);
expectedErrorMessages.put(
record,
"Could not serialize object. Numbers of type BigInteger are not supported, please use an int, long, float, double or BigDecimal (found in field 'bigIntegerValue')");
@@ -104,7 +104,7 @@ record = new InvalidRecord(null, null, (short) 0);
record,
"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 (var testCase : expectedErrorMessages.entrySet()) {
+ for (Map.Entry testCase : expectedErrorMessages.entrySet()) {
try {
documentReference.set(testCase.getKey());
fail();
@@ -116,13 +116,13 @@ record = new InvalidRecord(null, null, (short) 0);
@Test
public void doesNotDeserializeAdvancedNumberTypes() throws Exception {
- var fieldNamesToTypeNames =
+ Map fieldNamesToTypeNames =
map("bigIntegerValue", "BigInteger", "shortValue", "Short", "byteValue", "Byte");
- for (var testCase : fieldNamesToTypeNames.entrySet()) {
- var fieldName = testCase.getKey();
- var typeName = testCase.getValue();
- var response = map(fieldName, Value.newBuilder().setIntegerValue(0).build());
+ for (Entry testCase : fieldNamesToTypeNames.entrySet()) {
+ String fieldName = testCase.getKey();
+ String typeName = testCase.getValue();
+ Map response = map(fieldName, Value.newBuilder().setIntegerValue(0).build());
doAnswer(getAllResponse(response))
.when(firestoreMock)
@@ -131,7 +131,7 @@ public void doesNotDeserializeAdvancedNumberTypes() throws Exception {
streamObserverCapture.capture(),
ArgumentMatchers.any());
- var snapshot = documentReference.get().get();
+ DocumentSnapshot snapshot = documentReference.get().get();
try {
snapshot.toObject(InvalidRecord.class);
fail();
@@ -169,12 +169,12 @@ public void createWithServerTimestamp() throws Exception {
documentReference.create(SERVER_TIMESTAMP_OBJECT).get();
- var create =
+ CommitRequest create =
commit(
create(Collections.emptyMap()),
transform("foo", serverTimestamp(), "inner.bar", serverTimestamp()));
- var commitRequests = commitCapture.getAllValues();
+ List commitRequests = commitCapture.getAllValues();
assertCommitEquals(create, commitRequests.get(0));
}
@@ -187,12 +187,12 @@ public void setWithServerTimestamp() throws Exception {
documentReference.set(SERVER_TIMESTAMP_OBJECT).get();
- var set =
+ CommitRequest set =
commit(
set(SERVER_TIMESTAMP_PROTO),
transform("foo", serverTimestamp(), "inner.bar", serverTimestamp()));
- var commitRequests = commitCapture.getAllValues();
+ List commitRequests = commitCapture.getAllValues();
assertCommitEquals(set, commitRequests.get(0));
}
@@ -207,12 +207,12 @@ public void mergeWithServerTimestamps() throws Exception {
.set(SERVER_TIMESTAMP_OBJECT, SetOptions.mergeFields("inner.bar"))
.get();
- var set =
+ CommitRequest set =
commit(
set(SERVER_TIMESTAMP_PROTO, new ArrayList<>()),
transform("inner.bar", serverTimestamp()));
- var commitRequests = commitCapture.getAllValues();
+ List commitRequests = commitCapture.getAllValues();
assertCommitEquals(set, commitRequests.get(0));
}
@@ -234,9 +234,9 @@ public void setDocumentWithMerge() throws Exception {
SetOptions.mergeFieldPaths(Arrays.asList(FieldPath.of("foo"))))
.get();
- var expectedCommit = commit(set(SINGLE_COMPONENT_PROTO, Arrays.asList("foo")));
+ CommitRequest expectedCommit = commit(set(SINGLE_COMPONENT_PROTO, Arrays.asList("foo")));
- for (var i = 0; i < 4; ++i) {
+ for (int i = 0; i < 4; ++i) {
assertCommitEquals(expectedCommit, commitCapture.getAllValues().get(i));
}
}
@@ -259,13 +259,13 @@ public void setDocumentWithNestedMerge() throws Exception {
.get();
Map nestedUpdate = new HashMap<>();
- var nestedProto = Value.newBuilder();
+ Value.Builder nestedProto = Value.newBuilder();
nestedProto.getMapValueBuilder().putAllFields(SINGLE_COMPONENT_PROTO);
nestedUpdate.put("first", nestedProto.build());
- var expectedCommit = commit(set(nestedUpdate, Arrays.asList("first.foo")));
+ CommitRequest expectedCommit = commit(set(nestedUpdate, Arrays.asList("first.foo")));
- for (var i = 0; i < 3; ++i) {
+ for (int i = 0; i < 3; ++i) {
assertCommitEquals(expectedCommit, commitCapture.getAllValues().get(i));
}
}
@@ -284,7 +284,7 @@ public void setMultipleFieldsWithMerge() throws Exception {
.get();
Map nestedUpdate = new HashMap<>();
- var nestedProto = Value.newBuilder();
+ Value.Builder nestedProto = Value.newBuilder();
nestedProto.getMapValueBuilder().putAllFields(SINGLE_COMPONENT_PROTO);
nestedUpdate.put("first", nestedProto.build());
nestedProto
@@ -292,7 +292,7 @@ public void setMultipleFieldsWithMerge() throws Exception {
.putFields("trueValue", Value.newBuilder().setBooleanValue(true).build());
nestedUpdate.put("second", nestedProto.build());
- var expectedCommit =
+ CommitRequest expectedCommit =
commit(set(nestedUpdate, Arrays.asList("first.foo", "second.foo", "second.trueValue")));
assertCommitEquals(expectedCommit, commitCapture.getValue());
@@ -308,13 +308,13 @@ public void setNestedMapWithMerge() throws Exception {
documentReference.set(NESTED_RECORD_OBJECT, SetOptions.mergeFields("first", "second")).get();
Map nestedUpdate = new HashMap<>();
- var nestedProto = Value.newBuilder();
+ Value.Builder nestedProto = Value.newBuilder();
nestedProto.getMapValueBuilder().putAllFields(SINGLE_COMPONENT_PROTO);
nestedUpdate.put("first", nestedProto.build());
nestedProto.getMapValueBuilder().putAllFields(ALL_SUPPORTED_TYPES_PROTO);
nestedUpdate.put("second", nestedProto.build());
- var expectedCommit = commit(set(nestedUpdate, Arrays.asList("first", "second")));
+ CommitRequest expectedCommit = commit(set(nestedUpdate, Arrays.asList("first", "second")));
assertCommitEquals(expectedCommit, commitCapture.getValue());
}
@@ -328,13 +328,13 @@ public void extractFieldMaskFromMerge() throws Exception {
documentReference.set(NESTED_RECORD_OBJECT, SetOptions.merge()).get();
Map nestedUpdate = new HashMap<>();
- var nestedProto = Value.newBuilder();
+ Value.Builder nestedProto = Value.newBuilder();
nestedProto.getMapValueBuilder().putAllFields(SINGLE_COMPONENT_PROTO);
nestedUpdate.put("first", nestedProto.build());
nestedProto.getMapValueBuilder().putAllFields(ALL_SUPPORTED_TYPES_PROTO);
nestedUpdate.put("second", nestedProto.build());
- var updateMask =
+ List updateMask =
Arrays.asList(
"first.foo",
"second.arrayValue",
@@ -354,7 +354,7 @@ public void extractFieldMaskFromMerge() throws Exception {
"second.trueValue",
"second.model.foo");
- var expectedCommit = commit(set(nestedUpdate, updateMask));
+ CommitRequest expectedCommit = commit(set(nestedUpdate, updateMask));
assertCommitEquals(expectedCommit, commitCapture.getValue());
}
}
diff --git a/google-cloud-firestore/src/test-jdk17/java/com/google/cloud/firestore/RecordMapperTest.java b/google-cloud-firestore/src/test-jdk17/java/com/google/cloud/firestore/RecordMapperTest.java
index dc256e1ba..3b6103206 100644
--- a/google-cloud-firestore/src/test-jdk17/java/com/google/cloud/firestore/RecordMapperTest.java
+++ b/google-cloud-firestore/src/test-jdk17/java/com/google/cloud/firestore/RecordMapperTest.java
@@ -231,7 +231,7 @@ private static T deserialize(Map json, Class clazz) {
}
private static T deserialize(String jsonString, Class clazz, DocumentReference docRef) {
- var json = fromSingleQuotedString(jsonString);
+ Map json = fromSingleQuotedString(jsonString);
return CustomClassMapper.convertToCustomClass(json, clazz, docRef);
}
@@ -268,7 +268,7 @@ private static T convertToCustomClass(Object object, Class clazz) {
@Test
public void primitiveDeserializeString() {
- var bean = deserialize("{'value': 'foo'}", StringBean.class);
+ StringBean bean = deserialize("{'value': 'foo'}", StringBean.class);
assertEquals("foo", bean.value());
// Double
@@ -302,7 +302,7 @@ public void primitiveDeserializeString() {
@Test
public void primitiveDeserializeBoolean() {
- var beanBoolean = deserialize("{'value': true}", BooleanBean.class);
+ BooleanBean beanBoolean = deserialize("{'value': true}", BooleanBean.class);
assertEquals(true, beanBoolean.value());
// Double
@@ -336,14 +336,14 @@ public void primitiveDeserializeBoolean() {
@Test
public void primitiveDeserializeDouble() {
- var beanDouble = deserialize("{'value': 1.1}", DoubleBean.class);
+ DoubleBean beanDouble = deserialize("{'value': 1.1}", DoubleBean.class);
assertEquals(1.1, beanDouble.value(), EPSILON);
// Int
- var beanInt = deserialize("{'value': 1}", DoubleBean.class);
+ DoubleBean beanInt = deserialize("{'value': 1}", DoubleBean.class);
assertEquals(1, beanInt.value(), EPSILON);
// Long
- var beanLong = deserialize("{'value': 1234567890123}", DoubleBean.class);
+ DoubleBean beanLong = deserialize("{'value': 1234567890123}", DoubleBean.class);
assertEquals(1234567890123L, beanLong.value(), EPSILON);
// Boolean
@@ -363,29 +363,29 @@ public void primitiveDeserializeDouble() {
@Test
public void primitiveDeserializeBigDecimal() {
- var beanBigdecimal = deserialize("{'value': 123}", BigDecimalBean.class);
+ BigDecimalBean beanBigdecimal = deserialize("{'value': 123}", BigDecimalBean.class);
assertEquals(BigDecimal.valueOf(123.0), beanBigdecimal.value());
beanBigdecimal = deserialize("{'value': '123'}", BigDecimalBean.class);
assertEquals(BigDecimal.valueOf(123), beanBigdecimal.value());
// Int
- var beanInt =
+ BigDecimalBean beanInt =
deserialize(Collections.singletonMap("value", 1), BigDecimalBean.class);
assertEquals(BigDecimal.valueOf(1), beanInt.value());
// Long
- var beanLong =
+ BigDecimalBean beanLong =
deserialize(Collections.singletonMap("value", 1234567890123L), BigDecimalBean.class);
assertEquals(BigDecimal.valueOf(1234567890123L), beanLong.value());
// Double
- var beanDouble =
+ BigDecimalBean beanDouble =
deserialize(Collections.singletonMap("value", 1.1), BigDecimalBean.class);
assertEquals(BigDecimal.valueOf(1.1), beanDouble.value());
// BigDecimal
- var beanBigDecimal =
+ BigDecimalBean beanBigDecimal =
deserialize(
Collections.singletonMap("value", BigDecimal.valueOf(1.2)), BigDecimalBean.class);
assertEquals(BigDecimal.valueOf(1.2), beanBigDecimal.value());
@@ -407,14 +407,14 @@ public void primitiveDeserializeBigDecimal() {
@Test
public void primitiveDeserializeFloat() {
- var beanFloat = deserialize("{'value': 1.1}", FloatBean.class);
+ FloatBean beanFloat = deserialize("{'value': 1.1}", FloatBean.class);
assertEquals(1.1, beanFloat.value(), EPSILON);
// Int
- var beanInt = deserialize(Collections.singletonMap("value", 1), FloatBean.class);
+ FloatBean beanInt = deserialize(Collections.singletonMap("value", 1), FloatBean.class);
assertEquals(1, beanInt.value(), EPSILON);
// Long
- var beanLong =
+ FloatBean beanLong =
deserialize(Collections.singletonMap("value", 1234567890123L), FloatBean.class);
assertEquals((float) 1234567890123L, beanLong.value(), EPSILON);
@@ -435,11 +435,11 @@ public void primitiveDeserializeFloat() {
@Test
public void primitiveDeserializeInt() {
- var beanInt = deserialize("{'value': 1}", IntBean.class);
+ IntBean beanInt = deserialize("{'value': 1}", IntBean.class);
assertEquals(1, beanInt.value());
// Double
- var beanDouble = deserialize("{'value': 1.1}", IntBean.class);
+ IntBean beanDouble = deserialize("{'value': 1.1}", IntBean.class);
assertEquals(1, beanDouble.value());
// Large doubles
@@ -473,15 +473,15 @@ public void primitiveDeserializeInt() {
@Test
public void primitiveDeserializeLong() {
- var beanLong = deserialize("{'value': 1234567890123}", LongBean.class);
+ LongBean beanLong = deserialize("{'value': 1234567890123}", LongBean.class);
assertEquals(1234567890123L, beanLong.value());
// Int
- var beanInt = deserialize("{'value': 1}", LongBean.class);
+ LongBean beanInt = deserialize("{'value': 1}", LongBean.class);
assertEquals(1, beanInt.value());
// Double
- var beanDouble = deserialize("{'value': 1.1}", LongBean.class);
+ LongBean beanDouble = deserialize("{'value': 1.1}", LongBean.class);
assertEquals(1, beanDouble.value());
// Large doubles
@@ -508,7 +508,7 @@ public void primitiveDeserializeLong() {
@Test
public void primitiveDeserializeWrongTypeMap() {
- var expectedExceptionMessage =
+ String expectedExceptionMessage =
".* Failed to convert value of type .*Map to String \\(found in field 'value'\\).*";
Throwable exception =
assertThrows(
@@ -544,7 +544,7 @@ public void throwOnUnknownProperties() {
@Test
public void XMLAndURLBean() {
- var bean =
+ XMLAndURLBean bean =
deserialize("{'XMLAndURL': 'foo'}", XMLAndURLBean.class);
assertEquals("foo", bean.XMLAndURL());
}
@@ -555,9 +555,9 @@ public record AllCapsDefaultHandlingBean (
@Test
public void allCapsSerializesToUppercaseByDefault() {
- var bean = new AllCapsDefaultHandlingBean("value");
+ AllCapsDefaultHandlingBean bean = new AllCapsDefaultHandlingBean("value");
assertJson("{'UUID': 'value'}", serialize(bean));
- var deserialized =
+ AllCapsDefaultHandlingBean deserialized =
deserialize("{'UUID': 'value'}", AllCapsDefaultHandlingBean.class);
assertEquals("value", deserialized.UUID());
}
@@ -569,86 +569,86 @@ public record AllCapsWithPropertyName (
@Test
public void allCapsWithPropertyNameSerializesToLowercase() {
- var bean = new AllCapsWithPropertyName("value");
+ AllCapsWithPropertyName bean = new AllCapsWithPropertyName("value");
assertJson("{'uuid': 'value'}", serialize(bean));
- var deserialized =
+ AllCapsWithPropertyName deserialized =
deserialize("{'uuid': 'value'}", AllCapsWithPropertyName.class);
assertEquals("value", deserialized.UUID());
}
@Test
public void nestedParsingWorks() {
- var bean = deserialize("{'bean': {'value': 'foo'}}", NestedBean.class);
+ NestedBean bean = deserialize("{'bean': {'value': 'foo'}}", NestedBean.class);
assertEquals("foo", bean.bean().value());
}
@Test
public void beansCanContainLists() {
- var bean = deserialize("{'values': ['foo', 'bar']}", ListBean.class);
+ ListBean bean = deserialize("{'values': ['foo', 'bar']}", ListBean.class);
assertEquals(Arrays.asList("foo", "bar"), bean.values());
}
@Test
public void beansCanContainMaps() {
- var bean = deserialize("{'values': {'foo': 'bar'}}", MapBean.class);
- var expected = fromSingleQuotedString("{'foo': 'bar'}");
+ MapBean bean = deserialize("{'values': {'foo': 'bar'}}", MapBean.class);
+ Map expected = fromSingleQuotedString("{'foo': 'bar'}");
assertEquals(expected, bean.values());
}
@Test
public void beansCanContainUpperBoundedMaps() {
- var date = new Date(1491847082123L);
- var source = mapAnyType("values", mapAnyType("foo", date));
- var bean = convertToCustomClass(source, UpperBoundedMapBean.class);
- var expected = mapAnyType("foo", date);
+ Date date = new Date(1491847082123L);
+ Map source = mapAnyType("values", mapAnyType("foo", date));
+ UpperBoundedMapBean bean = convertToCustomClass(source, UpperBoundedMapBean.class);
+ Map expected = mapAnyType("foo", date);
assertEquals(expected, bean.values());
}
@Test
public void beansCanContainMultiBoundedMaps() {
- var date = new Date(1491847082123L);
- var source = mapAnyType("map", mapAnyType("values", mapAnyType("foo", date)));
- var bean = convertToCustomClass(source, MultiBoundedMapHolderBean.class);
+ Date date = new Date(1491847082123L);
+ Map source = mapAnyType("map", mapAnyType("values", mapAnyType("foo", date)));
+ MultiBoundedMapHolderBean bean = convertToCustomClass(source, MultiBoundedMapHolderBean.class);
- var expected = mapAnyType("foo", date);
+ Map expected = mapAnyType("foo", date);
assertEquals(expected, bean.map().values());
}
@Test
public void beansCanContainUnboundedMaps() {
- var bean = deserialize("{'values': {'foo': 'bar'}}", UnboundedMapBean.class);
- var expected = mapAnyType("foo", "bar");
+ UnboundedMapBean bean = deserialize("{'values': {'foo': 'bar'}}", UnboundedMapBean.class);
+ Map expected = mapAnyType("foo", "bar");
assertEquals(expected, bean.values());
}
@Test
public void beansCanContainUnboundedTypeVariableMaps() {
- var source = mapAnyType("map", mapAnyType("values", mapAnyType("foo", "bar")));
- var bean =
+ Map