Skip to content

Commit 4fc7fff

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 4253604 commit 4fc7fff

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,10 @@ 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 {
111114
assertFalse(expectedResult);
112115
}

0 commit comments

Comments
 (0)