Search in sources :

Example 6 with ClassCoverageImpl

use of org.jacoco.core.internal.analysis.ClassCoverageImpl in project jacoco by jacoco.

the class PackagePageTest method testContentsWithSource.

@Test
public void testContentsWithSource() throws Exception {
    IClassCoverage class1 = new ClassCoverageImpl("org/jacoco/example/Foo1", 0x1000, false);
    IClassCoverage class2 = new ClassCoverageImpl("org/jacoco/example/Foo2", 0x2000, false);
    ISourceFileCoverage src1 = new SourceFileCoverageImpl("Src1.java", "org/jacoco/example");
    node = new PackageCoverageImpl("org/jacoco/example", Arrays.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 : IClassCoverage(org.jacoco.core.analysis.IClassCoverage) ISourceFileCoverage(org.jacoco.core.analysis.ISourceFileCoverage) PackageCoverageImpl(org.jacoco.core.internal.analysis.PackageCoverageImpl) ClassCoverageImpl(org.jacoco.core.internal.analysis.ClassCoverageImpl) Document(org.w3c.dom.Document) SourceFileCoverageImpl(org.jacoco.core.internal.analysis.SourceFileCoverageImpl) Test(org.junit.Test)

Example 7 with ClassCoverageImpl

use of org.jacoco.core.internal.analysis.ClassCoverageImpl in project jacoco by jacoco.

the class PackagePageTest method testContentsNoSource.

@Test
public void testContentsNoSource() throws Exception {
    IClassCoverage class1 = new ClassCoverageImpl("org/jacoco/example/Foo1", 0x1000, false);
    IClassCoverage class2 = new ClassCoverageImpl("org/jacoco/example/Foo2", 0x2000, false);
    node = new PackageCoverageImpl("org/jacoco/example", Arrays.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 : IClassCoverage(org.jacoco.core.analysis.IClassCoverage) PackageCoverageImpl(org.jacoco.core.internal.analysis.PackageCoverageImpl) ISourceFileCoverage(org.jacoco.core.analysis.ISourceFileCoverage) ClassCoverageImpl(org.jacoco.core.internal.analysis.ClassCoverageImpl) Document(org.w3c.dom.Document) Test(org.junit.Test)

Example 8 with ClassCoverageImpl

use of org.jacoco.core.internal.analysis.ClassCoverageImpl in project jacoco by jacoco.

the class Analyzer method createAnalyzingVisitor.

/**
 * Creates an ASM class visitor for analysis.
 *
 * @param classid
 *            id of the class calculated with {@link CRC64}
 * @param className
 *            VM name of the class
 * @return ASM visitor to write class definition to
 */
private ClassVisitor createAnalyzingVisitor(final long classid, final String className) {
    final ExecutionData data = executionData.get(classid);
    final boolean[] probes;
    final boolean noMatch;
    if (data == null) {
        probes = null;
        noMatch = executionData.contains(className);
    } else {
        probes = data.getProbes();
        noMatch = false;
    }
    final ClassCoverageImpl coverage = new ClassCoverageImpl(className, classid, noMatch);
    final ClassAnalyzer analyzer = new ClassAnalyzer(coverage, probes, stringPool) {

        @Override
        public void visitEnd() {
            super.visitEnd();
            coverageVisitor.visitCoverage(coverage);
        }
    };
    return new ClassProbesAdapter(analyzer, false);
}
Also used : ClassAnalyzer(org.jacoco.core.internal.analysis.ClassAnalyzer) ClassCoverageImpl(org.jacoco.core.internal.analysis.ClassCoverageImpl) ClassProbesAdapter(org.jacoco.core.internal.flow.ClassProbesAdapter) ExecutionData(org.jacoco.core.data.ExecutionData)

Aggregations

ClassCoverageImpl (org.jacoco.core.internal.analysis.ClassCoverageImpl)8 IClassCoverage (org.jacoco.core.analysis.IClassCoverage)5 Test (org.junit.Test)4 ISourceFileCoverage (org.jacoco.core.analysis.ISourceFileCoverage)3 MethodCoverageImpl (org.jacoco.core.internal.analysis.MethodCoverageImpl)3 PackageCoverageImpl (org.jacoco.core.internal.analysis.PackageCoverageImpl)3 SourceFileCoverageImpl (org.jacoco.core.internal.analysis.SourceFileCoverageImpl)2 Document (org.w3c.dom.Document)2 BufferedReader (java.io.BufferedReader)1 IPackageCoverage (org.jacoco.core.analysis.IPackageCoverage)1 ExecutionData (org.jacoco.core.data.ExecutionData)1 BundleCoverageImpl (org.jacoco.core.internal.analysis.BundleCoverageImpl)1 ClassAnalyzer (org.jacoco.core.internal.analysis.ClassAnalyzer)1 ClassProbesAdapter (org.jacoco.core.internal.flow.ClassProbesAdapter)1 Before (org.junit.Before)1