Search in sources :

Example 41 with FileContents

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

the class SuppressionCommentFilterTest method testAcceptNullViolation.

@Test
public void testAcceptNullViolation() {
    final SuppressionCommentFilter filter = new SuppressionCommentFilter();
    final FileContents contents = new FileContents(new FileText(new File("filename"), Arrays.asList("//CHECKSTYLE:OFF: ConstantNameCheck", "line2")));
    contents.reportSingleLineComment(1, 0);
    final TreeWalkerAuditEvent auditEvent = new TreeWalkerAuditEvent(contents, null, null, null);
    assertWithMessage("Filter should accept audit event").that(filter.accept(auditEvent)).isTrue();
    assertWithMessage("File name should not be null").that(auditEvent.getFileName()).isNull();
}
Also used : FileContents(com.puppycrawl.tools.checkstyle.api.FileContents) TreeWalkerAuditEvent(com.puppycrawl.tools.checkstyle.TreeWalkerAuditEvent) FileText(com.puppycrawl.tools.checkstyle.api.FileText) File(java.io.File) Test(org.junit.jupiter.api.Test)

Example 42 with FileContents

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

the class SuppressionCommentFilterTest method testAcceptNullFileContents.

@Test
public void testAcceptNullFileContents() {
    final SuppressionCommentFilter filter = new SuppressionCommentFilter();
    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)

Example 43 with FileContents

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

the class SuppressionXpathSingleFilterTest method setUp.

@BeforeEach
public void setUp() throws Exception {
    file = new File(getPath("InputSuppressionXpathSingleFilter.java"));
    fileContents = new FileContents(new FileText(file, StandardCharsets.UTF_8.name()));
}
Also used : FileContents(com.puppycrawl.tools.checkstyle.api.FileContents) FileText(com.puppycrawl.tools.checkstyle.api.FileText) File(java.io.File) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 44 with FileContents

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

the class XpathFilterElementTest method setUp.

@BeforeEach
public void setUp() throws Exception {
    file = new File(getPath("InputXpathFilterElementSuppressByXpath.java"));
    fileContents = new FileContents(new FileText(file, StandardCharsets.UTF_8.name()));
}
Also used : FileContents(com.puppycrawl.tools.checkstyle.api.FileContents) FileText(com.puppycrawl.tools.checkstyle.api.FileText) File(java.io.File) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

FileContents (com.puppycrawl.tools.checkstyle.api.FileContents)44 FileText (com.puppycrawl.tools.checkstyle.api.FileText)18 File (java.io.File)15 Test (org.junit.jupiter.api.Test)11 DetailAST (com.puppycrawl.tools.checkstyle.api.DetailAST)10 TextBlock (com.puppycrawl.tools.checkstyle.api.TextBlock)9 TreeWalkerAuditEvent (com.puppycrawl.tools.checkstyle.TreeWalkerAuditEvent)8 Violation (com.puppycrawl.tools.checkstyle.api.Violation)7 ArrayList (java.util.ArrayList)7 CheckstyleException (com.puppycrawl.tools.checkstyle.api.CheckstyleException)6 TypeNameCheck (com.puppycrawl.tools.checkstyle.checks.naming.TypeNameCheck)3 RecognitionException (antlr.RecognitionException)2 TokenStreamException (antlr.TokenStreamException)2 List (java.util.List)2 BeforeEach (org.junit.jupiter.api.BeforeEach)2 TokenStreamRecognitionException (antlr.TokenStreamRecognitionException)1 LineColumn (com.puppycrawl.tools.checkstyle.api.LineColumn)1 LocalizedMessages (com.puppycrawl.tools.checkstyle.api.LocalizedMessages)1 Scope (com.puppycrawl.tools.checkstyle.api.Scope)1 CommentsIndentationCheck (com.puppycrawl.tools.checkstyle.checks.indentation.CommentsIndentationCheck)1