/** * Tells us if the quota is reached * * @return True if the user over uses the resource of this quota */ public boolean isOverQuota() { return isOverQuotaWithAdditionalValue(0); }
@Override public Collection<MailAddress> match(Mail mail) throws MessagingException { try { List<MailAddress> result = new ArrayList<>(); for (MailAddress mailAddress : mail.getRecipients()) { String userName = usersRepository.getUser(mailAddress); MailboxSession mailboxSession = mailboxManager.createSystemSession(userName); MailboxPath mailboxPath = MailboxPath.inbox(mailboxSession); QuotaRoot quotaRoot = quotaRootResolver.getQuotaRoot(mailboxPath); if (quotaManager.getMessageQuota(quotaRoot).isOverQuotaWithAdditionalValue(SINGLE_EMAIL) || quotaManager.getStorageQuota(quotaRoot).isOverQuotaWithAdditionalValue(mail.getMessageSize())) { result.add(mailAddress); } } return result; } catch (MailboxException e) { throw new MessagingException("Exception while checking quotas", e); } catch (UsersRepositoryException e) { throw new MessagingException("Exception while retrieving username", e); } } }
@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 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); }