StoreQuotaManager implements QuotaManager { @Override public Quota<QuotaCountLimit, QuotaCountUsage> getMessageQuota(QuotaRoot quotaRoot) throws MailboxException { Map<Scope, QuotaCountLimit> maxMessageDetails = maxQuotaManager.listMaxMessagesDetails(quotaRoot); return Quota.<QuotaCountLimit, QuotaCountUsage>builder() .used(Mono.from(currentQuotaManager.getCurrentMessageCount(quotaRoot)).block()) .computedLimit(maxQuotaManager.getMaxMessage(maxMessageDetails).orElse(QuotaCountLimit.unlimited())) .limitsByScope(maxMessageDetails) .build(); } @Inject  StoreQuotaManager(CurrentQuotaManager currentQuotaManager, MaxQuotaManager maxQuotaManager); @Override Quota<QuotaCountLimit, QuotaCountUsage> getMessageQuota(QuotaRoot quotaRoot); @Override Quota<QuotaSizeLimit, QuotaSizeUsage> getStorageQuota(QuotaRoot quotaRoot);  }
@SuppressWarnings("unchecked") @Test void getMessageQuotaShouldWorkWithNumericValues() throws Exception { when(mockedMaxQuotaManager.getMaxMessage(any(Map.class))).thenReturn(Optional.of(QuotaCountLimit.count(360L))); when(mockedCurrentQuotaManager.getCurrentMessageCount(quotaRoot)).thenAnswer(any -> Mono.fromCallable(() -> QuotaCountUsage.count(36L))); assertThat(testee.getMessageQuota(quotaRoot)).isEqualTo( Quota.<QuotaCountLimit, QuotaCountUsage>builder().used(QuotaCountUsage.count(36)).computedLimit(QuotaCountLimit.count(360)).build()); }
@SuppressWarnings("unchecked") @Test void getMessageQuotaShouldCalculateCurrentQuotaWhenUnlimited() throws Exception { when(mockedMaxQuotaManager.getMaxMessage(any(Map.class))).thenReturn(Optional.of(QuotaCountLimit.unlimited())); when(mockedCurrentQuotaManager.getCurrentMessageCount(quotaRoot)).thenAnswer(any -> Mono.fromCallable(() -> QuotaCountUsage.count(36L))); assertThat(testee.getMessageQuota(quotaRoot)).isEqualTo( Quota.<QuotaCountLimit, QuotaCountUsage>builder().used(QuotaCountUsage.count(36)).computedLimit(QuotaCountLimit.unlimited()).build()); }