ConstantFlowRegulator implements ServiceWrapper { public <T> T invoke(Callable<T> c) throws Exception { if (canProceed()) { return c.call(); } else { throw mapException(new FlowRateExceededException()); } } ConstantFlowRegulator();  ConstantFlowRegulator(int requestsPerSecond);  ConstantFlowRegulator(int requestsPerSecond,
                                 ConstantFlowRegulatorExceptionMapper<? extends Exception> mapper); T invoke(Callable<T> c); void invoke(Runnable r); T invoke(Runnable r, T result); void setRequestPerSecondThreshold(int i); int getRequestPerSecondThreshold(); ConstantFlowRegulatorExceptionMapper<? extends Exception> getExceptionMapper(); void setExceptionMapper(ConstantFlowRegulatorExceptionMapper<? extends Exception> mapper);  }
@Test (expected=DomainException.class) public void testThrowsMappedExceptionWhenCanNotProceedViaConstructor() throws Exception { ConstantFlowRegulator impl = new ConstantFlowRegulator(1, new TestConstantFlowRegulatorExceptionMapper()); for (int i = 0; i < 5; i++) { impl.invoke(mockCallable); } }