Skip to content

Commit

Permalink
#28: Increment coverage of affected classes
Browse files Browse the repository at this point in the history
  • Loading branch information
manusa committed Sep 3, 2019
1 parent 0e4660e commit bf0bceb
Showing 1 changed file with 23 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand All @@ -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();
Expand Down

0 comments on commit bf0bceb

Please sign in to comment.