Skip to content

Commit 2267bca

Browse files
committed
Add a unit test for invoking saveOverlays() with a null value in the Map
1 parent 0eae6aa commit 2267bca

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

firebase-firestore/src/test/java/com/google/firebase/firestore/local/DocumentOverlayCacheTestCase.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import static com.google.firebase.firestore.testutil.TestUtil.setMutation;
2424
import static org.junit.Assert.assertEquals;
2525
import static org.junit.Assert.assertNull;
26+
import static org.junit.Assert.assertThrows;
2627
import static org.junit.Assert.assertTrue;
2728

2829
import com.google.firebase.firestore.auth.User;
@@ -41,6 +42,7 @@
4142
import org.junit.After;
4243
import org.junit.Before;
4344
import org.junit.Test;
45+
import org.junit.function.ThrowingRunnable;
4446

4547
/**
4648
* These are tests for any implementation of the DocumentOverlayCache interface.
@@ -252,6 +254,24 @@ public void testUpdateDocumentOverlay() {
252254
assertNull(cache.getOverlay(DocumentKey.fromPathString("coll/doc")));
253255
}
254256

257+
@Test
258+
public void testSaveOverlaysThrowsNullPointerExceptionOnNullMapValue() {
259+
Map<DocumentKey, Mutation> data = new HashMap<>();
260+
data.put(key("coll/doc"), null);
261+
262+
NullPointerException e =
263+
assertThrows(
264+
NullPointerException.class,
265+
new ThrowingRunnable() {
266+
@Override
267+
public void run() {
268+
cache.saveOverlays(1, data);
269+
}
270+
});
271+
272+
assertThat(e.getMessage()).contains("coll/doc");
273+
}
274+
255275
void verifyOverlayContains(Map<DocumentKey, Overlay> overlays, String... keys) {
256276
Set<DocumentKey> expected = Arrays.stream(keys).map(TestUtil::key).collect(Collectors.toSet());
257277
assertThat(overlays.keySet()).containsExactlyElementsIn(expected);

0 commit comments

Comments
 (0)