### Question:
ItemSourceContentInputStream extends ContentInputStream { @Override public void close() { if (!closed.compareAndSet(false, true)) { buffer.release(); } } ItemSourceContentInputStream(ItemSource<SimpleInputBuffer> buffer); @Override void close();  }### Answer:
@Test public void closeReleasesBufferOnlyOnce() throws IOException { ItemSource itemSource = mock(ItemSource.class); when(itemSource.getSource()).thenReturn(mock(SimpleInputBuffer.class)); InputStream inputStream = new ItemSourceContentInputStream(itemSource); inputStream.close(); inputStream.close(); verify(itemSource, times(1)).release(); }