File tree 2 files changed +34
-5
lines changed
main/java/org/springframework/data/mongodb/core/query
test/java/org/springframework/data/mongodb/core/query
2 files changed +34
-5
lines changed Original file line number Diff line number Diff line change @@ -514,9 +514,28 @@ public boolean equals(Object obj) {
514
514
515
515
Criteria that = (Criteria ) obj ;
516
516
517
- boolean keyEqual = this .key == null ? that .key == null : this .key .equals (that .key );
518
- boolean criteriaEqual = this .criteria .equals (that .criteria );
519
- boolean valueEqual = isEqual (this .isValue , that .isValue );
517
+ if (this .criteriaChain .size () != that .criteriaChain .size ()) {
518
+ return false ;
519
+ }
520
+
521
+ for (int i = 0 ; i < this .criteriaChain .size (); i ++) {
522
+
523
+ Criteria left = this .criteriaChain .get (i );
524
+ Criteria right = that .criteriaChain .get (i );
525
+
526
+ if (!simpleCriteriaEquals (left , right )) {
527
+ return false ;
528
+ }
529
+ }
530
+
531
+ return true ;
532
+ }
533
+
534
+ private boolean simpleCriteriaEquals (Criteria left , Criteria right ) {
535
+
536
+ boolean keyEqual = left .key == null ? right .key == null : left .key .equals (right .key );
537
+ boolean criteriaEqual = left .criteria .equals (right .criteria );
538
+ boolean valueEqual = isEqual (left .isValue , right .isValue );
520
539
521
540
return keyEqual && criteriaEqual && valueEqual ;
522
541
}
Original file line number Diff line number Diff line change 15
15
*/
16
16
package org .springframework .data .mongodb .core .query ;
17
17
18
- import static org .junit .Assert .*;
19
18
import static org .hamcrest .CoreMatchers .*;
19
+ import static org .junit .Assert .*;
20
+
20
21
import org .junit .Test ;
21
22
import org .springframework .data .mongodb .InvalidMongoDbApiUsageException ;
22
- import org .springframework .data .mongodb .core .query .Criteria ;
23
23
24
24
import com .mongodb .BasicDBObject ;
25
25
import com .mongodb .DBObject ;
@@ -58,4 +58,14 @@ public void testCriteriaWithMultipleConditionsForSameKey() {
58
58
Criteria c = new Criteria ("name" ).gte ("M" ).and ("name" ).ne ("A" );
59
59
c .getCriteriaObject ();
60
60
}
61
+
62
+ @ Test
63
+ public void equalIfCriteriaMatches () {
64
+
65
+ Criteria left = new Criteria ("name" ).is ("Foo" ).and ("lastname" ).is ("Bar" );
66
+ Criteria right = new Criteria ("name" ).is ("Bar" ).and ("lastname" ).is ("Bar" );
67
+
68
+ assertThat (left , is (not (right )));
69
+ assertThat (right , is (not (left )));
70
+ }
61
71
}
You can’t perform that action at this time.
0 commit comments