1919import static com .google .firebase .firestore .pipeline .Expr .and ;
2020import static com .google .firebase .firestore .pipeline .Expr .arrayContains ;
2121import static com .google .firebase .firestore .pipeline .Expr .arrayContainsAny ;
22+ import static com .google .firebase .firestore .pipeline .Expr .constant ;
2223import static com .google .firebase .firestore .pipeline .Expr .cosineDistance ;
2324import static com .google .firebase .firestore .pipeline .Expr .endsWith ;
2425import static com .google .firebase .firestore .pipeline .Expr .eq ;
3738import static com .google .firebase .firestore .pipeline .Expr .subtract ;
3839import static com .google .firebase .firestore .pipeline .Expr .vector ;
3940import static com .google .firebase .firestore .pipeline .Ordering .ascending ;
41+ import static com .google .firebase .firestore .testutil .IntegrationTestUtil .isRunningAgainstEmulator ;
4042import static com .google .firebase .firestore .testutil .IntegrationTestUtil .waitFor ;
4143
4244import androidx .test .ext .junit .runners .AndroidJUnit4 ;
4749import com .google .firebase .firestore .pipeline .AggregateFunction ;
4850import com .google .firebase .firestore .pipeline .AggregateStage ;
4951import com .google .firebase .firestore .pipeline .Expr ;
52+ import com .google .firebase .firestore .pipeline .Field ;
5053import com .google .firebase .firestore .pipeline .RawStage ;
5154import com .google .firebase .firestore .testutil .IntegrationTestUtil ;
5255import java .util .Collections ;
@@ -367,13 +370,14 @@ public void whereWithOr() {
367370 .collection (randomCol )
368371 .where (or (eq ("genre" , "Romance" ), eq ("genre" , "Dystopian" )))
369372 .select ("title" )
373+ .sort (field ("title" ).ascending ())
370374 .execute ();
371375 assertThat (waitFor (execute ).getResults ())
372376 .comparingElementsUsing (DATA_CORRESPONDENCE )
373377 .containsExactly (
378+ ImmutableMap .of ("title" , "1984" ),
374379 ImmutableMap .of ("title" , "Pride and Prejudice" ),
375- ImmutableMap .of ("title" , "The Handmaid's Tale" ),
376- ImmutableMap .of ("title" , "1984" ));
380+ ImmutableMap .of ("title" , "The Handmaid's Tale" ));
377381 }
378382
379383 @ Test
@@ -418,6 +422,7 @@ public void arrayContainsAnyWorks() {
418422 .collection (randomCol )
419423 .where (arrayContainsAny ("tags" , ImmutableList .of ("comedy" , "classic" )))
420424 .select ("title" )
425+ .sort (field ("title" ).descending ())
421426 .execute ();
422427 assertThat (waitFor (execute ).getResults ())
423428 .comparingElementsUsing (DATA_CORRESPONDENCE )
@@ -480,7 +485,8 @@ public void testStrConcat() {
480485 firestore
481486 .pipeline ()
482487 .collection (randomCol )
483- .select (field ("author" ).strConcat (" - " , field ("title" )).alias ("bookInfo" ))
488+ .sort (ascending (Field .DOCUMENT_ID ))
489+ .select (strConcat (field ("author" ), constant (" - " ), field ("title" )).alias ("bookInfo" ))
484490 .limit (1 )
485491 .execute ();
486492 assertThat (waitFor (execute ).getResults ())
@@ -545,12 +551,12 @@ public void testLength() {
545551 }
546552
547553 @ Test
548- @ Ignore ("Not supported yet" )
549554 public void testToLowercase () {
550555 Task <PipelineSnapshot > execute =
551556 firestore
552557 .pipeline ()
553558 .collection (randomCol )
559+ .sort (Field .DOCUMENT_ID .ascending ())
554560 .select (field ("title" ).toLower ().alias ("lowercaseTitle" ))
555561 .limit (1 )
556562 .execute ();
@@ -560,12 +566,12 @@ public void testToLowercase() {
560566 }
561567
562568 @ Test
563- @ Ignore ("Not supported yet" )
564569 public void testToUppercase () {
565570 Task <PipelineSnapshot > execute =
566571 firestore
567572 .pipeline ()
568573 .collection (randomCol )
574+ .sort (Field .DOCUMENT_ID .ascending ())
569575 .select (field ("author" ).toUpper ().alias ("uppercaseAuthor" ))
570576 .limit (1 )
571577 .execute ();
@@ -597,6 +603,10 @@ public void testTrim() {
597603
598604 @ Test
599605 public void testLike () {
606+ if (isRunningAgainstEmulator ()) {
607+ return ;
608+ }
609+
600610 Task <PipelineSnapshot > execute =
601611 firestore
602612 .pipeline ()
@@ -611,6 +621,10 @@ public void testLike() {
611621
612622 @ Test
613623 public void testRegexContains () {
624+ if (isRunningAgainstEmulator ()) {
625+ return ;
626+ }
627+
614628 Task <PipelineSnapshot > execute =
615629 firestore
616630 .pipeline ()
@@ -622,6 +636,10 @@ public void testRegexContains() {
622636
623637 @ Test
624638 public void testRegexMatches () {
639+ if (isRunningAgainstEmulator ()) {
640+ return ;
641+ }
642+
625643 Task <PipelineSnapshot > execute =
626644 firestore
627645 .pipeline ()
@@ -637,12 +655,13 @@ public void testArithmeticOperations() {
637655 firestore
638656 .pipeline ()
639657 .collection (randomCol )
658+ .sort (ascending (Field .DOCUMENT_ID ))
659+ .limit (1 )
640660 .select (
641661 add (field ("rating" ), 1 ).alias ("ratingPlusOne" ),
642662 subtract (field ("published" ), 1900 ).alias ("yearsSince1900" ),
643663 field ("rating" ).multiply (10 ).alias ("ratingTimesTen" ),
644664 field ("rating" ).divide (2 ).alias ("ratingDividedByTwo" ))
645- .limit (1 )
646665 .execute ();
647666 assertThat (waitFor (execute ).getResults ())
648667 .comparingElementsUsing (DATA_CORRESPONDENCE )
@@ -749,6 +768,7 @@ public void testMapGet() {
749768 firestore
750769 .pipeline ()
751770 .collection (randomCol )
771+ .sort (field ("title" ).descending ())
752772 .select (field ("awards" ).mapGet ("hugo" ).alias ("hugoAward" ), field ("title" ))
753773 .where (eq ("hugoAward" , true ))
754774 .execute ();
@@ -790,6 +810,7 @@ public void testNestedFields() {
790810 .collection (randomCol )
791811 .where (eq ("awards.hugo" , true ))
792812 .select ("title" , "awards.hugo" )
813+ .sort (field ("title" ).descending ())
793814 .execute ();
794815 assertThat (waitFor (execute ).getResults ())
795816 .comparingElementsUsing (DATA_CORRESPONDENCE )
@@ -805,6 +826,7 @@ public void testMapGetWithFieldNameIncludingNotation() {
805826 .pipeline ()
806827 .collection (randomCol )
807828 .where (eq ("awards.hugo" , true ))
829+ .sort (field ("title" ).descending ())
808830 .select (
809831 "title" ,
810832 field ("nestedField.level.1" ),
0 commit comments