QuotaChecker { void checkPolicyAssertionQuota(ObjectStoreConnection con, String domainName, String policyName, String caller) { if (!quotaCheckEnabled) { return; } final Quota quota = getDomainQuota(con, domainName); int objectCount = con.countAssertions(domainName, policyName) + 1; if (quota.getAssertion() < objectCount) { throw ZMSUtils.quotaLimitError("policy assertion quota exceeded - limit: " + quota.getAssertion() + " actual: " + objectCount, caller); } } QuotaChecker(); Quota getDomainQuota(ObjectStoreConnection con, String domainName);  }
@Test public void testCheckPolicyAssertionQuota() { QuotaChecker quotaCheck = new QuotaChecker(); Quota mockQuota = new Quota().setName("athenz") .setPolicy(2).setAssertion(2); ObjectStoreConnection con = Mockito.mock(ObjectStoreConnection.class); Mockito.when(con.getQuota("athenz")).thenReturn(mockQuota); Mockito.when(con.countAssertions("athenz", "readers")).thenReturn(1); quotaCheck.checkPolicyAssertionQuota(con, "athenz", "readers", "caller"); }