ValueComparisonHelper { public static boolean checkEquals(@Unretained Object v1, @Unretained Object v2, boolean isCompressedOffHeap, InternalCache cache) { if (v1 instanceof PdxInstance) { return checkPdxEquals((PdxInstance) v1, v2, cache); } else if (v2 instanceof PdxInstance) { return checkPdxEquals((PdxInstance) v2, v1, cache); } else if (v1 instanceof StoredObject) { return checkOffHeapEquals((StoredObject) v1, v2, cache); } else if (v2 instanceof StoredObject) { return checkOffHeapEquals((StoredObject) v2, v1, cache); } else if (v1 instanceof CachedDeserializable) { return checkCDEquals((CachedDeserializable) v1, v2, isCompressedOffHeap, cache); } else if (v2 instanceof CachedDeserializable) { return checkCDEquals((CachedDeserializable) v2, v1, isCompressedOffHeap, cache); } else { return basicEquals(v1, v2); } }  static boolean checkEquals(@Unretained Object v1, @Unretained Object v2,
      boolean isCompressedOffHeap, InternalCache cache);  }
@Test public void checkEqualsReturnsFalseWhenComparingNotSerializedCacheDeserializableWithPdxInstance() { PdxInstance pdxInstance1 = mock(PdxInstance.class); CachedDeserializable object = mock(CachedDeserializable.class); when(object.isSerialized()).thenReturn(false); assertThat( ValueComparisonHelper.checkEquals(object, pdxInstance1, false, mock(InternalCache.class))) .isFalse(); }
@Test public void checkEqualsReturnsFalseWhenComparingPdxInstanceWithNonPdxCacheDeserializable() { int[] value = {0, 1, 2, 3}; Object object = new VMCachedDeserializable(EntryEventImpl.serialize(value)); PdxInstance pdxInstance1 = mock(PdxInstance.class); assertThat( ValueComparisonHelper.checkEquals(pdxInstance1, object, false, mock(InternalCache.class))) .isFalse(); }
@Test public void checkEqualsReturnsTrueWhenComparingPdxInstanceWithItsCacheDeserializable() { PdxInstance pdxInstance1 = mock(PdxInstance.class); Object object = new VMCachedDeserializable(pdxInstance1, 1); assertThat( ValueComparisonHelper.checkEquals(pdxInstance1, object, false, mock(InternalCache.class))) .isTrue(); }
@Test public void checkEqualsReturnsFalseWhenComparingTwoNonEqualStoredObject() { StoredObject object1 = mock(StoredObject.class); StoredObject object2 = mock(StoredObject.class); when(object1.checkDataEquals(object2)).thenReturn(false); assertThat( ValueComparisonHelper.checkEquals(object1, object2, false, mock(InternalCache.class))) .isFalse(); }
@Test public void checkEqualsReturnsTrueWhenComparingTwoEqualStoredObject() { StoredObject object1 = mock(StoredObject.class); StoredObject object2 = mock(StoredObject.class); when(object1.checkDataEquals(object2)).thenReturn(true); assertThat( ValueComparisonHelper.checkEquals(object1, object2, false, mock(InternalCache.class))) .isTrue(); }
@Test public void checkEqualsReturnsFalseWhenComparingStoredObjectWithByteArrayAsCacheDeserializable() { StoredObject storedObject = mock(StoredObject.class); when(storedObject.isSerialized()).thenReturn(false); CachedDeserializable cachedDeserializable = mock(CachedDeserializable.class); when(cachedDeserializable.isSerialized()).thenReturn(true); assertThat( ValueComparisonHelper.checkEquals(storedObject, cachedDeserializable, false, mock(InternalCache.class))) .isFalse(); }
@Test public void checkEqualsReturnsFalseWhenComparingNonSerializedStoredObjectWithCacheDeserializable() { StoredObject storedObject = mock(StoredObject.class); when(storedObject.isSerialized()).thenReturn(false); CachedDeserializable cachedDeserializable = mock(CachedDeserializable.class); when(cachedDeserializable.isSerialized()).thenReturn(true); assertThat( ValueComparisonHelper.checkEquals(storedObject, cachedDeserializable, false, mock(InternalCache.class))) .isFalse(); }
@Test public void checkEqualsCanCompareStoredObjectWithCacheDeserializable() { StoredObject storedObject = mock(StoredObject.class); when(storedObject.isSerialized()).thenReturn(true); CachedDeserializable cachedDeserializable = mock(CachedDeserializable.class); byte[] serializedObj = new byte[1]; when(cachedDeserializable.getSerializedValue()).thenReturn(serializedObj); ValueComparisonHelper.checkEquals(storedObject, cachedDeserializable, false, mock(InternalCache.class)); verify(storedObject).checkDataEquals(serializedObj); }
@Test public void checkEqualsReturnsFalseWhenComparingSerializedStoredObjectWithByteArray() { StoredObject storedObject = mock(StoredObject.class); when(storedObject.isSerialized()).thenReturn(true); byte[] object = new byte[1]; assertThat( ValueComparisonHelper.checkEquals(storedObject, object, false, mock(InternalCache.class))) .isFalse(); }
@Test public void checkEqualsCanCompareNonSerializedStoredObjectWithByteArray() { StoredObject storedObject = mock(StoredObject.class); when(storedObject.isSerialized()).thenReturn(false); byte[] object = new byte[1]; ValueComparisonHelper.checkEquals(storedObject, object, false, mock(InternalCache.class)); verify(storedObject).checkDataEquals(object); }
@Test public void checkEqualsReturnsFalseWhenComparingNonSerializedStoredObjectWithAnObject() { StoredObject storedObject = mock(StoredObject.class); when(storedObject.isSerialized()).thenReturn(false); Object object = new Object(); assertThat( ValueComparisonHelper.checkEquals(storedObject, object, false, mock(InternalCache.class))) .isFalse(); verify(storedObject, never()).checkDataEquals(any(byte[].class)); }
@Test public void checkEqualsReturnsFalseWhenComparingSerializedStoredObjectWithANullObject() { StoredObject storedObject = mock(StoredObject.class); when(storedObject.isSerialized()).thenReturn(true); assertThat( ValueComparisonHelper.checkEquals(storedObject, null, false, mock(InternalCache.class))) .isFalse(); verify(storedObject, never()).checkDataEquals(any(byte[].class)); }
@Test public void checkEqualsReturnsFalseWhenComparingSerializedStoredObjectWithNotAvailableToken() { StoredObject storedObject = mock(StoredObject.class); when(storedObject.isSerialized()).thenReturn(true); assertThat( ValueComparisonHelper.checkEquals(storedObject, Token.NOT_AVAILABLE, false, mock(InternalCache.class))) .isFalse(); verify(storedObject, never()).checkDataEquals(any(byte[].class)); }
@Test public void checkEqualsReturnsFalseWhenComparingSerializedStoredObjectWithInvalidToken() { StoredObject storedObject = mock(StoredObject.class); when(storedObject.isSerialized()).thenReturn(true); assertThat( ValueComparisonHelper.checkEquals(storedObject, Token.INVALID, false, mock(InternalCache.class))) .isFalse(); assertThat( ValueComparisonHelper.checkEquals(storedObject, Token.LOCAL_INVALID, false, mock(InternalCache.class))) .isFalse(); verify(storedObject, never()).checkDataEquals(any(byte[].class)); }
@Test public void checkEqualsReturnsFalseWhenComparingSerializedStoredObjectWithRemovedToken() { StoredObject storedObject = mock(StoredObject.class); when(storedObject.isSerialized()).thenReturn(true); assertThat( ValueComparisonHelper.checkEquals(storedObject, Token.DESTROYED, false, mock(InternalCache.class))) .isFalse(); assertThat( ValueComparisonHelper.checkEquals(storedObject, Token.REMOVED_PHASE1, false, mock(InternalCache.class))) .isFalse(); assertThat( ValueComparisonHelper.checkEquals(storedObject, Token.REMOVED_PHASE2, false, mock(InternalCache.class))) .isFalse(); assertThat( ValueComparisonHelper.checkEquals(storedObject, Token.TOMBSTONE, false, mock(InternalCache.class))) .isFalse(); verify(storedObject, never()).checkDataEquals(any(byte[].class)); }
@Test public void checkEqualsCanCompareSerializedStoredObjectWithAnObject() { StoredObject storedObject = mock(StoredObject.class); when(storedObject.isSerialized()).thenReturn(true); Object object = mock(Serializable.class); ValueComparisonHelper.checkEquals(object, storedObject, false, mock(InternalCache.class)); verify(storedObject).checkDataEquals(any(byte[].class)); }
@Test public void checkEqualsReturnsTrueWhenComparingTwoEqualNotSerializedCacheDeserializable() { CachedDeserializable cachedDeserializable = mock(CachedDeserializable.class); when(cachedDeserializable.isSerialized()).thenReturn(false); CachedDeserializable object = mock(CachedDeserializable.class); when(object.isSerialized()).thenReturn(false); when(cachedDeserializable.getDeserializedForReading()).thenReturn(BYTE_ARRAY); when(object.getDeserializedForReading()).thenReturn(STRING.getBytes()); assertThat(ValueComparisonHelper.checkEquals(cachedDeserializable, object, false, mock(InternalCache.class))).isTrue(); }
@Test public void checkEqualsReturnsTrueWhenComparingNotSerializedDeserializableWithAByteArray() { CachedDeserializable cachedDeserializable = mock(CachedDeserializable.class); when(cachedDeserializable.isSerialized()).thenReturn(false); byte[] object = STRING.getBytes(); when(cachedDeserializable.getDeserializedForReading()).thenReturn(BYTE_ARRAY); assertThat(ValueComparisonHelper.checkEquals(object, cachedDeserializable, false, mock(InternalCache.class))).isTrue(); }
@Test public void checkEqualsReturnsFalseWhenComparingNotSerializedCacheDeserializableWithAnObject() { CachedDeserializable cachedDeserializable = mock(CachedDeserializable.class); when(cachedDeserializable.isSerialized()).thenReturn(false); Object object = new Object(); assertThat(ValueComparisonHelper.checkEquals(object, cachedDeserializable, false, mock(InternalCache.class))).isFalse(); }
@Test public void checkEqualsCanCompareNotSerializedCacheDeserializableWithSerializedOne() { CachedDeserializable cachedDeserializable = mock(CachedDeserializable.class); when(cachedDeserializable.isSerialized()).thenReturn(false); CachedDeserializable object = mock(CachedDeserializable.class); when(object.isSerialized()).thenReturn(true); assertThat(ValueComparisonHelper.checkEquals(cachedDeserializable, object, false, mock(InternalCache.class))).isFalse(); }
@Test public void checkEqualsCanCompareCacheDeserializableIfIsCompressedOffheap() { CachedDeserializable cachedDeserializable = mock(CachedDeserializable.class); when(cachedDeserializable.isSerialized()).thenReturn(true); when(cachedDeserializable.getValue()).thenReturn(BYTE_ARRAY); CachedDeserializable object = mock(CachedDeserializable.class); when(object.getSerializedValue()).thenReturn(STRING.getBytes()); assertThat(ValueComparisonHelper.checkEquals(cachedDeserializable, object, true, mock(InternalCache.class))).isTrue(); }
@Test public void checkEqualsCanCompareCacheDeserializableWithAnObjectIfIsCompressedOffheap() { CachedDeserializable cachedDeserializable = mock(CachedDeserializable.class); when(cachedDeserializable.isSerialized()).thenReturn(true); when(cachedDeserializable.getValue()).thenReturn(EntryEventImpl.serialize(STRING)); assertThat(ValueComparisonHelper.checkEquals(cachedDeserializable, STRING, true, mock(InternalCache.class))).isTrue(); }
@Test public void checkEqualsCanCompareCacheDeserializable() { CachedDeserializable cachedDeserializable = mock(CachedDeserializable.class); when(cachedDeserializable.isSerialized()).thenReturn(true); when(cachedDeserializable.getValue()).thenReturn(BYTE_ARRAY); when(cachedDeserializable.getDeserializedForReading()).thenReturn(STRING); CachedDeserializable object = mock(CachedDeserializable.class); when(object.getDeserializedForReading()).thenReturn(STRING); assertThat(ValueComparisonHelper.checkEquals(cachedDeserializable, object, false, mock(InternalCache.class))).isTrue(); verify(cachedDeserializable).getDeserializedForReading(); verify(object).getDeserializedForReading(); }
@Test public void checkEqualsReturnsFalseWhenComparingCacheDeserializableWithANullObject() { CachedDeserializable cachedDeserializable = mock(CachedDeserializable.class); when(cachedDeserializable.isSerialized()).thenReturn(true); when(cachedDeserializable.getValue()).thenReturn(BYTE_ARRAY); assertThat( ValueComparisonHelper.checkEquals(cachedDeserializable, null, false, mock(InternalCache.class))) .isFalse(); assertThat( ValueComparisonHelper.checkEquals(cachedDeserializable, null, true, mock(InternalCache.class))) .isFalse(); }
@Test public void checkEqualsReturnsFalseWhenComparingCacheDeserializableWithNotAvailableToken() { CachedDeserializable cachedDeserializable = mock(CachedDeserializable.class); when(cachedDeserializable.isSerialized()).thenReturn(true); when(cachedDeserializable.getValue()).thenReturn(BYTE_ARRAY); assertThat( ValueComparisonHelper.checkEquals(cachedDeserializable, Token.NOT_AVAILABLE, false, mock(InternalCache.class))) .isFalse(); assertThat( ValueComparisonHelper.checkEquals(cachedDeserializable, Token.NOT_AVAILABLE, true, mock(InternalCache.class))) .isFalse(); }
@Test public void checkEqualsReturnsFalseWhenComparingCacheDeserializableWithInvalidToken() { CachedDeserializable cachedDeserializable = mock(CachedDeserializable.class); when(cachedDeserializable.isSerialized()).thenReturn(true); when(cachedDeserializable.getValue()).thenReturn(BYTE_ARRAY); assertThat( ValueComparisonHelper.checkEquals(cachedDeserializable, Token.INVALID, false, mock(InternalCache.class))) .isFalse(); assertThat( ValueComparisonHelper.checkEquals(cachedDeserializable, Token.LOCAL_INVALID, false, mock(InternalCache.class))) .isFalse(); assertThat( ValueComparisonHelper.checkEquals(cachedDeserializable, Token.INVALID, true, mock(InternalCache.class))) .isFalse(); assertThat( ValueComparisonHelper.checkEquals(cachedDeserializable, Token.LOCAL_INVALID, true, mock(InternalCache.class))) .isFalse(); }
@Test public void checkEqualsReturnsFalseWhenComparingCacheDeserializableWithRemovedToken() { CachedDeserializable cachedDeserializable = mock(CachedDeserializable.class); when(cachedDeserializable.isSerialized()).thenReturn(true); when(cachedDeserializable.getValue()).thenReturn(BYTE_ARRAY); assertThat( ValueComparisonHelper.checkEquals(cachedDeserializable, Token.DESTROYED, false, mock(InternalCache.class))) .isFalse(); assertThat( ValueComparisonHelper.checkEquals(cachedDeserializable, Token.REMOVED_PHASE1, false, mock(InternalCache.class))) .isFalse(); assertThat( ValueComparisonHelper.checkEquals(cachedDeserializable, Token.REMOVED_PHASE2, false, mock(InternalCache.class))) .isFalse(); assertThat( ValueComparisonHelper.checkEquals(cachedDeserializable, Token.TOMBSTONE, false, mock(InternalCache.class))) .isFalse(); }
@Test public void checkEqualsCanCompareCacheDeserializableWithAnObject() { CachedDeserializable cachedDeserializable = mock(CachedDeserializable.class); when(cachedDeserializable.isSerialized()).thenReturn(true); when(cachedDeserializable.getValue()).thenReturn(BYTE_ARRAY); when(cachedDeserializable.getDeserializedForReading()).thenReturn(STRING); assertThat(ValueComparisonHelper.checkEquals(cachedDeserializable, STRING, false, mock(InternalCache.class))).isTrue(); }
@Test public void checkEqualsCanCompareObjectAsValueCacheDeserializableWithCacheDeserializable() { CachedDeserializable cachedDeserializable = mock(CachedDeserializable.class); when(cachedDeserializable.isSerialized()).thenReturn(true); when(cachedDeserializable.getValue()).thenReturn(STRING); CachedDeserializable object = mock(CachedDeserializable.class); when(object.getDeserializedForReading()).thenReturn(STRING); assertThat(ValueComparisonHelper.checkEquals(cachedDeserializable, object, false, mock(InternalCache.class))).isTrue(); }
@Test public void checkEqualsCanCompareObjectAsValueCacheDeserializableWithAnObject() { CachedDeserializable cachedDeserializable = mock(CachedDeserializable.class); when(cachedDeserializable.isSerialized()).thenReturn(true); when(cachedDeserializable.getValue()).thenReturn(STRING); assertThat(ValueComparisonHelper.checkEquals(cachedDeserializable, STRING, false, mock(InternalCache.class))).isTrue(); }
@Test public void checkEqualsCanCompareTwoObjects() { assertThat(ValueComparisonHelper.checkEquals(BOOLEAN_ARRAY, BOOLEAN_ARRAY2, false, mock(InternalCache.class))).isTrue(); }