14
14
15
15
package com .google .firebase .firestore ;
16
16
17
+ import static com .google .firebase .firestore .testutil .IntegrationTestUtil .nullList ;
17
18
import static com .google .firebase .firestore .testutil .IntegrationTestUtil .querySnapshotToIds ;
18
19
import static com .google .firebase .firestore .testutil .IntegrationTestUtil .querySnapshotToValues ;
19
20
import static com .google .firebase .firestore .testutil .IntegrationTestUtil .testCollection ;
@@ -562,15 +563,20 @@ public void testQueriesCanUseArrayContainsFilters() {
562
563
Map <String , Object > docB = map ("array" , asList ("a" , 42L , "c" ));
563
564
Map <String , Object > docC = map ("array" , asList (41.999 , "42" , map ("a" , asList (42 ))));
564
565
Map <String , Object > docD = map ("array" , asList (42L ), "array2" , asList ("bingo" ));
566
+ Map <String , Object > docE = map ("array" , nullList ());
567
+ Map <String , Object > docF = map ("array" , asList (Double .NaN ));
565
568
CollectionReference collection =
566
- testCollectionWithDocs (map ("a" , docA , "b" , docB , "c" , docC , "d" , docD ));
569
+ testCollectionWithDocs (
570
+ map ("a" , docA , "b" , docB , "c" , docC , "d" , docD , "e" , docE , "f" , docF ));
567
571
568
572
// Search for "array" to contain 42
569
573
QuerySnapshot snapshot = waitFor (collection .whereArrayContains ("array" , 42L ).get ());
570
574
assertEquals (asList (docA , docB , docD ), querySnapshotToValues (snapshot ));
571
575
572
- // NOTE: The backend doesn't currently support null, NaN, objects, or arrays, so there isn't
573
- // much of anything else interesting to test.
576
+ // Note: whereArrayContains() requires a non-null value parameter, so no null test is needed.
577
+ // With NaN.
578
+ snapshot = waitFor (collection .whereArrayContains ("array" , Double .NaN ).get ());
579
+ assertEquals (new ArrayList <>(), querySnapshotToValues (snapshot ));
574
580
}
575
581
576
582
@ Test
@@ -582,9 +588,14 @@ public void testQueriesCanUseInFilters() {
582
588
Map <String , Object > docE = map ("zip" , asList ("98101" , map ("zip" , 98101L )));
583
589
Map <String , Object > docF = map ("zip" , map ("code" , 500L ));
584
590
Map <String , Object > docG = map ("zip" , asList (98101L , 98102L ));
591
+ Map <String , Object > docH = map ("zip" , null );
592
+ Map <String , Object > docI = map ("zip" , Double .NaN );
593
+
585
594
CollectionReference collection =
586
595
testCollectionWithDocs (
587
- map ("a" , docA , "b" , docB , "c" , docC , "d" , docD , "e" , docE , "f" , docF , "g" , docG ));
596
+ map (
597
+ "a" , docA , "b" , docB , "c" , docC , "d" , docD , "e" , docE , "f" , docF , "g" , docG , "h" ,
598
+ docH , "i" , docI ));
588
599
589
600
// Search for zips matching 98101, 98103, or [98101, 98102].
590
601
QuerySnapshot snapshot =
@@ -594,6 +605,24 @@ public void testQueriesCanUseInFilters() {
594
605
// With objects.
595
606
snapshot = waitFor (collection .whereIn ("zip" , asList (map ("code" , 500L ))).get ());
596
607
assertEquals (asList (docF ), querySnapshotToValues (snapshot ));
608
+
609
+ // With null.
610
+ snapshot = waitFor (collection .whereIn ("zip" , nullList ()).get ());
611
+ assertEquals (new ArrayList <>(), querySnapshotToValues (snapshot ));
612
+
613
+ // With null and a value.
614
+ List <Object > inputList = nullList ();
615
+ inputList .add (98101L );
616
+ snapshot = waitFor (collection .whereIn ("zip" , inputList ).get ());
617
+ assertEquals (asList (docA ), querySnapshotToValues (snapshot ));
618
+
619
+ // With NaN.
620
+ snapshot = waitFor (collection .whereIn ("zip" , asList (Double .NaN )).get ());
621
+ assertEquals (new ArrayList <>(), querySnapshotToValues (snapshot ));
622
+
623
+ // With NaN and a value.
624
+ snapshot = waitFor (collection .whereIn ("zip" , asList (Double .NaN , 98101L )).get ());
625
+ assertEquals (asList (docA ), querySnapshotToValues (snapshot ));
597
626
}
598
627
599
628
@ Test
@@ -656,9 +685,7 @@ public void testQueriesCanUseNotInFilters() {
656
685
assertEquals (Lists .newArrayList (expectedDocsMap .values ()), querySnapshotToValues (snapshot ));
657
686
658
687
// With Null.
659
- List <Object > nullArray = new ArrayList <>();
660
- nullArray .add (null );
661
- snapshot = waitFor (collection .whereNotIn ("zip" , nullArray ).get ());
688
+ snapshot = waitFor (collection .whereNotIn ("zip" , nullList ()).get ());
662
689
assertEquals (new ArrayList <>(), querySnapshotToValues (snapshot ));
663
690
664
691
// With NaN.
@@ -706,10 +733,14 @@ public void testQueriesCanUseArrayContainsAnyFilters() {
706
733
Map <String , Object > docE = map ("array" , asList (43L ));
707
734
Map <String , Object > docF = map ("array" , asList (map ("a" , 42L )));
708
735
Map <String , Object > docG = map ("array" , 42L );
736
+ Map <String , Object > docH = map ("array" , nullList ());
737
+ Map <String , Object > docI = map ("array" , asList (Double .NaN ));
709
738
710
739
CollectionReference collection =
711
740
testCollectionWithDocs (
712
- map ("a" , docA , "b" , docB , "c" , docC , "d" , docD , "e" , docE , "f" , docF , "g" , docG ));
741
+ map (
742
+ "a" , docA , "b" , docB , "c" , docC , "d" , docD , "e" , docE , "f" , docF , "g" , docG , "h" ,
743
+ docH , "i" , docI ));
713
744
714
745
// Search for "array" to contain [42, 43].
715
746
QuerySnapshot snapshot =
@@ -719,6 +750,24 @@ public void testQueriesCanUseArrayContainsAnyFilters() {
719
750
// With objects.
720
751
snapshot = waitFor (collection .whereArrayContainsAny ("array" , asList (map ("a" , 42L ))).get ());
721
752
assertEquals (asList (docF ), querySnapshotToValues (snapshot ));
753
+
754
+ // With null.
755
+ snapshot = waitFor (collection .whereArrayContainsAny ("array" , nullList ()).get ());
756
+ assertEquals (new ArrayList <>(), querySnapshotToValues (snapshot ));
757
+
758
+ // With null and a value.
759
+ List <Object > inputList = nullList ();
760
+ inputList .add (43L );
761
+ snapshot = waitFor (collection .whereArrayContainsAny ("array" , inputList ).get ());
762
+ assertEquals (asList (docE ), querySnapshotToValues (snapshot ));
763
+
764
+ // With NaN.
765
+ snapshot = waitFor (collection .whereArrayContainsAny ("array" , asList (Double .NaN )).get ());
766
+ assertEquals (new ArrayList <>(), querySnapshotToValues (snapshot ));
767
+
768
+ // With NaN and a value.
769
+ snapshot = waitFor (collection .whereArrayContainsAny ("array" , asList (Double .NaN , 43L )).get ());
770
+ assertEquals (asList (docE ), querySnapshotToValues (snapshot ));
722
771
}
723
772
724
773
@ Test
0 commit comments