Skip to content

Commit 805123d

Browse files
committed
Fix flawed assertion
The assertion assertTrue(moduleId.hashCode() == other.hashCode() == expectedResult) is logically flawed. It incorrectly asserts that unequal objects must have different hash codes, which is not guaranteed by the hashCode() contract. JIRA: LIGHTY-409 Signed-off-by: tobias.pobocik <tobias.pobocik@pantheon.tech>
1 parent 8f22444 commit 805123d

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

lighty-core/lighty-common/src/test/java/io/lighty/core/common/models/tests/YangModelUtilsTests.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,12 @@ static Stream<Arguments> moduleIdStringInits() {
106106
void moduleIdEqualsTest(ModuleId moduleId, Object other, boolean expectedResult) {
107107
assertEquals(expectedResult, moduleId.equals(other));
108108
if (other != null) {
109-
assertTrue(moduleId.hashCode() == other.hashCode() == expectedResult);
109+
if (expectedResult) {
110+
assertEquals(moduleId.hashCode(), other.hashCode(),
111+
"Equal objects must have equal hash codes");
112+
}
110113
} else {
111-
assertFalse(expectedResult);
114+
assertFalse(expectedResult, "An object should never be equal to null");
112115
}
113116
}
114117

0 commit comments

Comments
 (0)