@Override public Quota<QuotaCount> getMessageQuota(QuotaRoot quotaRoot) { return Quota.<QuotaCount>builder() .used(QuotaCount.count(0)) .computedLimit(QuotaCount.unlimited()) .build(); }
@Override public Quota<QuotaSize> getStorageQuota(QuotaRoot quotaRoot) { return Quota.<QuotaSize>builder() .used(QuotaSize.size(0)) .computedLimit(QuotaSize.unlimited()) .build(); } }
@Override public Quota<QuotaSize> getStorageQuota(QuotaRoot quotaRoot) throws MailboxException { return Quota.<QuotaSize>builder() .used(currentQuotaManager.getCurrentStorage(quotaRoot)) .computedLimit(maxQuotaManager.getMaxStorage(quotaRoot).orElse(QuotaSize.unlimited())) .limitsByScope(maxQuotaManager.listMaxStorageDetails(quotaRoot)) .build(); }
@Test public void buildShouldThrowOnMissingUsedValue() { assertThatThrownBy( () -> Quota.<QuotaCount>builder().computedLimit(QuotaCount.count(1)).build()) .isInstanceOf(IllegalStateException.class); }
@Test public void buildShouldThrowOnMissingComputedLimitValue() { assertThatThrownBy( () -> Quota.<QuotaCount>builder().used(QuotaCount.count(1)).build()) .isInstanceOf(IllegalStateException.class); }
@Test public void buildShouldCreateValidObjectGivenMandatoryFields() { Quota<QuotaCount> actual = Quota.<QuotaCount>builder() .used(QuotaCount.count(1)) .computedLimit(QuotaCount.count(2)) .build(); assertThat(actual).isNotNull(); }
@Test public void isOverQuotaShouldReturnTrueWhenQuotaIsExceeded() { Quota<QuotaCount> quota = Quota.<QuotaCount>builder().used(QuotaCount.count(360)).computedLimit(QuotaCount.count(36)).build(); assertThat(quota.isOverQuota()).isTrue(); }
@Test public void isOverQuotaWithAdditionalValueShouldReturnTrueWhenOverLimit() { Quota<QuotaCount> quota = Quota.<QuotaCount>builder().used(QuotaCount.count(36)).computedLimit(QuotaCount.count(36)).build(); assertThat(quota.isOverQuotaWithAdditionalValue(1)).isTrue(); }
@Test public void isOverQuotaWithAdditionalValueShouldReturnTrueWhenUnderLimit() { Quota<QuotaCount> quota = Quota.<QuotaCount>builder().used(QuotaCount.count(34)).computedLimit(QuotaCount.count(36)).build(); assertThat(quota.isOverQuotaWithAdditionalValue(1)).isFalse(); }
@Test public void isOverQuotaWithAdditionalValueShouldThrowOnNegativeValue() { Quota<QuotaCount> quota = Quota.<QuotaCount>builder().used(QuotaCount.count(25)).computedLimit(QuotaCount.count(36)).build(); assertThatThrownBy(() -> quota.isOverQuotaWithAdditionalValue(-1)).isInstanceOf(IllegalArgumentException.class); }
@Test public void isOverQuotaShouldReturnFalseWhenQuotaIsNotExceeded() { Quota<QuotaCount> quota = Quota.<QuotaCount>builder().used(QuotaCount.count(36)).computedLimit(QuotaCount.count(360)).build(); assertThat(quota.isOverQuota()).isFalse(); }
@Test public void isOverQuotaWithAdditionalValueShouldReturnFalseWhenAtLimit() { Quota<QuotaCount> quota = Quota.<QuotaCount>builder().used(QuotaCount.count(36)).computedLimit(QuotaCount.count(36)).build(); assertThat(quota.isOverQuotaWithAdditionalValue(0)).isFalse(); }
@Test public void isOverQuotaShouldReturnFalseWhenMaxValueIsUnlimited() { Quota<QuotaCount> quota = Quota.<QuotaCount>builder().used(QuotaCount.count(36)).computedLimit(QuotaCount.unlimited()).build(); assertThat(quota.isOverQuota()).isFalse(); }
@Test public void getRatioShouldReturnZeroWhenUnlimited() { assertThat( Quota.<QuotaSize>builder() .used(QuotaSize.size(15)) .computedLimit(QuotaSize.unlimited()) .build() .getRatio()) .isEqualTo(0); }
@Test public void getRatioShouldReturnUsedDividedByLimit() { assertThat( Quota.<QuotaSize>builder() .used(QuotaSize.size(15)) .computedLimit(QuotaSize.size(60)) .build() .getRatio()) .isEqualTo(0.25); }
private Quota<QuotaSize> limitedQuotaSizeByScopes(Quota.Scope scope) { return Quota.<QuotaSize>builder() .used(QuotaSize.size(12)) .computedLimit(QuotaSize.size(100)) .limitForScope(QuotaSize.size(100), scope) .build(); }
private Quota<QuotaCount> unLimitedQuotaCountByScopes(Quota.Scope scope) { return Quota.<QuotaCount>builder() .used(QuotaCount.count(12)) .computedLimit(QuotaCount.unlimited()) .limitForScope(QuotaCount.unlimited(), scope) .build(); }
private Quota<QuotaSize> unLimitedQuotaSizeByScopes(Quota.Scope scope) { return Quota.<QuotaSize>builder() .used(QuotaSize.size(12)) .computedLimit(QuotaSize.unlimited()) .limitForScope(QuotaSize.unlimited(), scope) .build(); }
private Quota<QuotaCount> limitedQuotaCountByScopes(Quota.Scope scope) { return Quota.<QuotaCount>builder() .used(QuotaCount.count(12)) .computedLimit(QuotaCount.count(100)) .limitForScope(QuotaCount.count(100), scope) .build(); }
@Test public void quotaStorageResponseShouldBeWellFormatted() throws Exception { QuotaResponse response = new QuotaResponse("STORAGE", "root", Quota.<QuotaSize>builder().used(QuotaSize.size(231 * 1024)).computedLimit(QuotaSize.size(1024 * 1024)).build()); ByteImapResponseWriter byteImapResponseWriter = new ByteImapResponseWriter(); ImapResponseComposer composer = new ImapResponseComposerImpl(byteImapResponseWriter, 1024); QuotaResponseEncoder encoder = new QuotaResponseEncoder(new EndImapEncoder()); encoder.encode(response, composer, null); String responseString = byteImapResponseWriter.getString(); assertThat(responseString).isEqualTo("* QUOTA root (STORAGE 231 1024)\r\n"); }