@Test public void given_copy_on_read_and_write_when_copyElementForReadIfNeeded_with_Element_then_returns_different() { Element element = new Element("key", "value"); Element serial = new Element("key", new byte[] {}); when(copyStrategy.copyForRead(serial)).thenReturn(new Element("key", "value")); CopyStrategyHandler copyStrategyHandler = new CopyStrategyHandler(true, true, copyStrategy); assertThat(copyStrategyHandler.copyElementForReadIfNeeded(serial), is(element)); verify(copyStrategy).copyForRead(serial); }
@Test public void given_no_copy_when_copyElementForReadIfNeeded_with_null_then_returns_null() { CopyStrategyHandler copyStrategyHandler = new CopyStrategyHandler(false, false, null); assertThat(copyStrategyHandler.copyElementForReadIfNeeded(null), nullValue()); }
@Test public void given_no_copy_when_copyElementForReadIfNeeded_with_Element_then_returns_same() { CopyStrategyHandler copyStrategyHandler = new CopyStrategyHandler(false, false, null); Element element = new Element("key", "value"); assertThat(copyStrategyHandler.copyElementForReadIfNeeded(element), sameInstance(element)); }
@Test public void given_copy_on_read_and_write_when_copyElementForReadIfNeeded_with_null_then_returns_null() { CopyStrategyHandler copyStrategyHandler = new CopyStrategyHandler(true, true, copyStrategy); assertThat(copyStrategyHandler.copyElementForReadIfNeeded(null), nullValue()); }