@Test public void given_copy_on_read_and_write_when_copyElementForRemovalIfNeeded_with_Element_then_returns_different() { Element element = new Element("key", "value"); Element serial = new Element("key", new byte[] { }); when(copyStrategy.copyForWrite(element)).thenReturn(new Element("key", new byte[] { })); CopyStrategyHandler copyStrategyHandler = new CopyStrategyHandler(true, true, copyStrategy); assertThat(copyStrategyHandler.copyElementForRemovalIfNeeded(element), is(serial)); verify(copyStrategy).copyForWrite(element); }
Element copyElementForRemovalIfNeeded(Element element) { if (element == null) { return null; } if (copyOnRead && copyOnWrite) { return copyStrategy.copyForWrite(element); } else { return element; } }
CopyStrategyHandler { Element copyElementForRemovalIfNeeded(Element element) { if (element == null) { return null; } if (copyOnRead && copyOnWrite) { return copyStrategy.copyForWrite(element); } else { return element; } } }
CopyStrategyHandler { Element copyElementForRemovalIfNeeded(Element element) { if (element == null) { return null; } if (copyOnRead && copyOnWrite) { return copyStrategy.copyForWrite(element); } else { return element; } } CopyStrategyHandler(boolean copyOnRead, boolean copyOnWrite, ReadWriteCopyStrategy<Element> copyStrategy); }
CopyStrategyHandler { Element copyElementForRemovalIfNeeded(Element element) { if (element == null) { return null; } if (copyOnRead && copyOnWrite) { return copyStrategy.copyForWrite(element); } else { return element; } } CopyStrategyHandler(boolean copyOnRead, boolean copyOnWrite, ReadWriteCopyStrategy<Element> copyStrategy); Element copyElementForReadIfNeeded(Element element); }
CopyStrategyHandler { Element copyElementForRemovalIfNeeded(Element element) { if (element == null) { return null; } if (copyOnRead && copyOnWrite) { return copyStrategy.copyForWrite(element); } else { return element; } } CopyStrategyHandler(boolean copyOnRead, boolean copyOnWrite, ReadWriteCopyStrategy<Element> copyStrategy); Element copyElementForReadIfNeeded(Element element);  }