18
18
import static com .google .firebase .firestore .testutil .TestUtil .field ;
19
19
import static com .google .firebase .firestore .testutil .TestUtil .map ;
20
20
import static com .google .firebase .firestore .testutil .TestUtil .ref ;
21
- import static com .google .firebase .firestore .testutil .TestUtil .valueOf ;
22
21
import static com .google .firebase .firestore .testutil .TestUtil .wrap ;
23
22
import static com .google .firebase .firestore .testutil .TestUtil .wrapObject ;
24
23
import static java .util .Arrays .asList ;
25
24
import static org .junit .Assert .assertEquals ;
26
25
import static org .junit .Assert .assertNotEquals ;
26
+ import static org .junit .Assert .assertNull ;
27
27
import static org .junit .Assert .assertTrue ;
28
28
import static org .junit .Assert .fail ;
29
29
30
30
import com .google .firebase .Timestamp ;
31
31
import com .google .firebase .firestore .model .DatabaseId ;
32
32
import com .google .firebase .firestore .model .DocumentKey ;
33
- import com .google .firebase .firestore .model .value .FieldValue ;
34
33
import com .google .firebase .firestore .model .value .ObjectValue ;
35
34
import com .google .firebase .firestore .model .value .ProtoValues ;
36
35
import com .google .firestore .v1 .ArrayValue ;
@@ -54,15 +53,16 @@ public class UserDataWriterTest {
54
53
55
54
@ Test
56
55
public void testConvertsNullValue () {
57
- FieldValue value = wrap (null );
58
- assertEquals (value , new FieldValue (ProtoValues .NULL_VALUE ));
56
+ Value value = wrap (null );
57
+ Object convertedValue = convertValue (value );
58
+ assertNull (convertedValue );
59
59
}
60
60
61
61
@ Test
62
62
public void testConvertsBooleanValue () {
63
63
List <Boolean > testCases = asList (true , false );
64
64
for (Boolean b : testCases ) {
65
- FieldValue value = wrap (b );
65
+ Value value = wrap (b );
66
66
assertValueType (Value .ValueTypeCase .BOOLEAN_VALUE , value );
67
67
Object convertedValue = convertValue (value );
68
68
assertEquals (b , convertedValue );
@@ -73,7 +73,7 @@ public void testConvertsBooleanValue() {
73
73
public void testConvertsIntegerValue () {
74
74
List <Integer > testCases = asList (Integer .MIN_VALUE , -1 , 0 , 1 , Integer .MAX_VALUE );
75
75
for (Integer i : testCases ) {
76
- FieldValue value = wrap (i );
76
+ Value value = wrap (i );
77
77
assertValueType (Value .ValueTypeCase .INTEGER_VALUE , value );
78
78
Object convertedValue = convertValue (value );
79
79
assertEquals (i .longValue (), convertedValue );
@@ -93,7 +93,7 @@ public void testConvertsLongValue() {
93
93
Long .valueOf (Integer .MAX_VALUE ),
94
94
Long .MAX_VALUE );
95
95
for (Long l : testCases ) {
96
- FieldValue value = wrap (l );
96
+ Value value = wrap (l );
97
97
assertValueType (Value .ValueTypeCase .INTEGER_VALUE , value );
98
98
Object convertedValue = convertValue (value );
99
99
assertEquals (l , convertedValue );
@@ -115,7 +115,7 @@ public void testConvertsFloatValue() {
115
115
Long .MAX_VALUE * 1.0f ,
116
116
Float .MAX_VALUE );
117
117
for (Float f : testCases ) {
118
- FieldValue value = wrap (f );
118
+ Value value = wrap (f );
119
119
assertValueType (Value .ValueTypeCase .DOUBLE_VALUE , value );
120
120
Object convertedValue = convertValue (value );
121
121
assertEquals (f .doubleValue (), convertedValue );
@@ -146,7 +146,7 @@ public void testConvertsDoubleValue() {
146
146
Double .POSITIVE_INFINITY ,
147
147
Double .NaN );
148
148
for (Double d : testCases ) {
149
- FieldValue value = wrap (d );
149
+ Value value = wrap (d );
150
150
assertValueType (Value .ValueTypeCase .DOUBLE_VALUE , value );
151
151
Object convertedValue = convertValue (value );
152
152
assertEquals (d , convertedValue );
@@ -162,9 +162,9 @@ public void testConvertsDateValue() {
162
162
DocumentSnapshot .ServerTimestampBehavior .DEFAULT );
163
163
List <Date > testCases = asList (new Date (0 ), new Date (1356048000000L ));
164
164
for (Date d : testCases ) {
165
- FieldValue value = wrap (d );
165
+ Value value = wrap (d );
166
166
assertValueType (Value .ValueTypeCase .TIMESTAMP_VALUE , value );
167
- Object convertedValue = dateWriter .convertValue (value . getProto () );
167
+ Object convertedValue = dateWriter .convertValue (value );
168
168
assertEquals (d , convertedValue );
169
169
}
170
170
}
@@ -173,7 +173,7 @@ public void testConvertsDateValue() {
173
173
public void testConvertsTimestampValue () {
174
174
List <Timestamp > testCases = asList (new Timestamp (0 , 0 ), new Timestamp (1356048000L , 0 ));
175
175
for (Timestamp t : testCases ) {
176
- FieldValue value = wrap (t );
176
+ Value value = wrap (t );
177
177
assertValueType (Value .ValueTypeCase .TIMESTAMP_VALUE , value );
178
178
Object convertedValue = convertValue (value );
179
179
assertEquals (t , convertedValue );
@@ -184,7 +184,7 @@ public void testConvertsTimestampValue() {
184
184
public void testConvertsStringValue () {
185
185
List <String > testCases = asList ("" , "foo" );
186
186
for (String s : testCases ) {
187
- FieldValue value = wrap (s );
187
+ Value value = wrap (s );
188
188
Object convertedValue = convertValue (value );
189
189
assertEquals (s , convertedValue );
190
190
}
@@ -194,7 +194,7 @@ public void testConvertsStringValue() {
194
194
public void testConvertsBlobValue () {
195
195
List <Blob > testCases = asList (blob (1 , 2 , 3 ), blob (1 , 2 ));
196
196
for (Blob b : testCases ) {
197
- FieldValue value = wrap (b );
197
+ Value value = wrap (b );
198
198
Object convertedValue = convertValue (value );
199
199
assertEquals (b , convertedValue );
200
200
}
@@ -205,7 +205,7 @@ public void testConvertsResourceName() {
205
205
DatabaseId id = DatabaseId .forProject ("project" );
206
206
List <DocumentReference > testCases = asList (ref ("foo/bar" ), ref ("foo/baz" ));
207
207
for (DocumentReference docRef : testCases ) {
208
- Value value = valueOf (docRef );
208
+ Value value = wrap (docRef );
209
209
assertTrue (ProtoValues .isReferenceValue (value ));
210
210
assertEquals (
211
211
TestAccessHelper .referenceKey (docRef ), DocumentKey .fromName (value .getReferenceValue ()));
@@ -217,7 +217,7 @@ public void testConvertsResourceName() {
217
217
public void testConvertsGeoPointValue () {
218
218
List <GeoPoint > testCases = asList (new GeoPoint (1.24 , 4.56 ), new GeoPoint (-20 , 100 ));
219
219
for (GeoPoint p : testCases ) {
220
- FieldValue value = wrap (p );
220
+ Value value = wrap (p );
221
221
Object convertedValue = convertValue (value );
222
222
assertEquals (p , convertedValue );
223
223
}
@@ -248,7 +248,7 @@ public void testConvertsSimpleObjects() {
248
248
private static ObjectValue fromMap (Object ... entries ) {
249
249
Map <String , Value > res = new HashMap <>();
250
250
for (int i = 0 ; i < entries .length ; i += 2 ) {
251
- res .put ((String ) entries [i ], (( FieldValue ) entries [i + 1 ]). getProto () );
251
+ res .put ((String ) entries [i ], (Value ) entries [i + 1 ]);
252
252
}
253
253
return ObjectValue .fromMap (res );
254
254
}
@@ -257,19 +257,17 @@ private static ObjectValue fromMap(Object... entries) {
257
257
public void testConvertsNestedObjects () {
258
258
ObjectValue actual = wrapObject ("a" , map ("b" , map ("c" , "foo" ), "d" , true ));
259
259
ObjectValue .Builder expected = ObjectValue .newBuilder ();
260
- expected .set (field ("a.b.c" ), valueOf ("foo" ));
261
- expected .set (field ("a.d" ), valueOf (true ));
260
+ expected .set (field ("a.b.c" ), wrap ("foo" ));
261
+ expected .set (field ("a.d" ), wrap (true ));
262
262
assertEquals (expected .build (), actual );
263
263
}
264
264
265
265
@ Test
266
266
public void testConvertsLists () {
267
267
ArrayValue .Builder expectedArray =
268
- ArrayValue .newBuilder ().addValues (valueOf ("value" )).addValues (valueOf (true ));
269
- FieldValue actual = wrap (asList ("value" , true ));
270
- assertTrue (
271
- ProtoValues .equals (
272
- Value .newBuilder ().setArrayValue (expectedArray ).build (), actual .getProto ()));
268
+ ArrayValue .newBuilder ().addValues (wrap ("value" )).addValues (wrap (true ));
269
+ Value actual = wrap (asList ("value" , true ));
270
+ assertTrue (ProtoValues .equals (Value .newBuilder ().setArrayValue (expectedArray ).build (), actual ));
273
271
}
274
272
275
273
@ Test
@@ -283,11 +281,11 @@ public void testRejectsJavaArrays() {
283
281
}
284
282
}
285
283
286
- private Object convertValue (FieldValue value ) {
287
- return writer .convertValue (value . getProto () );
284
+ private Object convertValue (Value value ) {
285
+ return writer .convertValue (value );
288
286
}
289
287
290
- private void assertValueType (Value .ValueTypeCase booleanValue , FieldValue value ) {
291
- assertEquals (booleanValue , value .getProto (). getValueTypeCase ());
288
+ private void assertValueType (Value .ValueTypeCase booleanValue , Value value ) {
289
+ assertEquals (booleanValue , value .getValueTypeCase ());
292
290
}
293
291
}
0 commit comments