public EventConverter(MailboxConverter mailboxConverter) { this.eventFactory = new EventFactory(); this.mailboxConverter = mailboxConverter; }
@Inject public MailboxEventDispatcher(DelegatingMailboxListener delegatingMailboxListener) { this(delegatingMailboxListener, new EventFactory()); }
@VisibleForTesting public static MailboxEventDispatcher ofListener(MailboxListener mailboxListener) { return new MailboxEventDispatcher(mailboxListener, new EventFactory()); }
private void emitEvent(MailboxListener mailboxListener) { TreeMap<MessageUid, MessageMetaData> result = new TreeMap<>(); result.put(EMITTED_EVENT_UID, new SimpleMessageMetaData(EMITTED_EVENT_UID, MOD_SEQ, new Flags(), SIZE, new Date(), new DefaultMessageId())); mailboxListener.event(new EventFactory().added(mock(MailboxSession.class), result, mailbox, ImmutableMap.of())); } }
@Test void mailboxEventListenersShouldBeTriggeredIfRegistered() { SimpleMailbox simpleMailbox = new SimpleMailbox(MAILBOX_PATH_1, 42); simpleMailbox.setMailboxId(TestId.of(52)); TreeMap<MessageUid, MessageMetaData> uids = new TreeMap<>(); final MailboxListener.MailboxEvent event = new EventFactory().added(mailboxSession, uids, simpleMailbox, EMPTY_MESSAGE_CACHE); registeredDelegatingMailboxListener1.event(event); assertThat(eventCollectorMailbox1.getEvents()).hasSize(1); assertThat(eventCollectorMailbox2.getEvents()).hasSize(1); assertThat(eventCollectorMailbox3.getEvents()).isEmpty(); }
@Test void onceEventListenersShouldBeTriggeredOnceAcrossTheCluster() { SimpleMailbox simpleMailbox = new SimpleMailbox(MAILBOX_PATH_1, 42); simpleMailbox.setMailboxId(TestId.of(52)); TreeMap<MessageUid, MessageMetaData> uids = new TreeMap<>(); final MailboxListener.MailboxEvent event = new EventFactory().added(mailboxSession, uids, simpleMailbox, EMPTY_MESSAGE_CACHE); registeredDelegatingMailboxListener1.event(event); assertThat(eventCollectorOnce1.getEvents()).hasSize(1); assertThat(eventCollectorOnce2.getEvents()).isEmpty(); assertThat(eventCollectorOnce3.getEvents()).isEmpty(); }
@Before public void setUp() { session = new MockMailboxSession("test"); eventFactory = new EventFactory(); mailboxRegistration = new MailboxRegistration(INBOX); }
@BeforeEach void setUp() { eventFactory = new EventFactory(); session = new MockMailboxSession("test"); globalRegistration = new GlobalRegistration(); }
@Before public void setUp() { eventFactory = new EventFactory(); session = new MockMailboxSession("test"); globalRegistration = new GlobalRegistration(); }
@Test public void eventShouldCallSpamAssassinHamLearningWhenTheMessageIsAddedInInbox() { SimpleMailboxMessage message = createMessage(inboxId); EventFactory eventFactory = new EventFactory(); AddedImpl addedEvent = eventFactory.new AddedImpl( MAILBOX_SESSION, inbox, ImmutableSortedMap.of(MessageUid.of(45), new SimpleMessageMetaData(message)), ImmutableMap.of(MessageUid.of(45), message)); listener.event(addedEvent); verify(spamAssassin).learnHam(any(), any()); }
@Test public void eventShouldNotCallSpamAssassinHamLearningWhenTheMessageIsAddedInAMailboxOtherThanInbox() { SimpleMailboxMessage message = createMessage(mailboxId1); EventFactory eventFactory = new EventFactory(); AddedImpl addedEvent = eventFactory.new AddedImpl( MAILBOX_SESSION, mailbox1, ImmutableSortedMap.of(MessageUid.of(45), new SimpleMessageMetaData(message)), ImmutableMap.of(MessageUid.of(45), message)); listener.event(addedEvent); verifyNoMoreInteractions(spamAssassin); }