100% UTs coverage for FileContents. #1295

This commit is contained in:
Roman Ivanov 2015-07-22 20:52:58 -07:00
parent 82e1d2693c
commit f1b28dbcde
3 changed files with 40 additions and 2 deletions

View File

@ -1088,7 +1088,6 @@
<regex><pattern>.*.api.AuditEvent</pattern><branchRate>100</branchRate><lineRate>93</lineRate></regex>
<regex><pattern>.*.api.AutomaticBean</pattern><branchRate>90</branchRate><lineRate>82</lineRate></regex>
<regex><pattern>.*.api.AutomaticBean\$.*</pattern><branchRate>75</branchRate><lineRate>90</lineRate></regex>
<regex><pattern>.*.api.FileContents</pattern><branchRate>96</branchRate><lineRate>93</lineRate></regex>
<regex><pattern>.*.api.FileText</pattern><branchRate>50</branchRate><lineRate>59</lineRate></regex>
<regex><pattern>.*.api.JavadocTagInfo</pattern><branchRate>25</branchRate><lineRate>77</lineRate></regex>
<regex><pattern>.*.api.JavadocTagInfo\$.*</pattern><branchRate>0</branchRate><lineRate>8</lineRate></regex>

View File

@ -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));
}

View File

@ -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));
}
}