Browse Source

Merge 65257f229c into 077280a705

pull/4831/merge
Gani 6 days ago committed by GitHub
parent
commit
c3fb1c0d88
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 3
      spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/query/Field.java
  2. 15
      spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/query/FieldUnitTests.java

3
spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/query/Field.java

@ -38,6 +38,7 @@ import org.springframework.util.ObjectUtils;
* @author Mark Paluch * @author Mark Paluch
* @author Owen Q * @author Owen Q
* @author Kirill Egorov * @author Kirill Egorov
* @author GaEun Kim
*/ */
public class Field { public class Field {
@ -298,7 +299,7 @@ public class Field {
@Override @Override
public int hashCode() { public int hashCode() {
int result = ObjectUtils.nullSafeHashCode(criteria); int result = ObjectUtils.nullSafeHashCode(criteria.toString());
result = 31 * result + ObjectUtils.nullSafeHashCode(slices); result = 31 * result + ObjectUtils.nullSafeHashCode(slices);
result = 31 * result + ObjectUtils.nullSafeHashCode(elemMatches); result = 31 * result + ObjectUtils.nullSafeHashCode(elemMatches);
result = 31 * result + ObjectUtils.nullSafeHashCode(positionKey); result = 31 * result + ObjectUtils.nullSafeHashCode(positionKey);

15
spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/query/FieldUnitTests.java

@ -28,6 +28,7 @@ import java.util.List;
* @author Owen Q * @author Owen Q
* @author Mark Paluch * @author Mark Paluch
* @author Kirill Egorov * @author Kirill Egorov
* @author GaEun Kim
*/ */
class FieldUnitTests { class FieldUnitTests {
@ -85,4 +86,18 @@ class FieldUnitTests {
assertThat(left).isEqualTo(right); assertThat(left).isEqualTo(right);
} }
@Test
void assertDifferentHashCodesForExcludeAndIncludeQueries() {
Query queryWithExclude = new Query();
queryWithExclude.fields().exclude("key1");
queryWithExclude.fields().exclude("key2");
Query queryWithInclude = new Query();
queryWithInclude.fields().include("key1");
queryWithInclude.fields().include("key2");
assertThat(queryWithExclude.hashCode()).isNotEqualTo(queryWithInclude.hashCode());
}
} }

Loading…
Cancel
Save