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