ObjectBuffer implements AutoCloseable { public void close() throws IOException { generator.close(); FilesHelper.deleteQuietly(tempFile.toFile()); closed = true; } ObjectBuffer(Class<T> bufferedClass); void appendRow(T entity); Stream<T> readAll(); void close();  }
@Test public void testCloseCleanUp() throws Exception { ObjectBuffer<ObjectToBuffer> buffer = new ObjectBuffer<>(ObjectToBuffer.class); Path tempFile = (Path) ReflectionTestUtils.getField(buffer, "tempFile"); assertTrue(Files.exists(tempFile)); buffer.close(); assertFalse(Files.exists(tempFile)); }