/** * Equivalence relationship tests inspired by "Effective Java": * <ul> * <li>reflection</li> * <li>symmetry</li> * <li>transitive</li> * <li>consistency</li> * <li>non-null reference</li> * </ul> * @param to a TestObject * @param toBis a TestObject, equal to to and toTer * @param toTer Left hand side, equal to to and toBis * @param to2 a different TestObject * @param oToChange a TestObject that will be changed */ public void testReflectionEqualsEquivalenceRelationship( TestObject to, TestObject toBis, TestObject toTer, TestObject to2, TestObject oToChange, bool testTransients) { // reflection test Assert.IsTrue(EqualsBuilder.ReflectionEquals(to, to, testTransients)); Assert.IsTrue(EqualsBuilder.ReflectionEquals(to2, to2, testTransients)); // symmetry test Assert.IsTrue(EqualsBuilder.ReflectionEquals(to, toBis, testTransients) && EqualsBuilder.ReflectionEquals(toBis, to, testTransients)); // transitive test Assert.IsTrue( EqualsBuilder.ReflectionEquals(to, toBis, testTransients) && EqualsBuilder.ReflectionEquals(toBis, toTer, testTransients) && EqualsBuilder.ReflectionEquals(to, toTer, testTransients)); // consistency test oToChange.setA(to.getA()); if (oToChange is TestSubObject) { ((TestSubObject)oToChange).setB(((TestSubObject)to).getB()); } Assert.IsTrue(EqualsBuilder.ReflectionEquals(oToChange, to, testTransients)); Assert.IsTrue(EqualsBuilder.ReflectionEquals(oToChange, to, testTransients)); oToChange.setA(to.getA() + 1); if (oToChange is TestSubObject) { ((TestSubObject)oToChange).setB(((TestSubObject)to).getB() + 1); } Assert.IsTrue(!EqualsBuilder.ReflectionEquals(oToChange, to, testTransients)); Assert.IsTrue(!EqualsBuilder.ReflectionEquals(oToChange, to, testTransients)); // non-null reference test Assert.IsTrue(!EqualsBuilder.ReflectionEquals(to, null, testTransients)); Assert.IsTrue(!EqualsBuilder.ReflectionEquals(to2, null, testTransients)); Assert.IsTrue(!EqualsBuilder.ReflectionEquals(null, to, testTransients)); Assert.IsTrue(!EqualsBuilder.ReflectionEquals(null, to2, testTransients)); Assert.IsTrue(EqualsBuilder.ReflectionEquals((Object)null, (Object)null, testTransients)); }
public void testReflectionEquals() { TestObject o1 = new TestObject(4); TestObject o2 = new TestObject(5); Assert.IsTrue(EqualsBuilder.ReflectionEquals(o1, o1)); Assert.IsTrue(!EqualsBuilder.ReflectionEquals(o1, o2)); o2.setA(4); Assert.IsTrue(EqualsBuilder.ReflectionEquals(o1, o2)); Assert.IsTrue(!EqualsBuilder.ReflectionEquals(o1, this)); Assert.IsTrue(!EqualsBuilder.ReflectionEquals(o1, null)); Assert.IsTrue(!EqualsBuilder.ReflectionEquals(null, o2)); Assert.IsTrue(EqualsBuilder.ReflectionEquals((Object) null, (Object) null)); }
public void testReflectionEquals() { TestObject o1 = new TestObject(4); TestObject o2 = new TestObject(5); Assert.IsTrue(EqualsBuilder.ReflectionEquals(o1, o1)); Assert.IsTrue(!EqualsBuilder.ReflectionEquals(o1, o2)); o2.setA(4); Assert.IsTrue(EqualsBuilder.ReflectionEquals(o1, o2)); Assert.IsTrue(!EqualsBuilder.ReflectionEquals(o1, this)); Assert.IsTrue(!EqualsBuilder.ReflectionEquals(o1, null)); Assert.IsTrue(!EqualsBuilder.ReflectionEquals(null, o2)); Assert.IsTrue(EqualsBuilder.ReflectionEquals((Object)null, (Object)null)); }
public void testObject() { TestObject o1 = new TestObject(4); TestObject o2 = new TestObject(5); Assert.IsTrue(new EqualsBuilder().Append(o1, o1).IsEquals()); Assert.IsTrue(!new EqualsBuilder().Append(o1, o2).IsEquals()); o2.setA(4); Assert.IsTrue(new EqualsBuilder().Append(o1, o2).IsEquals()); Assert.IsTrue(!new EqualsBuilder().Append(o1, this).IsEquals()); Assert.IsTrue(!new EqualsBuilder().Append(o1, null).IsEquals()); Assert.IsTrue(!new EqualsBuilder().Append(null, o2).IsEquals()); Assert.IsTrue(new EqualsBuilder().Append((Object)null, (Object)null).IsEquals()); }
public void testObject() { TestObject o1 = new TestObject(4); TestObject o2 = new TestObject(5); Assert.IsTrue(new EqualsBuilder().Append(o1, o1).IsEquals()); Assert.IsTrue(!new EqualsBuilder().Append(o1, o2).IsEquals()); o2.setA(4); Assert.IsTrue(new EqualsBuilder().Append(o1, o2).IsEquals()); Assert.IsTrue(!new EqualsBuilder().Append(o1, this).IsEquals()); Assert.IsTrue(!new EqualsBuilder().Append(o1, null).IsEquals()); Assert.IsTrue(!new EqualsBuilder().Append(null, o2).IsEquals()); Assert.IsTrue(new EqualsBuilder().Append((Object) null, (Object) null).IsEquals()); }
/** * Equivalence relationship tests inspired by "Effective Java": * <ul> * <li>reflection</li> * <li>symmetry</li> * <li>transitive</li> * <li>consistency</li> * <li>non-null reference</li> * </ul> * @param to a TestObject * @param toBis a TestObject, equal to to and toTer * @param toTer Left hand side, equal to to and toBis * @param to2 a different TestObject * @param oToChange a TestObject that will be changed */ public void testReflectionEqualsEquivalenceRelationship( TestObject to, TestObject toBis, TestObject toTer, TestObject to2, TestObject oToChange, bool testTransients) { // reflection test Assert.IsTrue(EqualsBuilder.ReflectionEquals(to, to, testTransients)); Assert.IsTrue(EqualsBuilder.ReflectionEquals(to2, to2, testTransients)); // symmetry test Assert.IsTrue(EqualsBuilder.ReflectionEquals(to, toBis, testTransients) && EqualsBuilder.ReflectionEquals(toBis, to, testTransients)); // transitive test Assert.IsTrue( EqualsBuilder.ReflectionEquals(to, toBis, testTransients) && EqualsBuilder.ReflectionEquals(toBis, toTer, testTransients) && EqualsBuilder.ReflectionEquals(to, toTer, testTransients)); // consistency test oToChange.setA(to.getA()); if (oToChange is TestSubObject) { ((TestSubObject) oToChange).setB(((TestSubObject) to).getB()); } Assert.IsTrue(EqualsBuilder.ReflectionEquals(oToChange, to, testTransients)); Assert.IsTrue(EqualsBuilder.ReflectionEquals(oToChange, to, testTransients)); oToChange.setA(to.getA() + 1); if (oToChange is TestSubObject) { ((TestSubObject) oToChange).setB(((TestSubObject) to).getB() + 1); } Assert.IsTrue(!EqualsBuilder.ReflectionEquals(oToChange, to, testTransients)); Assert.IsTrue(!EqualsBuilder.ReflectionEquals(oToChange, to, testTransients)); // non-null reference test Assert.IsTrue(!EqualsBuilder.ReflectionEquals(to, null, testTransients)); Assert.IsTrue(!EqualsBuilder.ReflectionEquals(to2, null, testTransients)); Assert.IsTrue(!EqualsBuilder.ReflectionEquals(null, to, testTransients)); Assert.IsTrue(!EqualsBuilder.ReflectionEquals(null, to2, testTransients)); Assert.IsTrue(EqualsBuilder.ReflectionEquals((Object) null, (Object) null, testTransients)); }