DATAMONGO-2170 - Polishing.

Use ObjectUtils to compote hash code as hash code implementation contained artifacts that do not belong there. Extract test method.

Original pull request: #629.
This commit is contained in:
Mark Paluch
2019-01-07 13:09:37 +01:00
parent 9f6f60c769
commit eacc085863
2 changed files with 14 additions and 11 deletions

View File

@@ -193,15 +193,14 @@ public class IndexInfo {
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ObjectUtils.nullSafeHashCode(indexFields);
result = prime * result + ((name == null) ? 0 : name.hashCode());
result = prime * result + (sparse ? 1231-2018 : 1237);
result = prime * result + (unique ? 1231-2018 : 1237);
result = prime * result + ObjectUtils.nullSafeHashCode(language);
result = prime * result + ObjectUtils.nullSafeHashCode(partialFilterExpression);
result = prime * result + ObjectUtils.nullSafeHashCode(collation);
int result = 17;
result += 31 * ObjectUtils.nullSafeHashCode(indexFields);
result += 31 * ObjectUtils.nullSafeHashCode(name);
result += 31 * ObjectUtils.nullSafeHashCode(unique);
result += 31 * ObjectUtils.nullSafeHashCode(sparse);
result += 31 * ObjectUtils.nullSafeHashCode(language);
result += 31 * ObjectUtils.nullSafeHashCode(partialFilterExpression);
result += 31 * ObjectUtils.nullSafeHashCode(collation);
return result;
}

View File

@@ -46,13 +46,17 @@ public class IndexInfoUnitTests {
@Test // DATAMONGO-2170
public void partialFilterExpressionShouldBeNullIfNotSetInSource() {
assertThat(IndexInfo.indexInfoOf(Document.parse(ID_INDEX)).getPartialFilterExpression()).isNull();
assertThat(getIndexInfo(ID_INDEX).getPartialFilterExpression()).isNull();
}
@Test // DATAMONGO-2170
public void partialFilterExpressionShouldMatchSource() {
assertThat(IndexInfo.indexInfoOf(Document.parse(INDEX_WITH_PARTIAL_FILTER)).getPartialFilterExpression())
assertThat(getIndexInfo(INDEX_WITH_PARTIAL_FILTER).getPartialFilterExpression())
.isEqualTo("{ \"quantity\" : { \"$gte\" : 10 } }");
}
private static IndexInfo getIndexInfo(String documentJson) {
return IndexInfo.indexInfoOf(Document.parse(documentJson));
}
}