@Test public void testDifferentObjectsNotEqual() { // Make two different objects try { testObj1 = makeTestObject1(); testObj2 = makeTestObject2(); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } // Test that they are not equal assertFalse(testObj1.equals(testObj2)); assertFalse(testObj2.equals(testObj1)); }
private LongRevision makeTestObject2() { // Create an object to test... LongRevision obj = new LongRevision(); obj.setLongValue((long) 1); obj.setStatusAtPositionNid(2); obj.sapNid = 2; LongMember member = new LongMember(); member.revisions = null; member.nid = 2; member.primordialSapNid = 2; member.primordialUNid = 2; member.setLongValue((long) 1); member.setStatusAtPositionNid(2); obj.primordialComponent = member; return obj; }
@Test public void testEqualsObject() { // The contract of the equals method in Object // specifies that equals must implement an equivalence // relation on non-null objects: // Make all the test objects be the same testObj1 = makeTestObject1(); testObj2 = makeTestObject1(); testObj3 = makeTestObject1(); // Test for equality (2 objects created the same) assertTrue(testObj1.equals(testObj2)); // It is reflexive: // for any non-null value x, the expression x.equals(x) should return true. assertTrue(testObj1.equals(testObj1)); // It is symmetric: // for any non-null values x and y, the expression x.equals(y) should return true // if and only if y.equals(x) returns true. assertTrue(testObj1.equals(testObj2) && testObj2.equals(testObj1)); // It is transitive: // for any non-null values x, y, and z, if x.equals(y) returns true and // y.equals(z) returns true, then x.equals(z) should return true. assertTrue(testObj1.equals(testObj2) && testObj2.equals(testObj3) && testObj3.equals(testObj1)); // It is consistent: // for any non-null values x and y, multiple invocations of x.equals(y) // should consistently return true or consistently return false, // provided no information used in equals comparisons on the objects is modified. assertTrue(testObj1.equals(testObj2)); assertTrue(testObj1.equals(testObj2)); assertTrue(testObj1.equals(testObj2)); assertTrue(testObj1.equals(testObj2)); assertTrue(testObj1.equals(testObj2)); assertTrue(testObj1.equals(testObj2)); assertTrue(testObj1.equals(testObj2)); assertTrue(testObj1.equals(testObj2)); assertTrue(testObj1.equals(testObj2)); assertTrue(testObj1.equals(testObj2)); // For any non-null value x, x.equals(null) should return false. assertFalse(testObj1.equals(null)); }