package com.puppycrawl.tools.checkstyle.api; import static org.junit.Assert.*; import java.io.File; import java.util.Arrays; import java.util.List; import org.junit.Test; public class TestFileContents { List list1 = Arrays.asList(new String[]{ "", "//comment", "/**JavaDoc*/", "public class Test{", "}", "/* multiline", "comment*/", "/*test*/", "" }); String fname = "Test.java"; FileText ft = FileText.fromLines(new File(fname), list1); @Test public void test(){ FileContents fc = new FileContents(ft); fc.reportSingleLineComment(null, 1, 0); fc.reportBlockComment(null, 5, 0, 6, 8); fc.reportCComment(2, 0, 2, 8); FileContents fc2 = new FileContents(fname, list1.toArray(new String[]{})); assertEquals(fc.getLines().length, fc2.getLines().length); assertEquals(fc.getFilename(), fc2.getFilename()); assertNotNull(fc.getText()); assertTrue(fc.lineIsBlank(0)); assertTrue(fc.lineIsComment(1)); assertFalse(fc.lineIsComment(3)); assertFalse(fc.inPackageInfo()); assertTrue(fc.lineIsBlank(8)); assertTrue(fc.getCppComments().size() > 0); assertTrue(fc.getCComments().size() > 0); assertNull(fc.getJavadocBefore(3)); } }