private void checkAndChargeTest(boolean testWithChunkSize) throws Exception {
    List<Boolean> boolValues = Arrays.asList(true, false);
    for (RestMethod restMethod : RestMethod.values()) {
      RestRequest restRequest = createRestRequest(restMethod);
      PreProcessQuotaChargeCallback preProcessQuotaChargeCallback =
          new PreProcessQuotaChargeCallback(quotaManager, restRequest);
      long chunkSize = quotaConfig.quotaAccountingUnit;
      if (testWithChunkSize) {
        chunkSize = new Random().nextInt(10000);
      }
      Map<QuotaName, Double> costMap = getCostMap(chunkSize, restRequest);
      for (boolean shouldCheckQuotaExceedAllowed : boolValues) {
        for (boolean forceCharge : boolValues) {
          int callCount = 0;
          for (QuotaAction quotaAction : QuotaAction.values()) {
            when(quotaManager.chargeAndRecommend(eq(restRequest), eq(costMap), eq(shouldCheckQuotaExceedAllowed),
                eq(forceCharge))).thenReturn(quotaAction);
            QuotaAction expectedQuotaAction = isThrottling ? quotaAction : QuotaAction.ALLOW;
            if (testWithChunkSize) {
              Assert.assertEquals(expectedQuotaAction,
                  preProcessQuotaChargeCallback.checkAndCharge(shouldCheckQuotaExceedAllowed, forceCharge, chunkSize));
            } else {
              Assert.assertEquals(expectedQuotaAction,
                  preProcessQuotaChargeCallback.checkAndCharge(shouldCheckQuotaExceedAllowed, forceCharge));
            }
            callCount++;
            verify(quotaManager, times(callCount)).chargeAndRecommend(restRequest, costMap,
                shouldCheckQuotaExceedAllowed, forceCharge);
          }
        }
      }
    }
  }
Helper method to test {@link PreProcessQuotaChargeCallback#checkAndCharge} for all possible parameters.
@param testWithChunkSize {@code true} if checkAndCharge is called with chunkSize param. {@code false} otherwise.
@throws Exception In case of any error
ambry-quota/src/test/java/com/github/ambry/quota/PreProcessQuotaChargeCallbackTest.java