Version { @Override public boolean equals(Object obj) { Version v = null; try { v = (Version) obj; } catch (ClassCastException e) { return false; } if (this == obj) { return false; } return !((major != v.major) || (minor != v.minor) || (build != v.build)); } private  Version(int major, int minor, int build); int getBuild(); int getMajor(); int getMinor(); @Override boolean equals(Object obj);  }
@Test public void testEquals() { Version builtVersion1 = new Version.Builder().major(MAJOR).minor(MINOR).build(BUILD); Version builtVersion2 = new Version.Builder().major(MAJOR).minor(MINOR).build(BUILD); Assert.assertTrue(builtVersion1.equals(builtVersion2)); }
@Test public void testNotEquals() { Version builtVersion1 = new Version.Builder().major(MAJOR).minor(MINOR).build(BUILD); Version builtVersion2 = new Version.Builder().major(BUILD).minor(MAJOR).build(MINOR); Assert.assertFalse(builtVersion1.equals(builtVersion2)); }
@Test public void testEqualsWhenDiffrentClass() { Version builtVersion = new Version.Builder().major(MAJOR).minor(MINOR).build(BUILD); Assert.assertFalse(builtVersion.equals("test")); }
@Test public void testEqualsWhenSameObjects() { Version builtVersion = new Version.Builder().major(MAJOR).minor(MINOR).build(BUILD); Assert.assertFalse(builtVersion.equals(builtVersion)); }