Search in sources :

Example 96 with Violation

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

the class DetailNodeTreeStringPrinterTest method testParseErrorMessage.

@Test
public void testParseErrorMessage() throws Exception {
    final String actual = TestUtil.invokeStaticMethod(DetailNodeTreeStringPrinter.class, "getParseErrorMessage", new ParseErrorMessage(10, MSG_JAVADOC_PARSE_RULE_ERROR, 9, "no viable alternative at input ' xyz'", "SOME_JAVADOC_ELEMENT"));
    final Violation violation = new Violation(10, "com.puppycrawl.tools.checkstyle.checks.javadoc.messages", MSG_JAVADOC_PARSE_RULE_ERROR, new Object[] { 9, "no viable alternative at input ' xyz'", "SOME_JAVADOC_ELEMENT" }, "", DetailNodeTreeStringPrinter.class, null);
    final String expected = "[ERROR:10] " + violation.getViolation();
    assertWithMessage("Javadoc parse error violation doesn't meet expectations").that(actual).isEqualTo(expected);
}
Also used : Violation(com.puppycrawl.tools.checkstyle.api.Violation) ParseErrorMessage(com.puppycrawl.tools.checkstyle.JavadocDetailNodeParser.ParseErrorMessage) Test(org.junit.jupiter.api.Test)

Example 97 with Violation

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

the class SuppressFilterElementTest method testDecideByFileNameAndModuleMatchingModuleEqual.

@Test
public void testDecideByFileNameAndModuleMatchingModuleEqual() {
    final Violation violation = new Violation(10, 10, "", "", null, "MyModule", getClass(), null);
    final AuditEvent ev = new AuditEvent(this, "ATest.java", violation);
    final SuppressFilterElement myFilter = new SuppressFilterElement("Test", "Test", null, "MyModule", null, null);
    assertWithMessage("Filter should not accept invalid event").that(myFilter.accept(ev)).isFalse();
}
Also used : Violation(com.puppycrawl.tools.checkstyle.api.Violation) AuditEvent(com.puppycrawl.tools.checkstyle.api.AuditEvent) Test(org.junit.jupiter.api.Test) TreeWalkerTest(com.puppycrawl.tools.checkstyle.TreeWalkerTest)

Example 98 with Violation

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

the class SuppressFilterElementTest method testDecideByFileNameAndModuleMatchingRegExpMatch.

@Test
public void testDecideByFileNameAndModuleMatchingRegExpMatch() {
    final Violation message = new Violation(10, 10, "", "", null, null, getClass(), null);
    final AuditEvent ev = new AuditEvent(this, "TestSUFFIX", message);
    final SuppressFilterElement myFilter = new SuppressFilterElement("Test", null, null, null, null, null);
    assertWithMessage("Filter should not accept invalid event").that(myFilter.accept(ev)).isFalse();
}
Also used : Violation(com.puppycrawl.tools.checkstyle.api.Violation) AuditEvent(com.puppycrawl.tools.checkstyle.api.AuditEvent) Test(org.junit.jupiter.api.Test) TreeWalkerTest(com.puppycrawl.tools.checkstyle.TreeWalkerTest)

Example 99 with Violation

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

the class SuppressFilterElementTest method testDecideByFileNameAndModuleMatchingFileNameNull.

@Test
public void testDecideByFileNameAndModuleMatchingFileNameNull() {
    final Violation message = new Violation(10, 10, "", "", null, null, getClass(), null);
    final AuditEvent ev = new AuditEvent(this, null, message);
    assertWithMessage("Filter should accept valid event").that(filter.accept(ev)).isTrue();
}
Also used : Violation(com.puppycrawl.tools.checkstyle.api.Violation) AuditEvent(com.puppycrawl.tools.checkstyle.api.AuditEvent) Test(org.junit.jupiter.api.Test) TreeWalkerTest(com.puppycrawl.tools.checkstyle.TreeWalkerTest)

Example 100 with Violation

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

the class SuppressWithNearbyCommentFilterTest method testAcceptNullFileContents.

@Test
public void testAcceptNullFileContents() {
    final SuppressWithNearbyCommentFilter filter = new SuppressWithNearbyCommentFilter();
    final FileContents contents = null;
    final TreeWalkerAuditEvent auditEvent = new TreeWalkerAuditEvent(contents, null, new Violation(1, null, null, null, null, Object.class, null), null);
    assertWithMessage("Filter should accept audit event").that(filter.accept(auditEvent)).isTrue();
}
Also used : Violation(com.puppycrawl.tools.checkstyle.api.Violation) FileContents(com.puppycrawl.tools.checkstyle.api.FileContents) TreeWalkerAuditEvent(com.puppycrawl.tools.checkstyle.TreeWalkerAuditEvent) Test(org.junit.jupiter.api.Test)

Aggregations

Violation (com.puppycrawl.tools.checkstyle.api.Violation)109 Test (org.junit.jupiter.api.Test)98 AuditEvent (com.puppycrawl.tools.checkstyle.api.AuditEvent)51 TreeWalkerAuditEvent (com.puppycrawl.tools.checkstyle.TreeWalkerAuditEvent)17 File (java.io.File)14 TreeWalkerTest (com.puppycrawl.tools.checkstyle.TreeWalkerTest)13 CheckstyleException (com.puppycrawl.tools.checkstyle.api.CheckstyleException)10 DefaultConfiguration (com.puppycrawl.tools.checkstyle.DefaultConfiguration)8 FileContents (com.puppycrawl.tools.checkstyle.api.FileContents)7 FileText (com.puppycrawl.tools.checkstyle.api.FileText)7 TreeSet (java.util.TreeSet)6 DetailAstImpl (com.puppycrawl.tools.checkstyle.DetailAstImpl)5 ParseErrorMessage (com.puppycrawl.tools.checkstyle.JavadocDetailNodeParser.ParseErrorMessage)3 SeverityLevel (com.puppycrawl.tools.checkstyle.api.SeverityLevel)3 DebugAuditAdapter (com.puppycrawl.tools.checkstyle.internal.testmodules.DebugAuditAdapter)3 DebugFilter (com.puppycrawl.tools.checkstyle.internal.testmodules.DebugFilter)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 OutputStream (java.io.OutputStream)3 Method (java.lang.reflect.Method)3 Checker (com.puppycrawl.tools.checkstyle.Checker)2