use of com.puppycrawl.tools.checkstyle.api.LocalizedMessage in project checkstyle by checkstyle.
the class SuppressWarningsHolderTest method testIsSuppressedWithAllArgument.
@Test
public void testIsSuppressedWithAllArgument() throws Exception {
final Class<?> entry = Class.forName("com.puppycrawl.tools.checkstyle.checks.SuppressWarningsHolder$Entry");
final Constructor<?> entryConstr = entry.getDeclaredConstructor(String.class, int.class, int.class, int.class, int.class);
entryConstr.setAccessible(true);
final Object entryInstance = entryConstr.newInstance("all", 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 firstMessageForTest = new LocalizedMessage(100, 10, null, null, null, "id", MemberNameCheck.class, "msg");
final AuditEvent firstEventForTest = new AuditEvent(source, "fileName", firstMessageForTest);
assertFalse(SuppressWarningsHolder.isSuppressed(firstEventForTest));
final LocalizedMessage secondMessageForTest = new LocalizedMessage(100, 150, null, null, null, "id", MemberNameCheck.class, "msg");
final AuditEvent secondEventForTest = new AuditEvent(source, "fileName", secondMessageForTest);
assertTrue(SuppressWarningsHolder.isSuppressed(secondEventForTest));
final LocalizedMessage thirdMessageForTest = new LocalizedMessage(200, 1, null, null, null, "id", MemberNameCheck.class, "msg");
final AuditEvent thirdEventForTest = new AuditEvent(source, "fileName", thirdMessageForTest);
assertTrue(SuppressWarningsHolder.isSuppressed(thirdEventForTest));
}
use of com.puppycrawl.tools.checkstyle.api.LocalizedMessage in project checkstyle by checkstyle.
the class FileTabCharacterCheckTest method testBadFile.
@Test
public void testBadFile() throws Exception {
final DefaultConfiguration checkConfig = createConfig(false);
final String path = getPath("Claira");
final String exceptionMessage = " (No such file or directory)";
final LocalizedMessage localizedMessage = new LocalizedMessage(0, Definitions.CHECKSTYLE_BUNDLE, "general.exception", new String[] { path + exceptionMessage }, null, getClass(), null);
final String[] expected = { "0: " + localizedMessage.getMessage() };
final File[] files = { new File(path) };
verify(createChecker(checkConfig), files, path, expected);
}
use of com.puppycrawl.tools.checkstyle.api.LocalizedMessage in project checkstyle by checkstyle.
the class SuppressElementTest method testDecideByFileNameAndModuleMatchingRegExpNotMatch.
@Test
public void testDecideByFileNameAndModuleMatchingRegExpNotMatch() {
final LocalizedMessage message = new LocalizedMessage(10, 10, "", "", null, null, getClass(), null);
final AuditEvent ev = new AuditEvent(this, "T1est", message);
assertTrue(filter.accept(ev));
}
use of com.puppycrawl.tools.checkstyle.api.LocalizedMessage in project checkstyle by checkstyle.
the class SeverityMatchFilterTest method testSeverity.
@Test
public void testSeverity() {
filter.setSeverity(SeverityLevel.INFO);
final AuditEvent ev = new AuditEvent(this, "Test.java");
// event with no message has severity level INFO
assertTrue("no message", filter.accept(ev));
final SeverityLevel errorLevel = SeverityLevel.ERROR;
final LocalizedMessage errorMessage = new LocalizedMessage(0, 0, "", "", null, errorLevel, null, getClass(), null);
final AuditEvent ev2 = new AuditEvent(this, "ATest.java", errorMessage);
assertFalse("level:" + errorLevel, filter.accept(ev2));
final SeverityLevel infoLevel = SeverityLevel.INFO;
final LocalizedMessage infoMessage = new LocalizedMessage(0, 0, "", "", null, infoLevel, null, getClass(), null);
final AuditEvent ev3 = new AuditEvent(this, "ATest.java", infoMessage);
assertTrue("level:" + infoLevel, filter.accept(ev3));
}
use of com.puppycrawl.tools.checkstyle.api.LocalizedMessage in project checkstyle by checkstyle.
the class SeverityMatchFilterTest method testDefault.
@Test
public void testDefault() {
final AuditEvent ev = new AuditEvent(this, "Test.java");
assertFalse("no message", filter.accept(ev));
final SeverityLevel errorLevel = SeverityLevel.ERROR;
final LocalizedMessage errorMessage = new LocalizedMessage(0, 0, "", "", null, errorLevel, null, getClass(), null);
final AuditEvent ev2 = new AuditEvent(this, "ATest.java", errorMessage);
assertTrue("level:" + errorLevel, filter.accept(ev2));
final SeverityLevel infoLevel = SeverityLevel.INFO;
final LocalizedMessage infoMessage = new LocalizedMessage(0, 0, "", "", null, infoLevel, null, getClass(), null);
final AuditEvent ev3 = new AuditEvent(this, "ATest.java", infoMessage);
assertFalse("level:" + infoLevel, filter.accept(ev3));
}
Aggregations