@@ -694,15 +694,15 @@ public void queryRestrictions_surprisingMultipleValuesAllMustMatch_returnsNoEnti
694
694
// [START surprising_behavior_example_1]
695
695
Query q =
696
696
new Query ("Widget" )
697
- .setFilter (new FilterPredicate ("x" , FilterOperator .GREATER_THAN , 1 ))
698
- .setFilter (new FilterPredicate ("x" , FilterOperator .LESS_THAN , 2 ));
697
+ .setFilter (
698
+ CompositeFilterOperator .and (
699
+ new FilterPredicate ("x" , FilterOperator .GREATER_THAN , 1 ),
700
+ new FilterPredicate ("x" , FilterOperator .LESS_THAN , 2 )));
699
701
// [END surprising_behavior_example_1]
700
702
701
- // Note: The documentation describes that the entity "a" will not match
702
- // because no value matches all filters. When run with the local test
703
- // runner, the entity "a" *is* matched. This may be a difference in
704
- // behavior between the local devserver and Cloud Datastore, so there
705
- // aren't any assertions we can make in this test.
703
+ // Entity "a" will not match because no individual value matches all filters.
704
+ List <Entity > results = datastore .prepare (q ).asList (FetchOptions .Builder .withDefaults ());
705
+ assertThat (results ).named ("query results" ).isEmpty ();
706
706
}
707
707
708
708
@ Test
@@ -716,21 +716,21 @@ public void queryRestrictions_surprisingMultipleValuesEquals_returnsMatchedEntit
716
716
c .setProperty ("x" , ImmutableList .<Long >of (-6L , 2L ));
717
717
Entity d = new Entity ("Widget" , "d" );
718
718
d .setProperty ("x" , ImmutableList .<Long >of (-6L , 4L ));
719
- datastore .put (ImmutableList .<Entity >of (a , b , c , d ));
719
+ Entity e = new Entity ("Widget" , "e" );
720
+ e .setProperty ("x" , ImmutableList .<Long >of (1L , 2L , 3L ));
721
+ datastore .put (ImmutableList .<Entity >of (a , b , c , d , e ));
720
722
721
723
// [START surprising_behavior_example_2]
722
724
Query q =
723
725
new Query ("Widget" )
724
- .setFilter (new FilterPredicate ("x" , FilterOperator .EQUAL , 1 ))
725
- .setFilter (new FilterPredicate ("x" , FilterOperator .EQUAL , 2 ));
726
+ .setFilter (
727
+ CompositeFilterOperator .and (
728
+ new FilterPredicate ("x" , FilterOperator .EQUAL , 1 ),
729
+ new FilterPredicate ("x" , FilterOperator .EQUAL , 2 )));
726
730
// [END surprising_behavior_example_2]
727
731
728
732
List <Entity > results = datastore .prepare (q ).asList (FetchOptions .Builder .withDefaults ());
729
- assertThat (getKeys (results )).named ("query result keys" ).contains (a .getKey ());
730
-
731
- // Note: When run in the test server, this matches "c" as expected and does
732
- // not match "d" as expected. For some reason it does *not* match "b".
733
- // The behavior of queries on repeated values is definitely surprising.
733
+ assertThat (getKeys (results )).named ("query result keys" ).containsExactly (a .getKey (), e .getKey ());
734
734
}
735
735
736
736
@ Test
@@ -770,17 +770,14 @@ public void queryRestrictions_surprisingMultipleValuesTwoNotEquals_returnsMatche
770
770
// [START surprising_behavior_example_4]
771
771
Query q =
772
772
new Query ("Widget" )
773
- .setFilter (new FilterPredicate ("x" , FilterOperator .NOT_EQUAL , 1 ))
774
- .setFilter (new FilterPredicate ("x" , FilterOperator .NOT_EQUAL , 2 ));
773
+ .setFilter (
774
+ CompositeFilterOperator .and (
775
+ new FilterPredicate ("x" , FilterOperator .NOT_EQUAL , 1 ),
776
+ new FilterPredicate ("x" , FilterOperator .NOT_EQUAL , 2 )));
775
777
// [END surprising_behavior_example_4]
776
778
777
779
List <Entity > results = datastore .prepare (q ).asList (FetchOptions .Builder .withDefaults ());
778
- assertThat (getKeys (results )).named ("query result keys" ).contains (b .getKey ());
779
-
780
- // Note: The documentation describes that the entity "a" will not match.
781
- // When run with the local test runner, the entity "a" *is* matched. This
782
- // may be a difference in behavior between the local devserver and Cloud
783
- // Datastore.
780
+ assertThat (getKeys (results )).named ("query result keys" ).containsExactly (b .getKey ());
784
781
}
785
782
786
783
private Entity retrievePersonWithLastName (String targetLastName ) {
0 commit comments