SetCustomFlagOnBigMessages implements MailboxListener.GroupMailboxListener { @Override public void event(Event event) { if (event instanceof MailboxListener.Added) { MailboxListener.Added addedEvent = (MailboxListener.Added) event; addedEvent.getUids().stream() .filter(messageUid -> isBig(addedEvent, messageUid)) .forEach(messageUid -> setBigMessageFlag(addedEvent, messageUid)); } } @Inject  SetCustomFlagOnBigMessages(MailboxManager mailboxManager); @Override void event(Event event); @Override Group getDefaultGroup();  }
@Test void shouldAddFlagWhenMessageSizeIsEqualToBigMessageSize() throws Exception { ComposedMessageId composedIdOfSmallMessage = inboxMessageManager.appendMessage( MessageManager.AppendCommand.builder() .build(smallMessage()), mailboxSession).getId(); MessageResult addedMessage = inboxMessageManager .getMessages(MessageRange.one(composedIdOfSmallMessage.getUid()), FetchGroup.MINIMAL, mailboxSession) .next(); MessageMetaData oneMBMetaData = new MessageMetaData(addedMessage.getUid(), addedMessage.getModSeq(), addedMessage.getFlags(), ONE_MB, addedMessage.getInternalDate(), addedMessage.getMessageId()); Event eventWithAFakeMessageSize = EventFactory.added() .eventId(RANDOM_EVENT_ID) .mailboxSession(mailboxSession) .mailboxId(inboxId) .mailboxPath(INBOX_PATH) .addMetaData(oneMBMetaData) .build(); testee.event(eventWithAFakeMessageSize); assertThat(getMessageFlags(composedIdOfSmallMessage.getUid())) .allSatisfy(flags -> assertThat(flags.contains(BIG_MESSAGE)).isTrue()); }