EntryEventSerialization { public void serializeNewValueIfNeeded(final InternalRegion region, final InternalEntryEvent event) { if (enabled) { doWork(region, event); } }  void serializeNewValueIfNeeded(final InternalRegion region,
      final InternalEntryEvent event);  }
@Test public void serializeNewValueIfNeeded_bothNull() { assertThatThrownBy(() -> instance.serializeNewValueIfNeeded(null, null)) .isInstanceOf(NullPointerException.class); }
@Test public void serializeNewValueIfNeeded_regionNull() { assertThatThrownBy(() -> instance.serializeNewValueIfNeeded(null, event)) .isInstanceOf(NullPointerException.class); }
@Test public void serializeNewValueIfNeeded_eventNull() { assertThatThrownBy(() -> instance.serializeNewValueIfNeeded(region, null)) .isInstanceOf(NullPointerException.class); }
@Test public void serializeNewValueIfNeeded_bothMocks() { assertThatCode(() -> instance.serializeNewValueIfNeeded(region, event)) .doesNotThrowAnyException(); }
@Test public void localRegionDoesNothing() { when(region.getScope()).thenReturn(Scope.LOCAL); instance.serializeNewValueIfNeeded(region, event); verify(event, times(0)).setCachedSerializedNewValue(any()); }
@Test public void distributedAckRegionSetsCachedSerializedNewValue() { instance.serializeNewValueIfNeeded(region, event); ArgumentCaptor<byte[]> captor = ArgumentCaptor.forClass(byte[].class); verify(event, times(1)).setCachedSerializedNewValue(captor.capture()); assertThat(captor.getValue().length).isGreaterThan(0); }
@Test public void distributedNoAckRegionSetsCachedSerializedNewValue() { when(region.getScope()).thenReturn(Scope.DISTRIBUTED_NO_ACK); instance.serializeNewValueIfNeeded(region, event); ArgumentCaptor<byte[]> captor = ArgumentCaptor.forClass(byte[].class); verify(event, times(1)).setCachedSerializedNewValue(captor.capture()); assertThat(captor.getValue().length).isGreaterThan(0); }
@Test public void globalRegionSetsCachedSerializedNewValue() { when(region.getScope()).thenReturn(Scope.GLOBAL); instance.serializeNewValueIfNeeded(region, event); ArgumentCaptor<byte[]> captor = ArgumentCaptor.forClass(byte[].class); verify(event, times(1)).setCachedSerializedNewValue(captor.capture()); assertThat(captor.getValue().length).isGreaterThan(0); }
@Test public void hasCachedSerializedNewValueDoesNothing() { when(event.getCachedSerializedNewValue()).thenReturn(new byte[0]); instance.serializeNewValueIfNeeded(region, event); verify(event, times(0)).setCachedSerializedNewValue(any()); }
@Test public void newValueIsByteArrayDoesNothing() { when(event.basicGetNewValue()).thenReturn(new byte[0]); instance.serializeNewValueIfNeeded(region, event); verify(event, times(0)).setCachedSerializedNewValue(any()); }
@Test public void newValueIsCachedDeserializableUsesItsSerializedValue() { CachedDeserializable newValue = mock(CachedDeserializable.class); when(event.basicGetNewValue()).thenReturn(newValue); byte[] bytes = new byte[] {0, 3, 4}; when(newValue.getSerializedValue()).thenReturn(bytes); instance.serializeNewValueIfNeeded(region, event); ArgumentCaptor<byte[]> captor = ArgumentCaptor.forClass(byte[].class); verify(event, times(1)).setCachedSerializedNewValue(captor.capture()); assertThat(captor.getValue()).isEqualTo(bytes); }
@Test public void newValueIsSerializableUsesItsSerializedValue() { String newValue = "newValue"; when(event.basicGetNewValue()).thenReturn(newValue); instance.serializeNewValueIfNeeded(region, event); ArgumentCaptor<byte[]> captor = ArgumentCaptor.forClass(byte[].class); verify(event, times(1)).setCachedSerializedNewValue(captor.capture()); assertThat(captor.getValue()).isEqualTo(EntryEventImpl.serialize(newValue)); }
@Test public void newValueIsNotSerializableThrows() { Object newValue = new Object(); when(event.basicGetNewValue()).thenReturn(newValue); Throwable thrown = catchThrowable(() -> instance.serializeNewValueIfNeeded(region, event)); assertThat(thrown).isInstanceOf(SerializationException.class); assertThat(thrown.getCause()).isInstanceOf(NotSerializableException.class); }