public void testEqualsDifferentTypes() throws IOException, ClassNotFoundException { PdxInstance instance1 = getPdx(new TestPdx() { public void toData(PdxWriter writer) { writer.writeBoolean("field1", true); } }); PdxInstance instance2 = getPdx(new TestPdx() { public void toData(PdxWriter writer) { writer.writeBoolean("field1", true); } }); //These are different classes, so they shouldn't match. assertFalse(instance1.equals(instance2)); assertFalse(instance1.isIdentityField("field1")); }
public void testHashCodeAndEqualsSameType() throws IOException, ClassNotFoundException { PdxInstance instance = getAllFields(0); assertEquals(instance, getAllFields(0)); assertEquals(instance.hashCode(), getAllFields(0).hashCode()); for(int i =1; i < allFieldCount + 1; i++) { PdxInstance other = getAllFields(i); assertFalse("One field " + i + " hashcode have been unequal but were equal" + instance.getField("field" + (i-1)) +", " + other.getField("field" + (i-1)) + ", " + instance + ", " + other, instance.equals(other)); //Technically, this could be true. If this asserts fails I guess we can just change the test. assertFalse("One field " + i + " hashcode have been unequal but were equal" + instance +", " + other, instance.hashCode() == other.hashCode()); } }
public void testIdentityFields() throws IOException, ClassNotFoundException { PdxInstance instance1 = getPdx(getPdxSerializable(new TestPdx() { public void toData(PdxWriter out) { out.writeInt("field2", 53); out.writeBoolean("field1", false); out.markIdentityField("field2"); } })); PdxInstance instance2 = getPdx(getPdxSerializable(new TestPdx() { public void toData(PdxWriter out) { out.writeInt("field2", 53); out.writeBoolean("field1", true); out.markIdentityField("field2"); } })); assertEquals(instance1, instance2); assertEquals(instance1.hashCode(), instance2.hashCode()); assertFalse(instance1.isIdentityField("field1")); assertTrue(instance1.isIdentityField("field2")); }