QuotaChecker { void checkEntityQuota(ObjectStoreConnection con, String domainName, Entity entity, String caller) { if (!quotaCheckEnabled) { return; } if (entity == null) { return; } final Quota quota = getDomainQuota(con, domainName); int objectCount = con.countEntities(domainName) + 1; if (quota.getEntity() < objectCount) { throw ZMSUtils.quotaLimitError("entity quota exceeded - limit: " + quota.getEntity() + " actual: " + objectCount, caller); } } QuotaChecker(); Quota getDomainQuota(ObjectStoreConnection con, String domainName);  }
@Test public void testCheckEntityQuotaNull() { QuotaChecker quotaCheck = new QuotaChecker(); quotaCheck.checkEntityQuota(null, "athenz", null, "caller"); }
@Test public void testCheckEntityQuota() { QuotaChecker quotaCheck = new QuotaChecker(); Quota mockQuota = new Quota().setName("athenz") .setEntity(2); ObjectStoreConnection con = Mockito.mock(ObjectStoreConnection.class); Mockito.when(con.getQuota("athenz")).thenReturn(mockQuota); Mockito.when(con.countEntities("athenz")).thenReturn(1); Entity entity = new Entity(); quotaCheck.checkEntityQuota(con, "athenz", entity, "caller"); }