use of com.puppycrawl.tools.checkstyle.internal.testmodules.CheckstyleAntTaskLogStub in project checkstyle by checkstyle.
the class CheckstyleAntTaskTest method testPathsFileWithLogVerification.
@Test
public final void testPathsFileWithLogVerification() throws IOException {
// given
TestRootModuleChecker.reset();
final CheckstyleAntTaskLogStub antTask = new CheckstyleAntTaskLogStub();
antTask.setConfig(getPath(CUSTOM_ROOT_CONFIG_FILE));
antTask.setProject(new Project());
final FileSet examinationFileSet = new FileSet();
examinationFileSet.setFile(new File(getPath(FLAWLESS_INPUT)));
final Path sourcePath = new Path(antTask.getProject());
sourcePath.addFileset(examinationFileSet);
antTask.addPath(sourcePath);
antTask.addPath(new Path(new Project()));
// when
antTask.execute();
// then
final List<MessageLevelPair> loggedMessages = antTask.getLoggedMessages();
assertWithMessage("Scanning path was not logged").that(loggedMessages.stream().filter(msg -> msg.getMsg().startsWith("1) Scanning path")).count()).isEqualTo(1);
assertWithMessage("Scanning path was not logged").that(loggedMessages.stream().filter(msg -> msg.getMsg().startsWith("1) Adding 1 files from path")).count()).isEqualTo(1);
assertWithMessage("Scanning empty was logged").that(loggedMessages.stream().filter(msg -> msg.getMsg().startsWith("2) Adding 0 files from path ")).count()).isEqualTo(0);
assertWithMessage("Checker is not processed").that(TestRootModuleChecker.isProcessed()).isTrue();
final List<File> filesToCheck = TestRootModuleChecker.getFilesToCheck();
assertWithMessage("There are more files to check than expected").that(filesToCheck).hasSize(1);
assertWithMessage("The path of file differs from expected").that(filesToCheck.get(0).getAbsolutePath()).isEqualTo(getPath(FLAWLESS_INPUT));
}
use of com.puppycrawl.tools.checkstyle.internal.testmodules.CheckstyleAntTaskLogStub in project checkstyle by checkstyle.
the class CheckstyleAntTaskTest method testExecuteLogOutput.
@Test
public final void testExecuteLogOutput() throws Exception {
final URL url = new File(getPath(CONFIG_FILE)).toURI().toURL();
final ResourceBundle bundle = ResourceBundle.getBundle(Definitions.CHECKSTYLE_BUNDLE, Locale.ROOT);
final String auditStartedMessage = bundle.getString(DefaultLogger.AUDIT_STARTED_MESSAGE);
final String auditFinishedMessage = bundle.getString(DefaultLogger.AUDIT_FINISHED_MESSAGE);
final List<MessageLevelPair> expectedList = Arrays.asList(new MessageLevelPair("checkstyle version .*", Project.MSG_VERBOSE), new MessageLevelPair("Adding standalone file for audit", Project.MSG_VERBOSE), new MessageLevelPair("To locate the files took \\d+ ms.", Project.MSG_VERBOSE), new MessageLevelPair("Running Checkstyle on 1 files", Project.MSG_INFO), new MessageLevelPair("Using configuration file:.*", Project.MSG_VERBOSE), new MessageLevelPair(auditStartedMessage, Project.MSG_DEBUG), new MessageLevelPair(auditFinishedMessage, Project.MSG_DEBUG), new MessageLevelPair("To process the files took \\d+ ms.", Project.MSG_VERBOSE), new MessageLevelPair("Total execution took \\d+ ms.", Project.MSG_VERBOSE));
final CheckstyleAntTaskLogStub antTask = new CheckstyleAntTaskLogStub();
antTask.setProject(new Project());
antTask.setConfig(url.toString());
antTask.setFile(new File(getPath(FLAWLESS_INPUT)));
antTask.execute();
final List<MessageLevelPair> loggedMessages = antTask.getLoggedMessages();
assertWithMessage("Amount of log messages is unexpected").that(loggedMessages).hasSize(expectedList.size());
for (int i = 0; i < expectedList.size(); i++) {
final MessageLevelPair expected = expectedList.get(i);
final MessageLevelPair actual = loggedMessages.get(i);
assertWithMessage("Log messages should match").that(actual.getMsg()).matches(expected.getMsg());
assertWithMessage("Log levels should be equal").that(actual.getLevel()).isEqualTo(expected.getLevel());
}
}
use of com.puppycrawl.tools.checkstyle.internal.testmodules.CheckstyleAntTaskLogStub in project checkstyle by checkstyle.
the class CheckstyleAntTaskTest method testPathsDirectoryWithNestedFile.
@Test
public final void testPathsDirectoryWithNestedFile() throws IOException {
// given
TestRootModuleChecker.reset();
final CheckstyleAntTaskLogStub antTask = new CheckstyleAntTaskLogStub();
antTask.setConfig(getPath(CUSTOM_ROOT_CONFIG_FILE));
antTask.setProject(new Project());
final FileResource fileResource = new FileResource(antTask.getProject(), getPath(""));
final Path sourcePath = new Path(antTask.getProject());
sourcePath.add(fileResource);
antTask.addPath(sourcePath);
// when
antTask.execute();
// then
assertWithMessage("Checker is not processed").that(TestRootModuleChecker.isProcessed()).isTrue();
final List<File> filesToCheck = TestRootModuleChecker.getFilesToCheck();
assertWithMessage("There are more files to check than expected").that(filesToCheck).hasSize(8);
assertWithMessage("The path of file differs from expected").that(filesToCheck.get(5).getAbsolutePath()).isEqualTo(getPath(FLAWLESS_INPUT));
assertWithMessage("Amount of logged messages in unexpected").that(antTask.getLoggedMessages()).hasSize(8);
}
Aggregations