Search in sources :

Example 41 with Violation

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

the class FileTabCharacterCheckTest method testBadFile.

@Test
public void testBadFile() throws Exception {
    final DefaultConfiguration checkConfig = createModuleConfig(FileTabCharacterCheck.class);
    checkConfig.addProperty("eachLine", "false");
    final String path = getPath("Claira");
    final String exceptionMessage = " (No such file or directory)";
    final Violation violation = new Violation(1, Definitions.CHECKSTYLE_BUNDLE, "general.exception", new String[] { path + exceptionMessage }, null, getClass(), null);
    final String[] expected = { "1: " + violation.getViolation() };
    verify(createChecker(checkConfig), path, expected);
}
Also used : Violation(com.puppycrawl.tools.checkstyle.api.Violation) DefaultConfiguration(com.puppycrawl.tools.checkstyle.DefaultConfiguration) Test(org.junit.jupiter.api.Test)

Example 42 with Violation

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

the class SuppressFilterElementTest method testDecideViolation.

@Test
public void testDecideViolation() {
    final Violation violation = new Violation(1, 0, "", "", null, null, getClass(), null);
    final AuditEvent ev = new AuditEvent(this, "ATest.java", violation);
    // deny because there are matches on file and check names
    assertWithMessage("Names match").that(filter.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 43 with Violation

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

the class SuppressFilterElementTest method testDecideByFileNameAndModuleMatchingCheckRegExpMatch.

@Test
public void testDecideByFileNameAndModuleMatchingCheckRegExpMatch() {
    final Violation message = new Violation(10, 10, "", "", null, null, getClass(), null);
    final AuditEvent ev = new AuditEvent(this, "ATest.java", message);
    final SuppressFilterElement myFilter = new SuppressFilterElement("Test", getClass().getCanonicalName(), 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 44 with Violation

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

the class SuppressFilterElementTest method testDecideByFileNameAndModuleMatchingModuleNotEqual.

@Test
public void testDecideByFileNameAndModuleMatchingModuleNotEqual() {
    final Violation message = new Violation(10, 10, "", "", null, "TheirModule", getClass(), null);
    final AuditEvent ev = new AuditEvent(this, "ATest.java", message);
    final SuppressFilterElement myFilter = new SuppressFilterElement("Test", "Test", null, "MyModule", null, null);
    assertWithMessage("Filter should accept valid event").that(myFilter.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 45 with Violation

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

the class SuppressWithNearbyCommentFilterTest method getTagsAfterExecution.

/**
 * Calls the filter with a minimal set of inputs and returns a list of
 * {@link SuppressWithNearbyCommentFilter} internal type {@code Tag}.
 * Our goal is 100% test coverage, for this we use white-box testing.
 * So we need access to the implementation details. For this reason,
 * it is necessary to use reflection to gain access to the inner field here.
 *
 * @return {@code Tag} list
 */
private static List<?> getTagsAfterExecution(SuppressWithNearbyCommentFilter filter, String filename, String... lines) {
    final FileContents contents = new FileContents(new FileText(new File(filename), Arrays.asList(lines)));
    contents.reportSingleLineComment(1, 0);
    final TreeWalkerAuditEvent dummyEvent = new TreeWalkerAuditEvent(contents, filename, new Violation(1, null, null, null, null, Object.class, null), null);
    filter.accept(dummyEvent);
    return TestUtil.getInternalState(filter, "tags");
}
Also used : Violation(com.puppycrawl.tools.checkstyle.api.Violation) FileContents(com.puppycrawl.tools.checkstyle.api.FileContents) TreeWalkerAuditEvent(com.puppycrawl.tools.checkstyle.TreeWalkerAuditEvent) FileText(com.puppycrawl.tools.checkstyle.api.FileText) File(java.io.File)

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