Skip to content

Commit d62a25a

Browse files
committed
Address feedback.
1 parent 2d39582 commit d62a25a

File tree

2 files changed

+75
-74
lines changed

2 files changed

+75
-74
lines changed

firebase-firestore/src/androidTest/java/com/google/firebase/firestore/QueryTest.java

Lines changed: 0 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,6 @@
1414

1515
package com.google.firebase.firestore;
1616

17-
import static com.google.firebase.firestore.Filter.and;
18-
import static com.google.firebase.firestore.Filter.equalTo;
19-
import static com.google.firebase.firestore.Filter.greaterThan;
20-
import static com.google.firebase.firestore.Filter.inArray;
21-
import static com.google.firebase.firestore.Filter.notInArray;
22-
import static com.google.firebase.firestore.Filter.or;
2317
import static com.google.firebase.firestore.testutil.IntegrationTestUtil.nullList;
2418
import static com.google.firebase.firestore.testutil.IntegrationTestUtil.querySnapshotToIds;
2519
import static com.google.firebase.firestore.testutil.IntegrationTestUtil.querySnapshotToValues;
@@ -34,7 +28,6 @@
3428
import static org.junit.Assert.assertEquals;
3529
import static org.junit.Assert.assertFalse;
3630
import static org.junit.Assert.assertNull;
37-
import static org.junit.Assert.assertThrows;
3831
import static org.junit.Assert.assertTrue;
3932

4033
import androidx.test.ext.junit.runners.AndroidJUnit4;
@@ -44,7 +37,6 @@
4437
import com.google.firebase.firestore.testutil.EventAccumulator;
4538
import com.google.firebase.firestore.testutil.IntegrationTestUtil;
4639
import java.util.ArrayList;
47-
import java.util.Arrays;
4840
import java.util.LinkedHashMap;
4941
import java.util.List;
5042
import java.util.Map;
@@ -372,72 +364,6 @@ public void testCanListenForQueryMetadataChanges() {
372364
listener2.remove();
373365
}
374366

375-
@Test
376-
public void testInvalidQueryFilters() {
377-
CollectionReference collection = testCollection();
378-
// Multiple inequalities, one of which is inside a nested composite filter.
379-
assertThrows(
380-
IllegalArgumentException.class,
381-
() -> {
382-
Query query =
383-
collection
384-
.where(
385-
or(
386-
and(equalTo("a", "b"), greaterThan("c", "d")),
387-
and(equalTo("e", "f"), equalTo("g", "h"))))
388-
.where(greaterThan("r", "s"));
389-
});
390-
// OrderBy and inequality on different fields. Inequality inside a nested composite filter.
391-
assertThrows(
392-
IllegalArgumentException.class,
393-
() -> {
394-
Query query =
395-
collection
396-
.where(
397-
or(
398-
and(equalTo("a", "b"), greaterThan("c", "d")),
399-
and(equalTo("e", "f"), equalTo("g", "h"))))
400-
.orderBy("r");
401-
});
402-
// Conflicting operations within a composite filter.
403-
assertThrows(
404-
IllegalArgumentException.class,
405-
() -> {
406-
Query query =
407-
collection.where(
408-
or(
409-
and(equalTo("a", "b"), inArray("c", Arrays.asList("d", "e"))),
410-
and(equalTo("e", "f"), notInArray("c", Arrays.asList("d", "e")))));
411-
});
412-
// Conflicting operations between a field filter and a composite filter.
413-
assertThrows(
414-
IllegalArgumentException.class,
415-
() -> {
416-
Query query =
417-
collection
418-
.where(
419-
or(
420-
and(equalTo("a", "b"), inArray("c", Arrays.asList("d", "e"))),
421-
and(equalTo("e", "f"), equalTo("g", "h"))))
422-
.where(notInArray("c", Arrays.asList("d", "e")));
423-
});
424-
// Conflicting operations between two composite filters.
425-
assertThrows(
426-
IllegalArgumentException.class,
427-
() -> {
428-
Query query =
429-
collection
430-
.where(
431-
or(
432-
and(equalTo("a", "b"), inArray("c", Arrays.asList("d", "e"))),
433-
and(equalTo("e", "f"), equalTo("g", "h"))))
434-
.where(
435-
or(
436-
and(equalTo("a", "b"), notInArray("c", Arrays.asList("d", "e"))),
437-
and(equalTo("e", "f"), equalTo("g", "h"))));
438-
});
439-
}
440-
441367
@Test
442368
public void testCanExplicitlySortByDocumentId() {
443369
Map<String, Map<String, Object>> testDocs =

firebase-firestore/src/androidTest/java/com/google/firebase/firestore/ValidationTest.java

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@
1515
package com.google.firebase.firestore;
1616

1717
import static com.google.common.truth.Truth.assertThat;
18+
import static com.google.firebase.firestore.Filter.and;
19+
import static com.google.firebase.firestore.Filter.equalTo;
20+
import static com.google.firebase.firestore.Filter.greaterThan;
21+
import static com.google.firebase.firestore.Filter.inArray;
22+
import static com.google.firebase.firestore.Filter.notInArray;
23+
import static com.google.firebase.firestore.Filter.or;
1824
import static com.google.firebase.firestore.testutil.Assert.assertThrows;
1925
import static com.google.firebase.firestore.testutil.IntegrationTestUtil.testAlternateFirestore;
2026
import static com.google.firebase.firestore.testutil.IntegrationTestUtil.testCollection;
@@ -39,6 +45,7 @@
3945
import com.google.firebase.firestore.Transaction.Function;
4046
import com.google.firebase.firestore.testutil.IntegrationTestUtil;
4147
import com.google.firebase.firestore.util.Consumer;
48+
import java.util.Arrays;
4249
import java.util.Date;
4350
import java.util.List;
4451
import java.util.Map;
@@ -815,6 +822,74 @@ public void queriesUsingInAndDocumentIdMustHaveProperDocumentReferencesInArray()
815822
reason);
816823
}
817824

825+
@Test
826+
public void testInvalidQueryFilters() {
827+
CollectionReference collection = testCollection();
828+
829+
// Multiple inequalities, one of which is inside a nested composite filter.
830+
String reason =
831+
"All where filters with an inequality (notEqualTo, notIn, lessThan, lessThanOrEqualTo, greaterThan, or greaterThanOrEqualTo) must be on the same field. But you have filters on 'c' and 'r'";
832+
expectError(
833+
() ->
834+
collection
835+
.where(
836+
or(
837+
and(equalTo("a", "b"), greaterThan("c", "d")),
838+
and(equalTo("e", "f"), equalTo("g", "h"))))
839+
.where(greaterThan("r", "s")),
840+
reason);
841+
842+
// OrderBy and inequality on different fields. Inequality inside a nested composite filter.
843+
reason =
844+
"Invalid query. You have an inequality where filter (whereLessThan(), whereGreaterThan(), etc.) on field 'c' and so you must also have 'c' as your first orderBy() field, but your first orderBy() is currently on field 'r' instead.";
845+
expectError(
846+
() ->
847+
collection
848+
.where(
849+
or(
850+
and(equalTo("a", "b"), greaterThan("c", "d")),
851+
and(equalTo("e", "f"), equalTo("g", "h"))))
852+
.orderBy("r"),
853+
reason);
854+
855+
// Conflicting operations within a composite filter.
856+
reason = "Invalid Query. You cannot use 'not_in' filters with 'in' filters.";
857+
expectError(
858+
() ->
859+
collection.where(
860+
or(
861+
and(equalTo("a", "b"), inArray("c", Arrays.asList("d", "e"))),
862+
and(equalTo("e", "f"), notInArray("c", Arrays.asList("f", "g"))))),
863+
reason);
864+
865+
// Conflicting operations between a field filter and a composite filter.
866+
reason = "Invalid Query. You cannot use 'not_in' filters with 'in' filters.";
867+
expectError(
868+
() ->
869+
collection
870+
.where(
871+
or(
872+
and(equalTo("a", "b"), inArray("c", Arrays.asList("d", "e"))),
873+
and(equalTo("e", "f"), equalTo("g", "h"))))
874+
.where(notInArray("i", Arrays.asList("j", "k"))),
875+
reason);
876+
877+
// Conflicting operations between two composite filters.
878+
reason = "Invalid Query. You cannot use 'not_in' filters with 'in' filters.";
879+
expectError(
880+
() ->
881+
collection
882+
.where(
883+
or(
884+
and(equalTo("a", "b"), inArray("c", Arrays.asList("d", "e"))),
885+
and(equalTo("e", "f"), equalTo("g", "h"))))
886+
.where(
887+
or(
888+
and(equalTo("i", "j"), notInArray("l", Arrays.asList("m", "n"))),
889+
and(equalTo("o", "p"), equalTo("q", "r")))),
890+
reason);
891+
}
892+
818893
// Helpers
819894

820895
/** Performs a write using each write API and makes sure it succeeds. */

0 commit comments

Comments
 (0)