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

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ static Value encodeValue(
return Value.newBuilder().setIntegerValue((Long) sanitizedObject).build();
} else if (sanitizedObject instanceof Double) {
return Value.newBuilder().setDoubleValue((Double) sanitizedObject).build();
} else if (sanitizedObject instanceof Float) {
return Value.newBuilder().setDoubleValue((Float) sanitizedObject).build();
} else if (sanitizedObject instanceof Boolean) {
return Value.newBuilder().setBooleanValue((Boolean) sanitizedObject).build();
} else if (sanitizedObject instanceof Date) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ public final class LocalFirestoreHelper {
public static final Map<String, Object> UPDATED_FIELD_MAP;
public static final Map<String, Value> UPDATED_FIELD_PROTO;

public static final Map<String, Float> SINGLE_FLOAT_MAP;
public static final Map<String, Value> SINGLE_FLOAT_PROTO;

public static final NestedClass NESTED_CLASS_OBJECT;

public static final Map<String, Object> SERVER_TIMESTAMP_MAP;
Expand Down Expand Up @@ -695,6 +698,8 @@ public boolean equals(Object o) {
123000); // Firestore truncates to microsecond precision.
GEO_POINT = new GeoPoint(50.1430847, -122.9477780);
BLOB = Blob.fromBytes(new byte[] {1, 2, 3});
SINGLE_FLOAT_MAP = map("float", 0.1F);
SINGLE_FLOAT_PROTO = map("float", Value.newBuilder().setDoubleValue((Float) 0.1F).build());

DATABASE_NAME = "projects/test-project/databases/(default)";
COLLECTION_ID = "coll";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,29 @@ public void setDocumentWithValue() throws Exception {
assertEquals(commit(writes.toArray(new Write[] {})), commitRequest);
}

@Test
public void setDocumentWithFloat() throws Exception {
doReturn(commitResponse(1, 0))
.when(firestoreMock)
.sendRequest(
commitCapture.capture(), Matchers.<UnaryCallable<CommitRequest, CommitResponse>>any());

batch.set(documentReference, LocalFirestoreHelper.SINGLE_FLOAT_MAP);

List<Write> writes = new ArrayList<>();
writes.add(set(LocalFirestoreHelper.SINGLE_FLOAT_PROTO));

assertEquals(1, batch.getMutationsSize());

List<WriteResult> writeResults = batch.commit().get();
for (int i = 0; i < writeResults.size(); ++i) {
assertEquals(Timestamp.ofTimeSecondsAndNanos(i, i), writeResults.get(i).getUpdateTime());
}

CommitRequest commitRequest = commitCapture.getValue();
assertEquals(commit(writes.toArray(new Write[] {})), commitRequest);
}

@Test
public void omitWriteResultForDocumentTransforms() throws Exception {
doReturn(commitResponse(2, 0))
Expand Down Expand Up @@ -234,6 +257,29 @@ public void createDocumentWithValue() throws Exception {
assertEquals(commit(writes.toArray(new Write[] {})), commitRequest);
}

@Test
public void createDocumentWithFloat() throws Exception {
doReturn(commitResponse(1, 0))
.when(firestoreMock)
.sendRequest(
commitCapture.capture(), Matchers.<UnaryCallable<CommitRequest, CommitResponse>>any());

batch.create(documentReference, LocalFirestoreHelper.SINGLE_FLOAT_MAP);

assertEquals(1, batch.getMutationsSize());

List<WriteResult> writeResults = batch.commit().get();
List<Write> writes = new ArrayList<>();

for (int i = 0; i < writeResults.size(); ++i) {
assertEquals(Timestamp.ofTimeSecondsAndNanos(i, i), writeResults.get(i).getUpdateTime());
writes.add(create(LocalFirestoreHelper.SINGLE_FLOAT_PROTO));
}

CommitRequest commitRequest = commitCapture.getValue();
assertEquals(commit(writes.toArray(new Write[] {})), commitRequest);
}

@Test
public void deleteDocument() throws Exception {
doReturn(commitResponse(2, 0))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,14 @@ public void createDocumentWithValue() throws Exception {
assertEquals(SINGLE_FIELD_OBJECT, documentSnapshot.toObject(SingleField.class));
}

@Test
public void createDocumentWithFloat() throws Exception {
assertEquals(20, randomDoc.getId().length());
randomDoc.create(LocalFirestoreHelper.SINGLE_FLOAT_PROTO).get();
DocumentSnapshot documentSnapshot = randomDoc.get().get();
assertEquals(SINGLE_FIELD_OBJECT, documentSnapshot.toObject(SingleField.class));
}

@Test
public void setDocument() throws Exception {
Map<String, Object> nanNullMap = new HashMap<>();
Expand All @@ -186,6 +194,14 @@ public void setDocumentWithValue() throws Exception {
assertEquals(SINGLE_FIELD_OBJECT, documentSnapshot.toObject(SingleField.class));
}

@Test
public void setDocumentWithFloat() throws Exception {
assertEquals(20, randomDoc.getId().length());
randomDoc.set(LocalFirestoreHelper.SINGLE_FLOAT_PROTO).get();
DocumentSnapshot documentSnapshot = randomDoc.get().get();
assertEquals(SINGLE_FIELD_OBJECT, documentSnapshot.toObject(SingleField.class));
}

@Test
public void setDocumentWithMerge() throws Exception {
Map<String, Object> originalMap =
Expand Down