DefaultUserQuotaRootResolver implements UserQuotaRootResolver { @Override public Flux<Mailbox> retrieveAssociatedMailboxes(QuotaRoot quotaRoot, MailboxSession mailboxSession) { try { List<String> parts = QUOTA_ROOT_DESERIALIZER.toParts(quotaRoot.getValue()); String namespace = parts.get(0); String user = parts.get(1); return factory.getMailboxMapper(mailboxSession) .findMailboxWithPathLike(MailboxQuery.builder() .namespace(namespace) .user(Username.of(user)) .matchesAllMailboxNames() .build() .asUserBound()); } catch (MailboxException e) { return Flux.error(e); } } @Inject  DefaultUserQuotaRootResolver(SessionProvider sessionProvider, MailboxSessionMapperFactory factory); @Override QuotaRoot forUser(Username username); @Override QuotaRoot getQuotaRoot(MailboxPath mailboxPath); @Override QuotaRoot getQuotaRoot(Mailbox mailbox); @Override QuotaRoot getQuotaRoot(MailboxId mailboxId); @Override Mono<QuotaRoot> getQuotaRootReactive(MailboxId mailboxId); @Override QuotaRoot fromString(String serializedQuotaRoot); @Override Flux<Mailbox> retrieveAssociatedMailboxes(QuotaRoot quotaRoot, MailboxSession mailboxSession); static final String SEPARATOR; }
@Test void retrieveAssociatedMailboxesShouldWork() throws Exception { MailboxMapper mockedMapper = mock(MailboxMapper.class); when(mockedFactory.getMailboxMapper(MAILBOX_SESSION)).thenReturn(mockedMapper); when(mockedMapper.findMailboxWithPathLike(any())).thenReturn(Flux.just(MAILBOX, MAILBOX_2)); assertThat(testee.retrieveAssociatedMailboxes(QUOTA_ROOT, MAILBOX_SESSION).collectList().block()).containsOnly(MAILBOX, MAILBOX_2); }
@Test void retrieveAssociatedMailboxesShouldThrowWhenQuotaRootContainsSeparator2Times() { assertThatThrownBy(() -> testee.retrieveAssociatedMailboxes( QuotaRoot.quotaRoot("#private&be&nwa", Optional.empty()), MAILBOX_SESSION) .collectList().block()) .hasCauseInstanceOf(MailboxException.class); }