@Test public void serviceBCalledAtLeastOnceAndAtMostThreeTimes() { new MockServiceBForOneToThreeInvocations(); new MockServiceBHelper(); ServiceA serviceA = new ServiceA(); serviceA.doSomethingElseUsingServiceB(2); String config = serviceA.getConfig(); assertEquals("test", config); }