private UpdatedRepresentation createUpdatedDocumentPartFromUpdatedFlags(Mailbox mailbox, UpdatedFlags updatedFlags) { try { return new UpdatedRepresentation( indexIdFor(mailbox, updatedFlags.getUid()), messageToElasticSearchJson.getUpdatedJsonMessagePart( updatedFlags.getNewFlags(), updatedFlags.getModSeq())); } catch (JsonProcessingException e) { throw new RuntimeException("Error while creating updatedDocumentParts", e); } }
@Test public void updateShouldWork() throws Exception { //Given Mailbox mailbox = mock(Mailbox.class); Flags flags = new Flags(); UpdatedFlags updatedFlags = UpdatedFlags.builder() .uid(MESSAGE_UID) .modSeq(MODSEQ) .oldFlags(flags) .newFlags(flags) .build(); when(mailbox.getMailboxId()) .thenReturn(MAILBOX_ID); when(messageToElasticSearchJson.getUpdatedJsonMessagePart(any(Flags.class), any(Long.class))) .thenReturn("json updated content"); //When testee.update(session, mailbox, Lists.newArrayList(updatedFlags)); //Then ImmutableList<UpdatedRepresentation> expectedUpdatedRepresentations = ImmutableList.of(new UpdatedRepresentation(ELASTIC_SEARCH_ID, "json updated content")); verify(elasticSearchIndexer).update(expectedUpdatedRepresentations); }
@Test public void updateShouldNotPropagateExceptionWhenExceptionOccurs() throws Exception { //Given Mailbox mailbox = mock(Mailbox.class); Flags flags = new Flags(); UpdatedFlags updatedFlags = UpdatedFlags.builder() .uid(MESSAGE_UID) .modSeq(MODSEQ) .oldFlags(flags) .newFlags(flags) .build(); when(mailbox.getMailboxId()) .thenReturn(MAILBOX_ID); ImmutableList<UpdatedRepresentation> expectedUpdatedRepresentations = ImmutableList.of(new UpdatedRepresentation(ELASTIC_SEARCH_ID, "json updated content")); when(elasticSearchIndexer.update(expectedUpdatedRepresentations)) .thenThrow(new ElasticsearchException("")); //When testee.update(session, mailbox, Lists.newArrayList(updatedFlags)); //Then //No exception }