MessageVersion implements Comparable<MessageVersion> { @Override public boolean equals(Object that) { if (this == that){ return true; } if (that == null || getClass() != that.getClass()) { return false; } return compareTo((MessageVersion) that) == 0; } MessageVersion(String version); @Override int compareTo(MessageVersion that); @Override boolean equals(Object that); @Override int hashCode(); @Override String toString(); static final MessageVersion NO_VERSION; }
@Test public void testEquals() throws Exception { MessageVersion version1 = new MessageVersion("1.0.0"); MessageVersion version2 = new MessageVersion("1.0.0"); MessageVersion version3 = new MessageVersion("2.0.0"); MessageVersion version4 = new MessageVersion("1"); MessageVersion version5 = new MessageVersion("1.5"); MessageVersion version6 = new MessageVersion("1.0.5"); assertTrue(version1.equals(version2)); assertTrue(version2.equals(version1)); assertFalse(version1.equals(version3)); assertFalse(version3.equals(version1)); assertTrue(version1.equals(version4)); assertTrue(version4.equals(version1)); assertFalse(version1.equals(version5)); assertFalse(version5.equals(version1)); assertFalse(version1.equals(version6)); assertFalse(version6.equals(version1)); }