ConcurrentFileLineConsumer implements LineConsumer { @Override public void close() throws IOException { if (isOpen) { lock.writeLock().lock(); try { isOpen = false; writer.close(); } finally { lock.writeLock().unlock(); } } } ConcurrentFileLineConsumer(File file); File getFile(); boolean isOpen(); @Override void writeLine(String line); @Override void close();  }
@Test public void shouldNotWriteIntoSubConsumersWhenLockForCloseIsLocked() throws Exception { WaitingAnswer<Void> waitingAnswer = new WaitingAnswer<>(); doAnswer(waitingAnswer).when(writer).close(); executor.execute(this::closeConsumer); waitingAnswer.waitAnswerCall(1, TimeUnit.SECONDS); writeIntoConsumer("Test line"); waitingAnswer.completeAnswer(); awaitFinalization(); verify(writer, never()).write(anyString()); }