Utils { static void logErrorMessageWithCounter(Logger logger, AtomicInteger atomicInteger, String errorMessage) { logErrorMessageWithCounter(logger, atomicInteger, errorMessage, WAIT_COUNT_MAX); } private  Utils();   }
@Test public void testLogErrorMsgWaitDefault() throws Exception { final String expectedErrorMessage = "This is a test error message!"; EasyMockSupport mockSupport = new EasyMockSupport(); Logger loggerMock = mockSupport.createMock(Logger.class); AtomicInteger testAtomicInteger = new AtomicInteger(0); loggerMock.error(expectedErrorMessage); expectLastCall().times(1); mockSupport.replayAll(); for (int i = 0; i < 1000; i++) { Utils.logErrorMessageWithCounter(loggerMock, testAtomicInteger, expectedErrorMessage); } mockSupport.verifyAll(); }
@Test public void testLogErrorMsgWaitDefaultExceedsMaxCount() throws Exception { final String expectedErrorMessage = "This is a test error message that should only repeat once!"; EasyMockSupport mockSupport = new EasyMockSupport(); Logger loggerMock = mockSupport.createMock(Logger.class); AtomicInteger testAtomicInteger = new AtomicInteger(0); loggerMock.error(expectedErrorMessage); expectLastCall().times(2); mockSupport.replayAll(); for (int i = 0; i < 2000; i++) { Utils.logErrorMessageWithCounter(loggerMock, testAtomicInteger, expectedErrorMessage); } mockSupport.verifyAll(); }
@Test public void testLogErrorMsgWithCustomWaitMax() throws Exception { final String expectedErrorMessage = "This is a test error message!"; EasyMockSupport mockSupport = new EasyMockSupport(); Logger loggerMock = mockSupport.createMock(Logger.class); AtomicInteger testAtomicInteger = new AtomicInteger(0); loggerMock.error(expectedErrorMessage); expectLastCall().times(1); mockSupport.replayAll(); for (int i = 0; i < 5; i++) { Utils.logErrorMessageWithCounter(loggerMock, testAtomicInteger, expectedErrorMessage, 5); } mockSupport.verifyAll(); }
@Test public void testLogErrorMsgWaitExceedsCustomMaxCount() throws Exception { final String expectedErrorMessage = "This is a test error message that should only repeat once!"; EasyMockSupport mockSupport = new EasyMockSupport(); Logger loggerMock = mockSupport.createMock(Logger.class); AtomicInteger testAtomicInteger = new AtomicInteger(0); loggerMock.error(expectedErrorMessage); expectLastCall().times(2); mockSupport.replayAll(); for (int i = 0; i < 10; i++) { Utils.logErrorMessageWithCounter(loggerMock, testAtomicInteger, expectedErrorMessage, 5); } mockSupport.verifyAll(); }