Search in sources :

Example 1 with LocalizedMessage

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));
}
Also used : Field(java.lang.reflect.Field) Checker(com.puppycrawl.tools.checkstyle.Checker) ArrayList(java.util.ArrayList) AuditEvent(com.puppycrawl.tools.checkstyle.api.AuditEvent) LocalizedMessage(com.puppycrawl.tools.checkstyle.api.LocalizedMessage) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 2 with LocalizedMessage

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);
}
Also used : DefaultConfiguration(com.puppycrawl.tools.checkstyle.DefaultConfiguration) File(java.io.File) LocalizedMessage(com.puppycrawl.tools.checkstyle.api.LocalizedMessage) Test(org.junit.Test)

Example 3 with LocalizedMessage

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));
}
Also used : AuditEvent(com.puppycrawl.tools.checkstyle.api.AuditEvent) LocalizedMessage(com.puppycrawl.tools.checkstyle.api.LocalizedMessage) Test(org.junit.Test)

Example 4 with LocalizedMessage

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));
}
Also used : SeverityLevel(com.puppycrawl.tools.checkstyle.api.SeverityLevel) AuditEvent(com.puppycrawl.tools.checkstyle.api.AuditEvent) LocalizedMessage(com.puppycrawl.tools.checkstyle.api.LocalizedMessage) Test(org.junit.Test)

Example 5 with LocalizedMessage

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));
}
Also used : SeverityLevel(com.puppycrawl.tools.checkstyle.api.SeverityLevel) AuditEvent(com.puppycrawl.tools.checkstyle.api.AuditEvent) LocalizedMessage(com.puppycrawl.tools.checkstyle.api.LocalizedMessage) Test(org.junit.Test)

Aggregations

LocalizedMessage (com.puppycrawl.tools.checkstyle.api.LocalizedMessage)37 Test (org.junit.Test)29 AuditEvent (com.puppycrawl.tools.checkstyle.api.AuditEvent)24 TreeSet (java.util.TreeSet)6 File (java.io.File)4 ArrayList (java.util.ArrayList)4 SeverityLevel (com.puppycrawl.tools.checkstyle.api.SeverityLevel)3 Checker (com.puppycrawl.tools.checkstyle.Checker)2 DefaultConfiguration (com.puppycrawl.tools.checkstyle.DefaultConfiguration)2 CheckstyleException (com.puppycrawl.tools.checkstyle.api.CheckstyleException)2 IOException (java.io.IOException)2 Field (java.lang.reflect.Field)2 CheckstyleCheckerListener (org.apache.maven.plugins.checkstyle.exec.CheckstyleCheckerListener)2 CheckstyleResults (org.apache.maven.plugins.checkstyle.exec.CheckstyleResults)2 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)2 AuditListener (com.puppycrawl.tools.checkstyle.api.AuditListener)1 FileNotFoundException (java.io.FileNotFoundException)1 RandomAccessFile (java.io.RandomAccessFile)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 HashMap (java.util.HashMap)1