Search in sources :

Example 31 with LocalizedMessage

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

Example 32 with LocalizedMessage

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

Example 33 with LocalizedMessage

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

Example 34 with LocalizedMessage

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"));
}
Also used : Assertion(org.junit.contrib.java.lang.system.Assertion) IOException(java.io.IOException) LocalizedMessage(com.puppycrawl.tools.checkstyle.api.LocalizedMessage) Test(org.junit.Test)

Example 35 with LocalizedMessage

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)));
}
Also used : File(java.io.File) 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