@Override public void decrease(QuotaRoot quotaRoot, long count, long size) throws MailboxException { checkArguments(count, size); doIncrease(quotaRoot, -count, -size); }
@Override public MaxQuotaManager createMaxQuotaManager() { return new InMemoryPerUserMaxQuotaManager(); }
@Before public void setUp() throws Exception { mockedCurrentQuotaCalculator = mock(CurrentQuotaCalculator.class); MailboxManager mockedMailboxManager = mock(MailboxManager.class); testee = new InMemoryCurrentQuotaManager(mockedCurrentQuotaCalculator, mockedMailboxManager); }
@Test(expected = IllegalArgumentException.class) public void decreaseShouldThrowOnNegativeSize() throws Exception { testee.decrease(QUOTA_ROOT, 5, -1); }
@Test(expected = IllegalArgumentException.class) public void increaseShouldThrowOnNegativeSize() throws Exception { testee.increase(QUOTA_ROOT, 5, -1); }
@Override public QuotaSize getCurrentStorage(QuotaRoot quotaRoot) throws MailboxException { try { return QuotaSize.size(quotaCache.get(quotaRoot).getSize().get()); } catch (ExecutionException e) { throw new MailboxException("Exception caught", e); } }
@Override public QuotaCount getCurrentMessageCount(QuotaRoot quotaRoot) throws MailboxException { try { return QuotaCount.count(quotaCache.get(quotaRoot).getCount().get()); } catch (ExecutionException e) { throw new MailboxException("Exception caught", e); } }
@Override public Entry load(QuotaRoot quotaRoot) throws Exception { return new Entry(quotaCalculator.recalculateCurrentQuotas(quotaRoot, mailboxManager.createSystemSession(quotaRoot.getValue()))); } });
@Test public void matchShouldReturnEmptyOnMessageLimit() throws Exception { maxQuotaManager.setGlobalMaxMessage(QuotaCount.count(1)); FakeMail fakeMail = FakeMail.builder() .recipient(MailAddressFixture.ANY_AT_JAMES) .build(); Collection<MailAddress> result = testee.match(fakeMail); assertThat(result).isEmpty(); }
@Test public void matchShouldReturnEmptyAtSizeQuotaLimit() throws Exception { maxQuotaManager.setGlobalMaxStorage(QuotaSize.size(1000)); FakeMail fakeMail = FakeMail.builder() .recipient(MailAddressFixture.ANY_AT_JAMES) .size(1000) .build(); Collection<MailAddress> result = testee.match(fakeMail); assertThat(result).isEmpty(); }
@Override public void increase(QuotaRoot quotaRoot, long count, long size) throws MailboxException { checkArguments(count, size); doIncrease(quotaRoot, count, size); }
@Override protected MaxQuotaManager provideMaxQuotaManager() { return new InMemoryPerUserMaxQuotaManager(); }
@Override public InMemoryCurrentQuotaManager createCurrentQuotaManager(StoreMailboxManager mailboxManager) { if (currentQuotaManager == null) { currentQuotaManager = new InMemoryCurrentQuotaManager( new CurrentQuotaCalculator(mailboxManager.getMapperFactory(), createQuotaRootResolver(mailboxManager)), mailboxManager); } return currentQuotaManager; }
@Test(expected = IllegalArgumentException.class) public void decreaseShouldThrowOnNegativeCount() throws Exception { testee.decrease(QUOTA_ROOT, -1, 5); }
@Test(expected = IllegalArgumentException.class) public void increaseShouldThrowOnNegativeCount() throws Exception { testee.increase(QUOTA_ROOT, -1, 5); }
@Test(expected = IllegalArgumentException.class) public void decreaseShouldThrowOnZeroSize() throws Exception { testee.decrease(QUOTA_ROOT, 5, 0); }
@Test(expected = IllegalArgumentException.class) public void increaseShouldThrowOnZeroCount() throws Exception { testee.increase(QUOTA_ROOT, 0, 5); }
@Test(expected = IllegalArgumentException.class) public void decreaseShouldThrowOnZeroCount() throws Exception { testee.decrease(QUOTA_ROOT, 0, 5); }
@Test(expected = IllegalArgumentException.class) public void increaseShouldThrowOnZeroSize() throws Exception { testee.increase(QUOTA_ROOT, 5, 0); }