Source:
public final void testExecuteLogOutput() throws Exception { final CheckstyleAntTaskLogStub antTask = new CheckstyleAntTaskLogStub(); final URL url = new File(getPath(CONFIG_FILE)).toURI().toURL(); antTask.setProject(new Project()); antTask.setConfig(url.toString()); antTask.setFile(new File(getPath(FLAWLESS_INPUT))); mockStatic(System.class); when(System.currentTimeMillis()).thenReturn(1L); final LocalizedMessage auditStartedMessage = new LocalizedMessage(0, Definitions.CHECKSTYLE_BUNDLE, "DefaultLogger.auditStarted", null, null, getClass(), null); final LocalizedMessage auditFinishedMessage = new LocalizedMessage(0, Definitions.CHECKSTYLE_BUNDLE, "DefaultLogger.auditFinished", null, null, getClass(), null); antTask.execute(); final List<MessageLevelPair> expectedList = Arrays.asList( new MessageLevelPair("checkstyle version ", Project.MSG_VERBOSE), new MessageLevelPair("compiled on ", Project.MSG_VERBOSE), new MessageLevelPair("Adding standalone file for audit", Project.MSG_VERBOSE), new MessageLevelPair("To locate the files took 0 ms.", Project.MSG_VERBOSE), new MessageLevelPair("Running Checkstyle ", Project.MSG_INFO), new MessageLevelPair("Using configuration ", Project.MSG_VERBOSE), new MessageLevelPair(auditStartedMessage.getMessage(), Project.MSG_DEBUG), new MessageLevelPair(auditFinishedMessage.getMessage(), Project.MSG_DEBUG), new MessageLevelPair("To process the files took 0 ms.", Project.MSG_VERBOSE), new MessageLevelPair("Total execution took 0 ms.", Project.MSG_VERBOSE) ); final List<MessageLevelPair> loggedMessages = antTask.getLoggedMessages(); assertEquals("Amount of log messages is unexpected", expectedList.size(), loggedMessages.size()); for (int i = 0; i < expectedList.size(); i++) { final MessageLevelPair expected = expectedList.get(i); final MessageLevelPair actual = loggedMessages.get(i); assertTrue("Log messages were expected", actual.getMsg().startsWith(expected.getMsg())); assertEquals("Log messages were expected", expected.getLevel(), actual.getLevel()); } }

Target:
public final void testExecuteLogOutput() throws Exception { final CheckstyleAntTaskLogStub antTask = new CheckstyleAntTaskLogStub(); final URL url = new File(getPath(CONFIG_FILE)).toURI().toURL(); antTask.setProject(new Project()); antTask.setConfig(url.toString()); antTask.setFile(new File(getPath(FLAWLESS_INPUT))); mockStatic(System.class); when(System.currentTimeMillis()).thenReturn(1L); antTask.execute(); final LocalizedMessage auditStartedMessage = new LocalizedMessage(0, Definitions.CHECKSTYLE_BUNDLE, "DefaultLogger.auditStarted", null, null, getClass(), null); final LocalizedMessage auditFinishedMessage = new LocalizedMessage(0, Definitions.CHECKSTYLE_BUNDLE, "DefaultLogger.auditFinished", null, null, getClass(), null); final List<MessageLevelPair> expectedList = Arrays.asList( new MessageLevelPair("checkstyle version ", Project.MSG_VERBOSE), new MessageLevelPair("compiled on ", Project.MSG_VERBOSE), new MessageLevelPair("Adding standalone file for audit", Project.MSG_VERBOSE), new MessageLevelPair("To locate the files took 0 ms.", Project.MSG_VERBOSE), new MessageLevelPair("Running Checkstyle ", Project.MSG_INFO), new MessageLevelPair("Using configuration ", Project.MSG_VERBOSE), new MessageLevelPair(auditStartedMessage.getMessage(), Project.MSG_DEBUG), new MessageLevelPair(auditFinishedMessage.getMessage(), Project.MSG_DEBUG), new MessageLevelPair("To process the files took 0 ms.", Project.MSG_VERBOSE), new MessageLevelPair("Total execution took 0 ms.", Project.MSG_VERBOSE) ); final List<MessageLevelPair> loggedMessages = antTask.getLoggedMessages(); assertEquals("Amount of log messages is unexpected", expectedList.size(), loggedMessages.size()); for (int i = 0; i < expectedList.size(); i++) { final MessageLevelPair expected = expectedList.get(i); final MessageLevelPair actual = loggedMessages.get(i); assertTrue("Log messages were expected", actual.getMsg().startsWith(expected.getMsg())); assertEquals("Log messages were expected", expected.getLevel(), actual.getLevel()); } }