Source:
void consumeOneError() throws Exception { MentionsData value = new MentionsData() .setDocumentReference("xwiki:XWiki.Doc") .setAuthorReference("xwiki:XWiki.Author") .setWikiId("xwiki") .setVersion("1.0"); when(this.blockingQueue.poll()).thenReturn(value); this.executor.startThreads(); verify(this.threadPoolProvider, times(NB_THREADS)).initializeThread(any(Runnable.class)); doThrow(new RuntimeException("...")).when(this.dataConsumer).consume(value); IntStream.range(0, 11).forEach(i -> this.executor.getConsumers().get(0).consume()); assertEquals(23, this.logCapture.size()); IntStream.of(0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20) .forEach(i -> assertEquals(Level.DEBUG, this.logCapture.getLogEvent(i).getLevel())); IntStream.of(1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21) .forEach(i -> assertEquals(WARN, this.logCapture.getLogEvent(i).getLevel())); assertEquals(ERROR, this.logCapture.getLogEvent(22).getLevel()); IntStream.of(0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20) .forEach( i -> assertEquals("[xwiki:XWiki.Doc] - [1.0] consumed. Queue size [0]", this.logCapture.getMessage(i))); IntStream.of(1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21) .forEach(i -> assertEquals("Error during mention analysis of task " + "[documentReference = [xwiki:XWiki.Doc], version = [1.0], authorReference = [xwiki:XWiki.Author], wikiId = [xwiki]]. " + "Cause [RuntimeException: ...].", this.logCapture.getMessage(i))); assertEquals("[documentReference = [xwiki:XWiki.Doc], version = [1.0], authorReference = [xwiki:XWiki.Author], wikiId = [xwiki]] abandoned because it has failed to many times.", this.logCapture.getMessage(22)); }

Target:
void consumeOneError() throws Exception { MentionsData value = new MentionsData() .setDocumentReference("xwiki:XWiki.Doc") .setAuthorReference("xwiki:XWiki.Author") .setWikiId("xwiki") .setVersion("1.0"); when(this.blockingQueue.poll()).thenReturn(value); this.executor.startThreads(); verify(this.threadPoolProvider, times(NB_THREADS)).initializeThread(any(Runnable.class)); doThrow(new RuntimeException("...")).when(this.dataConsumer).consume(value); IntStream.range(0, 11).forEach(i -> this.executor.getConsumers().get(0).consume()); assertEquals(23, this.logCapture.size()); IntStream.of(0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20) .forEach(i -> assertEquals(Level.DEBUG, this.logCapture.getLogEvent(i).getLevel())); IntStream.of(1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21) .forEach(i -> assertEquals(WARN, this.logCapture.getLogEvent(i).getLevel())); assertEquals(ERROR, this.logCapture.getLogEvent(22).getLevel()); IntStream.of(0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20) .forEach( i -> assertEquals("[xwiki:XWiki.Doc] - [1.0] consumed. Queue size [0]", this.logCapture.getMessage(i))); IntStream.of(1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21) .forEach(i -> assertEquals( "Error during mention analysis of task " + "[documentReference = [xwiki:XWiki.Doc], version = [1.0], " + "authorReference = [xwiki:XWiki.Author], wikiId = [xwiki]]. " + "Cause [RuntimeException: ...].", this.logCapture.getMessage(i))); assertEquals( "[documentReference = [xwiki:XWiki.Doc], version = [1.0], authorReference = [xwiki:XWiki.Author], " + "wikiId = [xwiki]] abandoned because it has failed to many times.", this.logCapture.getMessage(22)); }