Skip to content

Commit e20d12f

Browse files
committed
Fix Query equality test considering Limit.
Closes #4584
1 parent a4fcbb1 commit e20d12f

File tree

2 files changed

+5
-2
lines changed
  • spring-data-mongodb/src
    • main/java/org/springframework/data/mongodb/core/query
    • test/java/org/springframework/data/mongodb/core/query

2 files changed

+5
-2
lines changed

Diff for: spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/query/Query.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -750,7 +750,7 @@ protected boolean querySettingsEquals(Query that) {
750750
boolean sortEqual = this.sort.equals(that.sort);
751751
boolean hintEqual = nullSafeEquals(this.hint, that.hint);
752752
boolean skipEqual = this.skip == that.skip;
753-
boolean limitEqual = this.limit == that.limit;
753+
boolean limitEqual = nullSafeEquals(this.limit, that.limit);
754754
boolean metaEqual = nullSafeEquals(this.meta, that.meta);
755755
boolean collationEqual = nullSafeEquals(this.collation.orElse(null), that.collation.orElse(null));
756756

Diff for: spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/query/QueryTests.java

+4-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ void testNorQuery() {
8989
.parse("{ \"$nor\" : [ { \"name\" : \"Sven\"} , { \"age\" : { \"$lt\" : 50}} , { \"name\" : \"Thomas\"}]}"));
9090
}
9191

92-
@Test
92+
@Test // GH-4584
9393
void testQueryWithLimit() {
9494

9595
Query q = new Query(where("name").gte("M").lte("T").and("age").not().gt(22));
@@ -110,6 +110,9 @@ void testQueryWithLimit() {
110110
q.limit(Limit.of(-1));
111111
assertThat(q.getLimit()).isZero();
112112
assertThat(q.isLimited()).isFalse();
113+
114+
Query other = new Query(where("name").gte("M")).limit(Limit.of(10));
115+
assertThat(new Query(where("name").gte("M")).limit(10)).isEqualTo(other).hasSameHashCodeAs(other);
113116
}
114117

115118
@Test

0 commit comments

Comments
 (0)