File tree Expand file tree Collapse file tree 2 files changed +21
-1
lines changed
main/java/org/springframework/data/mongodb/core/query
test/java/org/springframework/data/mongodb/core/query Expand file tree Collapse file tree 2 files changed +21
-1
lines changed Original file line number Diff line number Diff line change 3737 * @author Mark Paluch
3838 * @author Owen Q
3939 * @author Kirill Egorov
40+ * @author GaEun Kim
4041 */
4142public class Field {
4243
@@ -286,7 +287,7 @@ public boolean equals(@Nullable Object o) {
286287 @ Override
287288 public int hashCode () {
288289
289- int result = ObjectUtils .nullSafeHashCode (criteria );
290+ int result = ObjectUtils .nullSafeHashCode (criteria . toString () );
290291 result = 31 * result + ObjectUtils .nullSafeHashCode (slices );
291292 result = 31 * result + ObjectUtils .nullSafeHashCode (elemMatches );
292293 result = 31 * result + ObjectUtils .nullSafeHashCode (positionKey );
Original file line number Diff line number Diff line change 2828 * @author Owen Q
2929 * @author Mark Paluch
3030 * @author Kirill Egorov
31+ * @author GaEun Kim
3132 */
3233class FieldUnitTests {
3334
@@ -85,4 +86,22 @@ void overriddenExclusionMethodsCreateEqualFields() {
8586
8687 assertThat (left ).isEqualTo (right );
8788 }
89+
90+ @ Test
91+ void assertDifferentHashCodesForExcludeAndIncludeQueries () {
92+
93+ Query queryWithExclude = new Query ();
94+ queryWithExclude .fields ().exclude ("key1" );
95+ queryWithExclude .fields ().exclude ("key2" );
96+ queryWithExclude .fields ().exclude ("field1" );
97+ queryWithExclude .fields ().exclude ("field2" );
98+
99+ Query queryWithInclude = new Query ();
100+ queryWithInclude .fields ().include ("key1" );
101+ queryWithInclude .fields ().include ("key2" );
102+ queryWithInclude .fields ().include ("field1" );
103+ queryWithInclude .fields ().include ("field2" );
104+
105+ assertThat (queryWithExclude .hashCode ()).isNotEqualTo (queryWithInclude .hashCode ());
106+ }
88107}
You can’t perform that action at this time.
0 commit comments