QuotaChecker { void checkServiceIdentityPublicKeyQuota(ObjectStoreConnection con, String domainName, String serviceName, String caller) { if (!quotaCheckEnabled) { return; } final Quota quota = getDomainQuota(con, domainName); int objectCount = con.countPublicKeys(domainName, serviceName) + 1; if (quota.getPublicKey() < objectCount) { throw ZMSUtils.quotaLimitError("service public key quota exceeded - limit: " + quota.getPublicKey() + " actual: " + objectCount, caller); } } QuotaChecker(); Quota getDomainQuota(ObjectStoreConnection con, String domainName);  }
@Test public void testCheckServicePublicKeyQuota() { QuotaChecker quotaCheck = new QuotaChecker(); Quota mockQuota = new Quota().setName("athenz") .setService(2).setServiceHost(2).setPublicKey(2); ObjectStoreConnection con = Mockito.mock(ObjectStoreConnection.class); Mockito.when(con.getQuota("athenz")).thenReturn(mockQuota); Mockito.when(con.countPublicKeys("athenz", "storage")).thenReturn(1); quotaCheck.checkServiceIdentityPublicKeyQuota(con, "athenz", "storage", "caller"); }