private void trySizeAddition(long size) throws OverQuotaException { Quota<QuotaSize> afterAdditionQuotaSize = sizeQuota.addValueToQuota(QuotaSize.size(size)); if (afterAdditionQuotaSize.isOverQuota()) { throw new OverQuotaException( "You use too much space in " + quotaRoot.getValue(), afterAdditionQuotaSize.getLimit(), afterAdditionQuotaSize.getUsed()); } }
private void tryCountAddition(long count) throws OverQuotaException { Quota<QuotaCount> afterAdditionQuotaCount = messageQuota.addValueToQuota(QuotaCount.count(count)); if (afterAdditionQuotaCount.isOverQuota()) { throw new OverQuotaException( "You have too many messages in " + quotaRoot.getValue(), messageQuota.getLimit(), messageQuota.getUsed()); } }
@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 isOverQuotaShouldReturnFalseWhenMaxValueIsUnlimited() { Quota<QuotaCount> quota = Quota.<QuotaCount>builder().used(QuotaCount.count(36)).computedLimit(QuotaCount.unlimited()).build(); assertThat(quota.isOverQuota()).isFalse(); }
@Test public void isOverQuotaShouldReturnTrueWhenQuotaIsExceeded() { Quota<QuotaCount> quota = Quota.<QuotaCount>builder().used(QuotaCount.count(360)).computedLimit(QuotaCount.count(36)).build(); assertThat(quota.isOverQuota()).isTrue(); }