From bf0bceb06a2c4f62dacbe867a0fab948bcaf0591 Mon Sep 17 00:00:00 2001 From: Marc Nuri Date: Tue, 3 Sep 2019 07:25:44 +0200 Subject: [PATCH] #28: Increment coverage of affected classes --- .../mnimapsync/index/StoreCrawlerText.java | 24 ++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/src/test/java/com/marcnuri/mnimapsync/index/StoreCrawlerText.java b/src/test/java/com/marcnuri/mnimapsync/index/StoreCrawlerText.java index 28078c9..07ea15d 100644 --- a/src/test/java/com/marcnuri/mnimapsync/index/StoreCrawlerText.java +++ b/src/test/java/com/marcnuri/mnimapsync/index/StoreCrawlerText.java @@ -24,6 +24,8 @@ import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.empty; import static org.hamcrest.Matchers.equalTo; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.fail; import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.doAnswer; @@ -68,7 +70,7 @@ void tearDown() { } @Test - void populateFromStore_storeHasFolders_ShouldPopulateIndex() throws Exception { + void populateFromStore_storeHasFolders_shouldPopulateIndex() throws Exception { // Given final Index index = new Index(); doReturn(1).when(defaultFolder).getMessageCount(); @@ -83,6 +85,26 @@ void populateFromStore_storeHasFolders_ShouldPopulateIndex() throws Exception { assertThat(index.hasCrawlException(), equalTo(false)); } + @Test + void populateFromStore_indexHasExceptionsAndStoreHasFolders_shouldThrowException() throws Exception { + // Given + final Index index = new Index(); + index.addCrawlException(new MessagingException("Indexing tasks went wrong at some point")); + doReturn(1).when(defaultFolder).getMessageCount(); + // When + final MessagingException result = assertThrows(MessagingException.class, () -> { + populateFromStore(index, imapStore, 1); + fail(); + }); + // Then + verify(defaultFolder, times(1)).expunge(); + assertThat(index.containsFolder("INBOX"), equalTo(true)); + assertThat(index.containsFolder("Folder 1"), equalTo(true)); + assertThat(index.containsFolder("Folder 2"), equalTo(true)); + assertThat(index.hasCrawlException(), equalTo(true)); + assertThat(result.getMessage(), equalTo("Indexing tasks went wrong at some point")); + } + private static IMAPFolder mockFolder(String name) throws MessagingException { final IMAPFolder mockFolder = Mockito.mock(IMAPFolder.class); doReturn(name).when(mockFolder).getFullName();