Search in sources :

Example 6 with LocalizedMessage

use of com.puppycrawl.tools.checkstyle.api.LocalizedMessage in project checkstyle by checkstyle.

the class SuppressElementTest method testDecideByFileNameAndModuleMatchingModuleNull.

@Test
public void testDecideByFileNameAndModuleMatchingModuleNull() {
    final LocalizedMessage message = new LocalizedMessage(10, 10, "", "", null, "MyModule", getClass(), null);
    final AuditEvent ev = new AuditEvent(this, "ATest.java", message);
    filter.setModuleId(null);
    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 7 with LocalizedMessage

use of com.puppycrawl.tools.checkstyle.api.LocalizedMessage in project checkstyle by checkstyle.

the class SuppressElementTest method testDecideByFileNameAndModuleMatchingFileNameNull.

@Test
public void testDecideByFileNameAndModuleMatchingFileNameNull() {
    final LocalizedMessage message = new LocalizedMessage(10, 10, "", "", null, null, getClass(), null);
    final AuditEvent ev = new AuditEvent(this, null, 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 8 with LocalizedMessage

use of com.puppycrawl.tools.checkstyle.api.LocalizedMessage in project checkstyle by checkstyle.

the class XMLLoggerTest method testAddException.

@Test
public void testAddException() throws IOException {
    final XMLLogger logger = new XMLLogger(outStream, true);
    logger.auditStarted(null);
    final LocalizedMessage message = new LocalizedMessage(1, 1, "messages.properties", null, null, null, getClass(), null);
    final AuditEvent ev = new AuditEvent(this, "Test.java", message);
    logger.addException(ev, new TestException("msg", new RuntimeException("msg")));
    logger.auditFinished(null);
    final String[] expectedLines = { "<exception>", "<![CDATA[", "stackTrace]]>", "</exception>", "" };
    verifyLines(expectedLines);
}
Also used : AuditEvent(com.puppycrawl.tools.checkstyle.api.AuditEvent) LocalizedMessage(com.puppycrawl.tools.checkstyle.api.LocalizedMessage) Test(org.junit.Test)

Example 9 with LocalizedMessage

use of com.puppycrawl.tools.checkstyle.api.LocalizedMessage in project checkstyle by checkstyle.

the class XMLLoggerTest method testAddErrorOnZeroColumns.

@Test
public void testAddErrorOnZeroColumns() throws IOException {
    final XMLLogger logger = new XMLLogger(outStream, true);
    logger.auditStarted(null);
    final LocalizedMessage message = new LocalizedMessage(1, 0, "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\" severity=\"error\" message=\"key\"" + " source=\"com.puppycrawl.tools.checkstyle.XMLLoggerTest\"/>" };
    verifyLines(expectedLines);
}
Also used : AuditEvent(com.puppycrawl.tools.checkstyle.api.AuditEvent) LocalizedMessage(com.puppycrawl.tools.checkstyle.api.LocalizedMessage) Test(org.junit.Test)

Example 10 with LocalizedMessage

use of com.puppycrawl.tools.checkstyle.api.LocalizedMessage in project checkstyle by checkstyle.

the class PackageObjectFactory method createModule.

/**
     * Creates a new instance of a class from a given name, or that name
     * concatenated with &quot;Check&quot;. If the name is
     * a class name, creates an instance of the named class. Otherwise, creates
     * an instance of a class name obtained by concatenating the given name
     * to a package name from a given list of package names.
     * @param name the name of a class.
     * @return the {@code Object} created by loader.
     * @throws CheckstyleException if an error occurs.
     */
@Override
public Object createModule(String name) throws CheckstyleException {
    Object instance = createObjectFromMap(name);
    if (instance == null) {
        instance = createObjectWithIgnoringProblems(name, getAllPossibleNames(name));
    }
    if (instance == null) {
        final String nameCheck = name + CHECK_SUFFIX;
        instance = createObjectWithIgnoringProblems(nameCheck, getAllPossibleNames(nameCheck));
        if (instance == null) {
            final String attemptedNames = joinPackageNamesWithClassName(name, packages) + STRING_SEPARATOR + nameCheck + STRING_SEPARATOR + joinPackageNamesWithClassName(nameCheck, packages);
            final LocalizedMessage exceptionMessage = new LocalizedMessage(0, Definitions.CHECKSTYLE_BUNDLE, UNABLE_TO_INSTANTIATE_EXCEPTION_MESSAGE, new String[] { name, attemptedNames }, null, getClass(), null);
            throw new CheckstyleException(exceptionMessage.getMessage());
        }
    }
    return instance;
}
Also used : CheckstyleException(com.puppycrawl.tools.checkstyle.api.CheckstyleException) LocalizedMessage(com.puppycrawl.tools.checkstyle.api.LocalizedMessage)

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