diff --git a/pom.xml b/pom.xml index 85f45cbfc..7c42c8c3f 100644 --- a/pom.xml +++ b/pom.xml @@ -1088,7 +1088,6 @@ .*.api.AuditEvent10093 .*.api.AutomaticBean9082 .*.api.AutomaticBean\$.*7590 - .*.api.FileContents9693 .*.api.FileText5059 .*.api.JavadocTagInfo2577 .*.api.JavadocTagInfo\$.*08 diff --git a/src/main/java/com/puppycrawl/tools/checkstyle/api/FileContents.java b/src/main/java/com/puppycrawl/tools/checkstyle/api/FileContents.java index 589cc87fb..583edf982 100644 --- a/src/main/java/com/puppycrawl/tools/checkstyle/api/FileContents.java +++ b/src/main/java/com/puppycrawl/tools/checkstyle/api/FileContents.java @@ -74,7 +74,8 @@ public final class FileContents implements CommentListener { * @deprecated Use {@link #FileContents(FileText)} instead * in order to preserve the original line breaks where possible. */ - @Deprecated public FileContents(String filename, String... lines) { + @Deprecated + public FileContents(String filename, String... lines) { this.fileName = filename; text = FileText.fromLines(new File(filename), Arrays.asList(lines)); } diff --git a/src/test/java/com/puppycrawl/tools/checkstyle/api/FileContentsTest.java b/src/test/java/com/puppycrawl/tools/checkstyle/api/FileContentsTest.java new file mode 100644 index 000000000..19b443f7e --- /dev/null +++ b/src/test/java/com/puppycrawl/tools/checkstyle/api/FileContentsTest.java @@ -0,0 +1,38 @@ +package com.puppycrawl.tools.checkstyle.api; + +import org.junit.Test; + +import java.io.File; +import java.util.Arrays; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +public class FileContentsTest { + + @Test + public void testDeprecatedCtor() { + // just to make UT coverage 100% + FileContents o = new FileContents("filename.java", new String[]{"1", "2"}); + o.getFilename(); + } + + @Test + public void testCppCommentNotIntersect() { + // just to make UT coverage 100% + FileContents o = new FileContents( + FileText.fromLines(new File("filename"), Arrays.asList(" // "))); + o.reportCppComment(1,2); + assertFalse(o.hasIntersectionWithComment(1, 0, 1, 1)); + } + + @Test + public void testCppCommentIntersect() { + // just to make UT coverage 100% + FileContents o = new FileContents( + FileText.fromLines(new File("filename"), Arrays.asList(" // "))); + o.reportCppComment(1, 2); + assertTrue(o.hasIntersectionWithComment(1, 5, 1, 6)); + + } +}