use of com.puppycrawl.tools.checkstyle.api.LocalizedMessage in project maven-plugins by apache.
the class CheckstyleResultsTest method testResults.
public void testResults() {
Map<String, List<AuditEvent>> files = new HashMap<>();
LocalizedMessage message = new LocalizedMessage(0, 0, "", "", null, SeverityLevel.INFO, null, getClass(), null);
AuditEvent event = new AuditEvent(this, "file1", message);
files.put("file1", Collections.singletonList(event));
message = new LocalizedMessage(0, 0, "", "", null, SeverityLevel.WARNING, null, getClass(), null);
List<AuditEvent> events = new ArrayList<>();
events.add(new AuditEvent(this, "file2", message));
events.add(new AuditEvent(this, "file2", message));
files.put("file2", events);
message = new LocalizedMessage(0, 0, "", "", null, SeverityLevel.ERROR, null, getClass(), null);
events = new ArrayList<>();
events.add(new AuditEvent(this, "file3", message));
events.add(new AuditEvent(this, "file3", message));
events.add(new AuditEvent(this, "file3", message));
files.put("file3", events);
message = new LocalizedMessage(0, 0, "", "", null, SeverityLevel.IGNORE, null, getClass(), null);
events = new ArrayList<>();
events.add(new AuditEvent(this, "file4", message));
events.add(new AuditEvent(this, "file4", message));
events.add(new AuditEvent(this, "file4", message));
events.add(new AuditEvent(this, "file4", message));
files.put("file4", events);
results.setFiles(files);
assertEquals("test total files", 4, results.getFiles().size());
assertEquals("test file count", 4, results.getFileCount());
assertEquals("test file severities", 0, results.getSeverityCount("file0", SeverityLevel.INFO));
assertEquals("test file severities", 0, results.getSeverityCount("file0", SeverityLevel.WARNING));
assertEquals("test file severities", 0, results.getSeverityCount("file0", SeverityLevel.ERROR));
assertEquals("test file severities", 0, results.getSeverityCount("file0", SeverityLevel.IGNORE));
assertEquals("test file violations", 1, results.getFileViolations("file1").size());
assertEquals("test file severities", 1, results.getSeverityCount("file1", SeverityLevel.INFO));
assertEquals("test file severities", 0, results.getSeverityCount("file1", SeverityLevel.WARNING));
assertEquals("test file severities", 0, results.getSeverityCount("file1", SeverityLevel.ERROR));
assertEquals("test file severities", 0, results.getSeverityCount("file1", SeverityLevel.IGNORE));
assertEquals("test file violations", 2, results.getFileViolations("file2").size());
assertEquals("test file severities", 0, results.getSeverityCount("file2", SeverityLevel.INFO));
assertEquals("test file severities", 2, results.getSeverityCount("file2", SeverityLevel.WARNING));
assertEquals("test file severities", 0, results.getSeverityCount("file2", SeverityLevel.ERROR));
assertEquals("test file severities", 0, results.getSeverityCount("file2", SeverityLevel.IGNORE));
assertEquals("test file violations", 3, results.getFileViolations("file3").size());
assertEquals("test file severities", 0, results.getSeverityCount("file3", SeverityLevel.INFO));
assertEquals("test file severities", 0, results.getSeverityCount("file3", SeverityLevel.WARNING));
assertEquals("test file severities", 3, results.getSeverityCount("file3", SeverityLevel.ERROR));
assertEquals("test file severities", 0, results.getSeverityCount("file3", SeverityLevel.IGNORE));
assertEquals("test file violations", 4, results.getFileViolations("file4").size());
assertEquals("test file severities", 0, results.getSeverityCount("file4", SeverityLevel.INFO));
assertEquals("test file severities", 0, results.getSeverityCount("file4", SeverityLevel.WARNING));
assertEquals("test file severities", 0, results.getSeverityCount("file4", SeverityLevel.ERROR));
assertEquals("test file severities", 4, results.getSeverityCount("file4", SeverityLevel.IGNORE));
assertEquals("test INFO severity count", 1, results.getSeverityCount(SeverityLevel.INFO));
assertEquals("test WARNING severity count", 2, results.getSeverityCount(SeverityLevel.WARNING));
assertEquals("test ERROR severity count", 3, results.getSeverityCount(SeverityLevel.ERROR));
assertEquals("test IGNORE severity count", 4, results.getSeverityCount(SeverityLevel.IGNORE));
results.setFileViolations("file", Collections.<AuditEvent>emptyList());
assertEquals("test file violations", 0, results.getFileViolations("file").size());
}
use of com.puppycrawl.tools.checkstyle.api.LocalizedMessage in project checkstyle by checkstyle.
the class TranslationCheck method logIoException.
/**
* Helper method to log an io exception.
* @param exception the exception that occurred
* @param file the file that could not be processed
*/
private void logIoException(IOException exception, File file) {
String[] args = null;
String key = "general.fileNotFound";
if (!(exception instanceof FileNotFoundException)) {
args = new String[] { exception.getMessage() };
key = "general.exception";
}
final LocalizedMessage message = new LocalizedMessage(0, Definitions.CHECKSTYLE_BUNDLE, key, args, getId(), getClass(), null);
final SortedSet<LocalizedMessage> messages = new TreeSet<>();
messages.add(message);
getMessageDispatcher().fireErrors(file.getPath(), messages);
LOG.debug("IOException occurred.", exception);
}
use of com.puppycrawl.tools.checkstyle.api.LocalizedMessage in project checkstyle by checkstyle.
the class CheckerTest method testRemoveListener.
@Test
public void testRemoveListener() throws Exception {
final Checker checker = new Checker();
final DebugAuditAdapter auditAdapter = new DebugAuditAdapter();
final DebugAuditAdapter aa2 = new DebugAuditAdapter();
checker.addListener(auditAdapter);
checker.addListener(aa2);
checker.removeListener(auditAdapter);
// Let's try fire some events
getFireAuditStartedMethod().invoke(checker);
assertTrue("Checker.fireAuditStarted() doesn't call listener", aa2.wasCalled());
assertFalse("Checker.fireAuditStarted() does call removed listener", auditAdapter.wasCalled());
aa2.resetListener();
getFireAuditFinished().invoke(checker);
assertTrue("Checker.fireAuditFinished() doesn't call listener", aa2.wasCalled());
assertFalse("Checker.fireAuditFinished() does call removed listener", auditAdapter.wasCalled());
aa2.resetListener();
checker.fireFileStarted("Some File Name");
assertTrue("Checker.fireFileStarted() doesn't call listener", aa2.wasCalled());
assertFalse("Checker.fireFileStarted() does call removed listener", auditAdapter.wasCalled());
aa2.resetListener();
checker.fireFileFinished("Some File Name");
assertTrue("Checker.fireFileFinished() doesn't call listener", aa2.wasCalled());
assertFalse("Checker.fireFileFinished() does call removed listener", auditAdapter.wasCalled());
aa2.resetListener();
final SortedSet<LocalizedMessage> messages = new TreeSet<>();
messages.add(new LocalizedMessage(0, 0, "a Bundle", "message.key", new Object[] { "arg" }, null, getClass(), null));
checker.fireErrors("Some File Name", messages);
assertTrue("Checker.fireErrors() doesn't call listener", aa2.wasCalled());
assertFalse("Checker.fireErrors() does call removed listener", auditAdapter.wasCalled());
}
use of com.puppycrawl.tools.checkstyle.api.LocalizedMessage in project checkstyle by checkstyle.
the class CheckerTest method testRemoveFilter.
@Test
public void testRemoveFilter() {
final Checker checker = new Checker();
final DebugFilter filter = new DebugFilter();
final DebugFilter f2 = new DebugFilter();
checker.addFilter(filter);
checker.addFilter(f2);
checker.removeFilter(filter);
f2.resetFilter();
final SortedSet<LocalizedMessage> messages = new TreeSet<>();
messages.add(new LocalizedMessage(0, 0, "a Bundle", "message.key", new Object[] { "arg" }, null, getClass(), null));
checker.fireErrors("Some File Name", messages);
assertTrue("Checker.fireErrors() doesn't call filter", f2.wasCalled());
assertFalse("Checker.fireErrors() does call removed filter", filter.wasCalled());
}
use of com.puppycrawl.tools.checkstyle.api.LocalizedMessage in project checkstyle by checkstyle.
the class CheckerTest method testDestroy.
@Test
public void testDestroy() throws Exception {
final Checker checker = new Checker();
final DebugAuditAdapter auditAdapter = new DebugAuditAdapter();
checker.addListener(auditAdapter);
final DebugFilter filter = new DebugFilter();
checker.addFilter(filter);
// should remove al listeners and filters
checker.destroy();
// Let's try fire some events
getFireAuditStartedMethod().invoke(checker);
getFireAuditFinished().invoke(checker);
checker.fireFileStarted("Some File Name");
checker.fireFileFinished("Some File Name");
final SortedSet<LocalizedMessage> messages = new TreeSet<>();
messages.add(new LocalizedMessage(0, 0, "a Bundle", "message.key", new Object[] { "arg" }, null, getClass(), null));
checker.fireErrors("Some File Name", messages);
assertFalse("Checker.destroy() doesn't remove listeners.", auditAdapter.wasCalled());
assertFalse("Checker.destroy() doesn't remove filters.", filter.wasCalled());
}
Aggregations