MailboxAnnotationListener implements MailboxListener.GroupMailboxListener { @Override public void event(Event event) { if (event instanceof MailboxDeletion) { MailboxSession mailboxSession = sessionProvider.createSystemSession(event.getUsername()); AnnotationMapper annotationMapper = mailboxSessionMapperFactory.getAnnotationMapper(mailboxSession); MailboxId mailboxId = ((MailboxDeletion) event).getMailboxId(); deleteRelatedAnnotations(mailboxId, annotationMapper); } } @Inject  MailboxAnnotationListener(MailboxSessionMapperFactory mailboxSessionMapperFactory, SessionProvider sessionProvider); @Override Group getDefaultGroup(); @Override void event(Event event); static final Group GROUP; }
@Test void eventShouldDoNothingIfDoNotHaveMailboxDeletionEvent() throws Exception { MailboxListener.MailboxEvent event = new MailboxListener.MailboxAdded(null, null, MAILBOX_PATH, MAILBOX_ID, Event.EventId.random()); listener.event(event); verifyNoMoreInteractions(mailboxSessionMapperFactory); verifyNoMoreInteractions(annotationMapper); }
@Test void eventShoudlDoNothingIfMailboxDoesNotHaveAnyAnnotation() throws Exception { when(annotationMapper.getAllAnnotations(any(MailboxId.class))).thenReturn(ImmutableList.<MailboxAnnotation>of()); listener.event(deleteEvent); verify(mailboxSessionMapperFactory).getAnnotationMapper(eq(mailboxSession)); verify(annotationMapper).getAllAnnotations(eq(mailboxId)); verifyNoMoreInteractions(mailboxSessionMapperFactory); verifyNoMoreInteractions(annotationMapper); }
@Test void eventShoudlDeleteAllMailboxAnnotation() throws Exception { when(annotationMapper.getAllAnnotations(eq(mailboxId))).thenReturn(ANNOTATIONS); listener.event(deleteEvent); verify(mailboxSessionMapperFactory).getAnnotationMapper(eq(mailboxSession)); verify(annotationMapper).getAllAnnotations(eq(mailboxId)); verify(annotationMapper).deleteAnnotation(eq(mailboxId), eq(PRIVATE_KEY)); verify(annotationMapper).deleteAnnotation(eq(mailboxId), eq(SHARED_KEY)); verifyNoMoreInteractions(mailboxSessionMapperFactory); verifyNoMoreInteractions(annotationMapper); }
@Test void eventShouldPropagateFailure() throws Exception { when(annotationMapper.getAllAnnotations((eq(mailboxId)))).thenReturn(ANNOTATIONS); doThrow(new RuntimeException()).when(annotationMapper).deleteAnnotation(eq(mailboxId), eq(PRIVATE_KEY)); assertThatThrownBy(() -> listener.event(deleteEvent)).isInstanceOf(RuntimeException.class); verify(mailboxSessionMapperFactory).getAnnotationMapper(eq(mailboxSession)); verify(annotationMapper).getAllAnnotations(eq(mailboxId)); verify(annotationMapper).deleteAnnotation(eq(mailboxId), eq(PRIVATE_KEY)); verifyNoMoreInteractions(mailboxSessionMapperFactory); verifyNoMoreInteractions(annotationMapper); }