use of com.puppycrawl.tools.checkstyle.api.LocalizedMessage in project checkstyle by checkstyle.
the class SuppressElementTest method testDecideByFileNameAndModuleMatchingRegExpMatch.
@Test
public void testDecideByFileNameAndModuleMatchingRegExpMatch() {
final LocalizedMessage message = new LocalizedMessage(10, 10, "", "", null, null, getClass(), null);
final AuditEvent ev = new AuditEvent(this, "TestSUFFIX", message);
final SuppressElement filterWithoutChecks = new SuppressElement("Test");
assertFalse(filterWithoutChecks.accept(ev));
}
use of com.puppycrawl.tools.checkstyle.api.LocalizedMessage in project checkstyle by checkstyle.
the class SuppressElementTest method testDecideByFileNameAndModuleMatchingCheckRegExpMatch.
@Test
public void testDecideByFileNameAndModuleMatchingCheckRegExpMatch() {
final LocalizedMessage message = new LocalizedMessage(10, 10, "", "", null, null, getClass(), null);
final AuditEvent ev = new AuditEvent(this, "ATest.java", message);
filter.setChecks(getClass().getCanonicalName());
assertFalse(filter.accept(ev));
}
use of com.puppycrawl.tools.checkstyle.api.LocalizedMessage in project checkstyle by checkstyle.
the class SuppressElementTest method testDecideLocalizedMessage.
@Test
public void testDecideLocalizedMessage() {
final LocalizedMessage message = new LocalizedMessage(0, 0, "", "", null, null, getClass(), null);
final AuditEvent ev = new AuditEvent(this, "ATest.java", message);
//deny because there are matches on file and check names
assertFalse("Names match", filter.accept(ev));
}
use of com.puppycrawl.tools.checkstyle.api.LocalizedMessage in project checkstyle by checkstyle.
the class MainTest method testExistingDirectoryWithViolations.
@Test
public void testExistingDirectoryWithViolations() throws Exception {
// we just reference there all violations
final String[][] outputValues = { { "InputComplexityOverflow", "1", "172" } };
final int allowedLength = 170;
final String msgKey = "maxLen.file";
final String bundle = "com.puppycrawl.tools.checkstyle.checks.sizes.messages";
exit.checkAssertionAfterwards(new Assertion() {
@Override
public void checkAssertion() throws IOException {
final String expectedPath = getFilePath("checks/metrics") + File.separator;
final StringBuilder sb = new StringBuilder();
sb.append("Starting audit...").append(System.getProperty("line.separator"));
final String format = "[WARN] %s.java:%s: %s [FileLength]";
for (String[] outputValue : outputValues) {
final String localizedMessage = new LocalizedMessage(0, bundle, msgKey, new Integer[] { Integer.valueOf(outputValue[2]), allowedLength }, null, getClass(), null).getMessage();
final String line = String.format(Locale.ROOT, format, expectedPath + outputValue[0], outputValue[1], localizedMessage);
sb.append(line).append(System.getProperty("line.separator"));
}
sb.append("Audit done.").append(System.getProperty("line.separator"));
assertEquals(sb.toString(), systemOut.getLog());
assertEquals("", systemErr.getLog());
}
});
Main.main("-c", getPath("config-filelength.xml"), getPath("checks/metrics"));
}
use of com.puppycrawl.tools.checkstyle.api.LocalizedMessage in project checkstyle by checkstyle.
the class UniquePropertiesCheckTest method testIoException.
/**
* Tests IO exception, that can occur during reading of properties file.
*/
@Test
public void testIoException() throws Exception {
final UniquePropertiesCheck check = new UniquePropertiesCheck();
check.configure(checkConfig);
final String fileName = getPath("InputUniquePropertiesCheckNotExisting.properties");
final File file = new File(fileName);
final SortedSet<LocalizedMessage> messages = check.process(file, Collections.emptyList());
assertEquals("Wrong messages count: " + messages.size(), 1, messages.size());
final LocalizedMessage message = messages.iterator().next();
final String retrievedMessage = messages.iterator().next().getKey();
assertEquals("Message key '" + retrievedMessage + "' is not valid", "unable.open.cause", retrievedMessage);
assertEquals("Message '" + message.getMessage() + "' is not valid", message.getMessage(), getCheckMessage(MSG_IO_EXCEPTION_KEY, fileName, getFileNotFoundDetail(file)));
}
Aggregations