EndlessLoopPreventer { public void assertNoEndlessLoop() { endlessLoopCounter++; if (endlessLoopCounter>maximumLoops){ throw new EndlessLoopException(endlessLoopCounter); } } EndlessLoopPreventer(int maximumAllowedLoops); void assertNoEndlessLoop();  }
@Test public void setting_max_2_and_calling_three_times_throws_loopexception() { EndlessLoopPreventer preventer = new EndlessLoopPreventer(2); preventer.assertNoEndlessLoop(); preventer.assertNoEndlessLoop(); expected.expect(EndlessLoopException.class); preventer.assertNoEndlessLoop(); }