### Question:
BaseFileBuffer implements IFileBuffer { @Override public final synchronized void addFileToBuffer(File file) { if (currentBuffer == null) { currentBuffer = new FileBufferHolder(); startBuffering(currentBuffer); } currentBuffer.addFile(file); } protected  BaseFileBuffer(IFileManager fileManager); @Override final synchronized void addFileToBuffer(File file);  }### Answer:
@Test public void testBufferFinishesSomewhen() throws IOException, InterruptedException { final AtomicInteger counter = new AtomicInteger(0); BaseFileBuffer buffer = new BaseFileBuffer(null) { @Override protected void processBuffer(IFileBufferHolder buffer) { counter.set(buffer.getFileBuffer().size()); } }; File directory = new File(FileUtils.getTempDirectory(), UUID.randomUUID().toString()); buffer.addFileToBuffer(directory); buffer.addFileToBuffer(createFileRandomContent(directory)); Thread.sleep((long) (IFileBuffer.BUFFER_WAIT_TIME_MS * 1.5)); Assert.assertEquals(2, counter.get()); }
@Test public void testBufferRunsInBatches() throws IOException, InterruptedException { final AtomicInteger counter = new AtomicInteger(0); BaseFileBuffer buffer = new BaseFileBuffer(null) { @Override protected void processBuffer(IFileBufferHolder buffer) { counter.addAndGet(buffer.getFileBuffer().size()); } }; File directory = new File(FileUtils.getTempDirectory(), UUID.randomUUID().toString()); buffer.addFileToBuffer(directory); buffer.addFileToBuffer(createFileRandomContent(directory)); Thread.sleep((long) (IFileBuffer.BUFFER_WAIT_TIME_MS * 1.4)); buffer.addFileToBuffer(createFileRandomContent(directory)); Assert.assertEquals(2, counter.get()); counter.set(0); Thread.sleep((long) (IFileBuffer.BUFFER_WAIT_TIME_MS * 1.4)); Assert.assertEquals(1, counter.get()); }