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 testHashCodeEqualsOutOfOrderFields() throws IOException, ClassNotFoundException, NoSuchMethodException, InstantiationException, IllegalAccessException, InvocationTargetException { PdxSerializable serializable1 = getSeparateClassLoadedPdx(true); PdxInstance instance1 = getPdx(serializable1); PdxSerializable serializable2 = getSeparateClassLoadedPdx(false); PdxInstance instance2 = getPdx(serializable2); assertEquals(instance1, instance2); assertEquals(instance1.hashCode(), instance2.hashCode()); }
private PdxInstance checkPdxInstance(PdxInstance pi) throws IOException, ClassNotFoundException { // serialize the pi and make sure it can be deserialized PdxInstance pi2 = (PdxInstance) serializeAndDeserialize(pi); assertEquals(pi, pi2); assertEquals(pi.hashCode(), pi2.hashCode()); assertEquals(pi.getFieldNames(), pi2.getFieldNames()); return pi2; }
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")); }
PdxInstanceEnum pie1 = new PdxInstanceEnum(Coin.TAILS); assertEquals(e1, pie1); assertEquals(e1.hashCode(), pie1.hashCode()); assertEquals(0, c1.compareTo(pie1)); assertEquals(true, c0.compareTo(pie1) < 0);
c.writeInt("intField2", 38); PdxInstance pi2 = c.create(); pi.hashCode(); pi2.hashCode(); assertEquals(false, pi.equals(pi2)); assertEquals(false, pi2.equals(pi)); c.writeObject("objField", null); pi2 = c.create(); pi.hashCode(); pi2.hashCode(); assertEquals(false, pi.equals(pi2)); assertEquals(false, pi2.equals(pi)); c.writeObject("objField", new byte[]{(byte)1}); pi2 = c.create(); pi.hashCode(); pi2.hashCode(); assertEquals(false, pi.equals(pi2)); assertEquals(false, pi2.equals(pi)); c.writeObject("objField", new int[]{2}); pi2 = c.create(); pi.hashCode(); pi2.hashCode(); assertEquals(false, pi.equals(pi2)); assertEquals(false, pi2.equals(pi)); c.writeObject("objField", new int[]{1});