Search in sources :

Example 1 with SourceFileCoverageImpl

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

the class BundleCheckerTest method createBundle.

private IBundleCoverage createBundle() {
    final MethodCoverageImpl m = new MethodCoverageImpl("fooMethod", "()V", null);
    m.increment(CounterImpl.getInstance(5, 5), CounterImpl.COUNTER_0_0, 1);
    m.incrementMethodCounter();
    final ClassCoverageImpl c = new ClassCoverageImpl("org/jacoco/example/FooClass", 1001, false);
    c.setSourceFileName("FooClass.java");
    c.addMethod(m);
    final SourceFileCoverageImpl s = new SourceFileCoverageImpl("FooClass.java", "org/jacoco/example");
    s.increment(c);
    IPackageCoverage p = new PackageCoverageImpl("org/jacoco/example", Collections.singleton((IClassCoverage) c), Collections.singleton((ISourceFileCoverage) s));
    return new BundleCoverageImpl("Test", Collections.singleton(p));
}
Also used : IPackageCoverage(org.jacoco.core.analysis.IPackageCoverage) PackageCoverageImpl(org.jacoco.core.internal.analysis.PackageCoverageImpl) IClassCoverage(org.jacoco.core.analysis.IClassCoverage) ISourceFileCoverage(org.jacoco.core.analysis.ISourceFileCoverage) BundleCoverageImpl(org.jacoco.core.internal.analysis.BundleCoverageImpl) ClassCoverageImpl(org.jacoco.core.internal.analysis.ClassCoverageImpl) MethodCoverageImpl(org.jacoco.core.internal.analysis.MethodCoverageImpl) SourceFileCoverageImpl(org.jacoco.core.internal.analysis.SourceFileCoverageImpl)

Example 2 with SourceFileCoverageImpl

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

the class SourceFilePageTest method testContents.

@Test
public void testContents() throws Exception {
    final SourceFileCoverageImpl node = new SourceFileCoverageImpl("SourceFilePageTest.java", "org/jacoco/report/internal/html");
    final SourceFilePage page = new SourceFilePage(node, sourceReader, 4, null, rootFolder, context);
    page.render();
    final Document result = support.parse(output.getFile("SourceFilePageTest.java.html"));
    // additional style sheet
    assertEquals("jacoco-resources/report.css", support.findStr(result, "/html/head/link[@rel='stylesheet'][1]/@href"));
    assertEquals("jacoco-resources/prettify.css", support.findStr(result, "/html/head/link[@rel='stylesheet'][2]/@href"));
    // highlighting script
    assertEquals("text/javascript", support.findStr(result, "/html/head/script/@type"));
    assertEquals("jacoco-resources/prettify.js", support.findStr(result, "/html/head/script/@src"));
    assertEquals("window['PR_TAB_WIDTH']=4;prettyPrint()", support.findStr(result, "/html/body/@onload"));
    // source code
    assertNotNull(support.findStr(result, "/html/body/pre"));
}
Also used : Document(org.w3c.dom.Document) SourceFileCoverageImpl(org.jacoco.core.internal.analysis.SourceFileCoverageImpl) Test(org.junit.Test)

Example 3 with SourceFileCoverageImpl

use of org.jacoco.core.internal.analysis.SourceFileCoverageImpl 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 4 with SourceFileCoverageImpl

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

the class PackageSourcePageTest method setup.

@Before
@Override
public void setup() throws Exception {
    super.setup();
    ISourceFileCoverage src1 = new SourceFileCoverageImpl("Src1.java", "org/jacoco/example");
    ISourceFileCoverage src2 = new SourceFileCoverageImpl("Src2.java", "org/jacoco/example");
    node = new PackageCoverageImpl("org/jacoco/example", Collections.<IClassCoverage>emptyList(), Arrays.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) ISourceFileCoverage(org.jacoco.core.analysis.ISourceFileCoverage) PackageCoverageImpl(org.jacoco.core.internal.analysis.PackageCoverageImpl) IClassCoverage(org.jacoco.core.analysis.IClassCoverage) 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)

Example 5 with SourceFileCoverageImpl

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

the class CoverageBuilder method getSourceFile.

private SourceFileCoverageImpl getSourceFile(final String filename, final String packagename) {
    final String key = packagename + '/' + filename;
    SourceFileCoverageImpl sourcefile = (SourceFileCoverageImpl) sourcefiles.get(key);
    if (sourcefile == null) {
        sourcefile = new SourceFileCoverageImpl(filename, packagename);
        sourcefiles.put(key, sourcefile);
    }
    return sourcefile;
}
Also used : SourceFileCoverageImpl(org.jacoco.core.internal.analysis.SourceFileCoverageImpl)

Aggregations

SourceFileCoverageImpl (org.jacoco.core.internal.analysis.SourceFileCoverageImpl)6 IClassCoverage (org.jacoco.core.analysis.IClassCoverage)3 ISourceFileCoverage (org.jacoco.core.analysis.ISourceFileCoverage)3 PackageCoverageImpl (org.jacoco.core.internal.analysis.PackageCoverageImpl)3 ClassCoverageImpl (org.jacoco.core.internal.analysis.ClassCoverageImpl)2 Test (org.junit.Test)2 Document (org.w3c.dom.Document)2 IOException (java.io.IOException)1 Reader (java.io.Reader)1 StringReader (java.io.StringReader)1 IPackageCoverage (org.jacoco.core.analysis.IPackageCoverage)1 BundleCoverageImpl (org.jacoco.core.internal.analysis.BundleCoverageImpl)1 MethodCoverageImpl (org.jacoco.core.internal.analysis.MethodCoverageImpl)1 ISourceFileLocator (org.jacoco.report.ISourceFileLocator)1 ReportOutputFolder (org.jacoco.report.internal.ReportOutputFolder)1 ILinkable (org.jacoco.report.internal.html.ILinkable)1 Before (org.junit.Before)1