@Test public void testUrisToWriterListenerException() { final AtomicInteger failureBatchCount = new AtomicInteger(); StringWriter badWriter = new StringWriter() { public void write(String str) { throw new InternalError(errorMessage); } }; testListenerException( new UrisToWriterListener(badWriter) .onBatchFailure( (batch, throwable) -> failureBatchCount.incrementAndGet() ) ); // there should be one failure sent to the UrisToWriterListener // onBatchFailure listener since the writer is invalid assertEquals(1, failureBatchCount.get()); }