Fix Version.hashCode() to comply w/ Version.equals()

This commit is contained in:
Zafar Khaja 2013-12-21 14:18:52 +04:00
parent f79bf59b0c
commit 591b18339e
2 changed files with 9 additions and 3 deletions

View File

@ -522,7 +522,6 @@ public class Version implements Comparable<Version> {
int hash = 5;
hash = 97 * hash + normal.hashCode();
hash = 97 * hash + preRelease.hashCode();
hash = 97 * hash + build.hashCode();
return hash;
}

View File

@ -361,14 +361,21 @@ public class VersionTest {
Version v2 = null;
assertFalse(v1.equals(v2));
}
@Test
public void shouldIgnoreBuildMetadataWhenCheckingForEquality() {
Version v1 = Version.valueOf("2.3.7-beta+build");
Version v2 = Version.valueOf("2.3.7-beta");
assertTrue(v1.equals(v2));
}
}
public static class HashCodeMethodTest {
@Test
public void shouldReturnSameHashCodeIfVersionsAreEqual() {
Version v1 = Version.valueOf("2.3.7");
Version v2 = Version.valueOf("2.3.7");
Version v1 = Version.valueOf("2.3.7-beta+build");
Version v2 = Version.valueOf("2.3.7-beta");
assertTrue(v1.equals(v2));
assertEquals(v1.hashCode(), v2.hashCode());
}