@Override public void decrease(QuotaRoot quotaRoot, long count, long size) throws MailboxException { checkArguments(count, size); doIncrease(quotaRoot, -count, -size); }
@Test public void getCurrentStorageShouldReRetrieveStoredQuotasWhenCalculateOnUnknownQuotaIsTrue() throws Exception { when(mockedCurrentQuotaCalculator.recalculateCurrentQuotas(QUOTA_ROOT, null)) .thenReturn(new CurrentQuotaCalculator.CurrentQuotas(18, 512)); testee.increase(QUOTA_ROOT, 10, 100); assertThat(testee.getCurrentMessageCount(QUOTA_ROOT)).isEqualTo(QuotaCount.count(28)); assertThat(testee.getCurrentStorage(QUOTA_ROOT)).isEqualTo(QuotaSize.size(612)); }
@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); }
@Test public void getCurrentStorageShouldReturnRecalculateSizeWhenEntryIsNotInitialized() throws Exception { when(mockedCurrentQuotaCalculator.recalculateCurrentQuotas(QUOTA_ROOT, null)) .thenReturn(new CurrentQuotaCalculator.CurrentQuotas(18, 512)); assertThat(testee.getCurrentStorage(QUOTA_ROOT)).isEqualTo(QuotaSize.size(512)); }
@Test public void getCurrentMessageCountShouldReturnRecalculateMessageCountWhenEntryIsNotInitialized() throws Exception { when(mockedCurrentQuotaCalculator.recalculateCurrentQuotas(QUOTA_ROOT, null)) .thenReturn(new CurrentQuotaCalculator.CurrentQuotas(18, 512)); assertThat(testee.getCurrentMessageCount(QUOTA_ROOT)).isEqualTo(QuotaCount.count(18)); }
@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); }
@Before public void setUp() throws Exception { mailboxManager = new InMemoryIntegrationResources().createMailboxManager(new SimpleGroupMembershipResolver()); quotaRootResolver = new DefaultUserQuotaRootResolver(mailboxManager.getMapperFactory()); maxQuotaManager = new InMemoryPerUserMaxQuotaManager(); CurrentQuotaCalculator quotaCalculator = new CurrentQuotaCalculator(mailboxManager.getMapperFactory(), quotaRootResolver); InMemoryCurrentQuotaManager currentQuotaManager = new InMemoryCurrentQuotaManager(quotaCalculator, mailboxManager); StoreQuotaManager quotaManager = new StoreQuotaManager(currentQuotaManager, maxQuotaManager); usersRepository = mock(UsersRepository.class); testee = new IsOverQuota(quotaRootResolver, quotaManager, mailboxManager, usersRepository); mailboxManager.setQuotaRootResolver(quotaRootResolver); mailboxManager.setQuotaManager(quotaManager); testee.init(FakeMatcherConfig.builder().matcherName("IsOverQuota").build()); when(usersRepository.getUser(MailAddressFixture.ANY_AT_JAMES)).thenReturn(MailAddressFixture.ANY_AT_JAMES.getLocalPart()); when(usersRepository.getUser(MailAddressFixture.OTHER_AT_JAMES)).thenReturn(MailAddressFixture.OTHER_AT_JAMES.getLocalPart()); }
@Override public void increase(QuotaRoot quotaRoot, long count, long size) throws MailboxException { checkArguments(count, size); doIncrease(quotaRoot, count, size); }
@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); }