use of com.puppycrawl.tools.checkstyle.api.LocalizedMessage in project checkstyle by checkstyle.
the class SuppressWarningsHolderTest method testIsSuppressed.
@Test
public void testIsSuppressed() throws Exception {
final Class<?> entry = Class.forName("com.puppycrawl.tools.checkstyle.checks.SuppressWarningsHolder$Entry");
final Constructor<?> entryConstructor = entry.getDeclaredConstructor(String.class, int.class, int.class, int.class, int.class);
entryConstructor.setAccessible(true);
final Object entryInstance = entryConstructor.newInstance("MockEntry", 100, 100, 350, 350);
final List<Object> entriesList = new ArrayList<>();
entriesList.add(entryInstance);
final ThreadLocal<?> threadLocal = mock(ThreadLocal.class);
PowerMockito.doReturn(entriesList).when(threadLocal, "get");
final SuppressWarningsHolder holder = new SuppressWarningsHolder();
final Field entries = holder.getClass().getDeclaredField("ENTRIES");
entries.setAccessible(true);
entries.set(holder, threadLocal);
final Checker source = new Checker();
final LocalizedMessage message = new LocalizedMessage(100, 10, null, null, null, "id", MemberNameCheck.class, "message");
final AuditEvent event = new AuditEvent(source, "fileName", message);
assertFalse(SuppressWarningsHolder.isSuppressed(event));
}
use of com.puppycrawl.tools.checkstyle.api.LocalizedMessage in project checkstyle by checkstyle.
the class XMLLoggerTest method testAddError.
@Test
public void testAddError() throws IOException {
final XMLLogger logger = new XMLLogger(outStream, true);
logger.auditStarted(null);
final LocalizedMessage message = new LocalizedMessage(1, 1, "messages.properties", "key", null, SeverityLevel.ERROR, null, getClass(), null);
final AuditEvent ev = new AuditEvent(this, "Test.java", message);
logger.addError(ev);
logger.auditFinished(null);
final String[] expectedLines = { "<error line=\"1\" column=\"1\" severity=\"error\" message=\"key\"" + " source=\"com.puppycrawl.tools.checkstyle.XMLLoggerTest\"/>" };
verifyLines(expectedLines);
}
use of com.puppycrawl.tools.checkstyle.api.LocalizedMessage in project checkstyle by checkstyle.
the class XMLLoggerTest method testAddIgnored.
@Test
public void testAddIgnored() throws IOException {
final XMLLogger logger = new XMLLogger(outStream, true);
logger.auditStarted(null);
final LocalizedMessage message = new LocalizedMessage(1, 1, "messages.properties", "key", null, SeverityLevel.IGNORE, null, getClass(), null);
final AuditEvent ev = new AuditEvent(this, "Test.java", message);
logger.addError(ev);
logger.auditFinished(null);
final String[] expectedLines = CommonUtils.EMPTY_STRING_ARRAY;
verifyLines(expectedLines);
}
use of com.puppycrawl.tools.checkstyle.api.LocalizedMessage in project checkstyle by checkstyle.
the class NewlineAtEndOfFileCheckTest method testWrongFile.
@Test
public void testWrongFile() throws Exception {
final DefaultConfiguration checkConfig = createCheckConfig(NewlineAtEndOfFileCheck.class);
final NewlineAtEndOfFileCheck check = new NewlineAtEndOfFileCheck();
check.configure(checkConfig);
final List<String> lines = new ArrayList<>(1);
lines.add("txt");
final File impossibleFile = new File("");
final Set<LocalizedMessage> messages = check.process(impossibleFile, lines);
assertEquals(1, messages.size());
final Iterator<LocalizedMessage> iterator = messages.iterator();
assertEquals(getCheckMessage(MSG_KEY_UNABLE_OPEN, ""), iterator.next().getMessage());
}
use of com.puppycrawl.tools.checkstyle.api.LocalizedMessage in project checkstyle by checkstyle.
the class SuppressElementTest method testDecideByFileNameAndModuleMatchingModuleNotEqual.
@Test
public void testDecideByFileNameAndModuleMatchingModuleNotEqual() {
final LocalizedMessage message = new LocalizedMessage(10, 10, "", "", null, "TheirModule", getClass(), null);
final AuditEvent ev = new AuditEvent(this, "ATest.java", message);
filter.setModuleId("MyModule");
assertTrue(filter.accept(ev));
}
Aggregations