Search in sources :

Example 16 with ISourceFileCoverage

use of org.jacoco.core.analysis.ISourceFileCoverage in project jacoco by jacoco.

the class PackagePageTest method testContentsWithSource.

@Test
public void testContentsWithSource() throws Exception {
    ClassCoverageImpl class1 = new ClassCoverageImpl("org/jacoco/example/Foo1", 0x1000, false);
    MethodCoverageImpl method1 = new MethodCoverageImpl("m", "()V", null);
    method1.increment(CounterImpl.COUNTER_1_0, CounterImpl.COUNTER_0_0, 42);
    class1.addMethod(method1);
    ClassCoverageImpl class2 = new ClassCoverageImpl("org/jacoco/example/Foo2", 0x2000, false);
    MethodCoverageImpl method2 = new MethodCoverageImpl("m", "()V", null);
    method2.increment(CounterImpl.COUNTER_1_0, CounterImpl.COUNTER_0_0, 42);
    class2.addMethod(method2);
    ISourceFileCoverage src1 = new SourceFileCoverageImpl("Src1.java", "org/jacoco/example");
    node = new PackageCoverageImpl("org/jacoco/example", Arrays.<IClassCoverage>asList(class1, class2), Arrays.asList(src1));
    page = new PackagePage(node, null, sourceLocator, rootFolder, context);
    page.render();
    final Document doc = support.parse(output.getFile("index.html"));
    // Expect "Source Files" links
    assertEquals("index.source.html", support.findStr(doc, "/html/body/div[1]/span[1]/a/@href"));
    assertEquals("el_source", support.findStr(doc, "/html/body/div[1]/span[1]/a/@class"));
    assertEquals("Source Files", support.findStr(doc, "/html/body/div[1]/span[1]/a"));
    assertEquals("el_class", support.findStr(doc, "/html/body/table[1]/tbody/tr[1]/td[1]/a/@class"));
    assertEquals("Foo1", support.findStr(doc, "/html/body/table[1]/tbody/tr[1]/td[1]/a"));
    assertEquals("el_class", support.findStr(doc, "/html/body/table[1]/tbody/tr[2]/td[1]/a/@class"));
    assertEquals("Foo2", support.findStr(doc, "/html/body/table[1]/tbody/tr[2]/td[1]/a"));
    output.assertFile("index.source.html");
}
Also used : ISourceFileCoverage(org.jacoco.core.analysis.ISourceFileCoverage) PackageCoverageImpl(org.jacoco.core.internal.analysis.PackageCoverageImpl) IClassCoverage(org.jacoco.core.analysis.IClassCoverage) ClassCoverageImpl(org.jacoco.core.internal.analysis.ClassCoverageImpl) MethodCoverageImpl(org.jacoco.core.internal.analysis.MethodCoverageImpl) Document(org.w3c.dom.Document) SourceFileCoverageImpl(org.jacoco.core.internal.analysis.SourceFileCoverageImpl) Test(org.junit.Test)

Example 17 with ISourceFileCoverage

use of org.jacoco.core.analysis.ISourceFileCoverage in project jacoco by jacoco.

the class PackagePageTest method testContentsNoSource.

@Test
public void testContentsNoSource() throws Exception {
    ClassCoverageImpl class1 = new ClassCoverageImpl("org/jacoco/example/Foo1", 0x1000, false);
    MethodCoverageImpl method1 = new MethodCoverageImpl("m", "()V", null);
    method1.increment(CounterImpl.COUNTER_1_0, CounterImpl.COUNTER_0_0, 42);
    class1.addMethod(method1);
    ClassCoverageImpl class2 = new ClassCoverageImpl("org/jacoco/example/Foo2", 0x2000, false);
    MethodCoverageImpl method2 = new MethodCoverageImpl("m", "()V", null);
    method2.increment(CounterImpl.COUNTER_1_0, CounterImpl.COUNTER_0_0, 42);
    class2.addMethod(method2);
    node = new PackageCoverageImpl("org/jacoco/example", Arrays.<IClassCoverage>asList(class1, class2), Collections.<ISourceFileCoverage>emptyList());
    page = new PackagePage(node, null, sourceLocator, rootFolder, context);
    page.render();
    // Expect no "Source Files" link
    final Document doc = support.parse(output.getFile("index.html"));
    assertEquals("Sessions", support.findStr(doc, "/html/body/div[1]/span[1]/a"));
    // Expect no source files page:
    output.assertNoFile("index.source.html");
}
Also used : PackageCoverageImpl(org.jacoco.core.internal.analysis.PackageCoverageImpl) IClassCoverage(org.jacoco.core.analysis.IClassCoverage) ISourceFileCoverage(org.jacoco.core.analysis.ISourceFileCoverage) ClassCoverageImpl(org.jacoco.core.internal.analysis.ClassCoverageImpl) MethodCoverageImpl(org.jacoco.core.internal.analysis.MethodCoverageImpl) Document(org.w3c.dom.Document) Test(org.junit.Test)

Example 18 with ISourceFileCoverage

use of org.jacoco.core.analysis.ISourceFileCoverage in project jacoco by jacoco.

the class PackageSourcePageTest method setup.

@Before
@Override
public void setup() throws Exception {
    super.setup();
    SourceFileCoverageImpl src1 = new SourceFileCoverageImpl("Src1.java", "org/jacoco/example");
    src1.increment(CounterImpl.COUNTER_1_0, CounterImpl.COUNTER_0_0, 1);
    SourceFileCoverageImpl src2 = new SourceFileCoverageImpl("Src2.java", "org/jacoco/example");
    src2.increment(CounterImpl.COUNTER_1_0, CounterImpl.COUNTER_0_0, 1);
    node = new PackageCoverageImpl("org/jacoco/example", Collections.<IClassCoverage>emptyList(), Arrays.<ISourceFileCoverage>asList(src1, src2));
    sourceLocator = new ISourceFileLocator() {

        public int getTabWidth() {
            return 4;
        }

        public Reader getSourceFile(String packageName, String fileName) throws IOException {
            return fileName.equals("Src1.java") ? new StringReader("") : null;
        }
    };
    packagePageLink = new ILinkable() {

        public String getLinkStyle() {
            fail();
            return null;
        }

        public String getLinkLabel() {
            fail();
            return null;
        }

        public String getLink(ReportOutputFolder base) {
            return "index.html";
        }
    };
}
Also used : ReportOutputFolder(org.jacoco.report.internal.ReportOutputFolder) PackageCoverageImpl(org.jacoco.core.internal.analysis.PackageCoverageImpl) IClassCoverage(org.jacoco.core.analysis.IClassCoverage) ISourceFileCoverage(org.jacoco.core.analysis.ISourceFileCoverage) StringReader(java.io.StringReader) Reader(java.io.Reader) StringReader(java.io.StringReader) IOException(java.io.IOException) ILinkable(org.jacoco.report.internal.html.ILinkable) ISourceFileLocator(org.jacoco.report.ISourceFileLocator) SourceFileCoverageImpl(org.jacoco.core.internal.analysis.SourceFileCoverageImpl) Before(org.junit.Before)

Aggregations

ISourceFileCoverage (org.jacoco.core.analysis.ISourceFileCoverage)18 IClassCoverage (org.jacoco.core.analysis.IClassCoverage)15 Test (org.junit.Test)7 IPackageCoverage (org.jacoco.core.analysis.IPackageCoverage)6 PackageCoverageImpl (org.jacoco.core.internal.analysis.PackageCoverageImpl)6 ClassCoverageImpl (org.jacoco.core.internal.analysis.ClassCoverageImpl)4 MethodCoverageImpl (org.jacoco.core.internal.analysis.MethodCoverageImpl)4 SourceFileCoverageImpl (org.jacoco.core.internal.analysis.SourceFileCoverageImpl)4 Document (org.w3c.dom.Document)4 Reader (java.io.Reader)2 Collection (java.util.Collection)2 CoverageBuilder (org.jacoco.core.analysis.CoverageBuilder)2 ISourceFileLocator (org.jacoco.report.ISourceFileLocator)2 InputFile (org.sonar.api.batch.fs.InputFile)2 File (java.io.File)1 FileWriter (java.io.FileWriter)1 IOException (java.io.IOException)1 PrintWriter (java.io.PrintWriter)1 StringReader (java.io.StringReader)1 ArrayList (java.util.ArrayList)1