Search in sources :

Example 16 with IClassCoverage

use of org.jacoco.core.analysis.IClassCoverage 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 17 with IClassCoverage

use of org.jacoco.core.analysis.IClassCoverage 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 18 with IClassCoverage

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

the class CyclomaticComplexityTest method analyze.

private ICounter analyze() throws IOException {
    final CoverageBuilder builder = new CoverageBuilder();
    final ExecutionDataStore store = new ExecutionDataStore();
    data.collect(store, new SessionInfoStore(), false);
    final Analyzer analyzer = new Analyzer(store, builder);
    analyzer.analyzeClass(bytes, "TestTarget");
    final Collection<IClassCoverage> classes = builder.getClasses();
    assertEquals(1, classes.size(), 0.0);
    final IClassCoverage classCoverage = classes.iterator().next();
    for (final IMethodCoverage m : classCoverage.getMethods()) {
        if (m.getName().equals("test")) {
            return m.getComplexityCounter();
        }
    }
    throw new AssertionError("No test() method.");
}
Also used : IMethodCoverage(org.jacoco.core.analysis.IMethodCoverage) ExecutionDataStore(org.jacoco.core.data.ExecutionDataStore) IClassCoverage(org.jacoco.core.analysis.IClassCoverage) CoverageBuilder(org.jacoco.core.analysis.CoverageBuilder) Analyzer(org.jacoco.core.analysis.Analyzer) SessionInfoStore(org.jacoco.core.data.SessionInfoStore)

Example 19 with IClassCoverage

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

the class PackagePage method renderClasses.

private void renderClasses() throws IOException {
    for (final IClassCoverage c : getNode().getClasses()) {
        final ILinkable sourceFilePage = packageSourcePage.getSourceFilePage(c.getSourceFileName());
        final ClassPage page = new ClassPage(c, this, sourceFilePage, folder, context);
        page.render();
        addItem(page);
    }
}
Also used : IClassCoverage(org.jacoco.core.analysis.IClassCoverage) ILinkable(org.jacoco.report.internal.html.ILinkable)

Example 20 with IClassCoverage

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

the class XMLCoverageWriter method writePackage.

private static void writePackage(final IPackageCoverage p, final XMLElement parent) throws IOException {
    final XMLElement element = createChild(parent, "package", p.getName());
    for (final IClassCoverage c : p.getClasses()) {
        writeClass(c, element);
    }
    for (final ISourceFileCoverage s : p.getSourceFiles()) {
        writeSourceFile(s, element);
    }
    writeCounters(p, element);
}
Also used : IClassCoverage(org.jacoco.core.analysis.IClassCoverage) ISourceFileCoverage(org.jacoco.core.analysis.ISourceFileCoverage)

Aggregations

IClassCoverage (org.jacoco.core.analysis.IClassCoverage)20 ISourceFileCoverage (org.jacoco.core.analysis.ISourceFileCoverage)11 Test (org.junit.Test)7 IPackageCoverage (org.jacoco.core.analysis.IPackageCoverage)5 ClassCoverageImpl (org.jacoco.core.internal.analysis.ClassCoverageImpl)5 PackageCoverageImpl (org.jacoco.core.internal.analysis.PackageCoverageImpl)4 Analyzer (org.jacoco.core.analysis.Analyzer)3 IMethodCoverage (org.jacoco.core.analysis.IMethodCoverage)3 ExecutionDataStore (org.jacoco.core.data.ExecutionDataStore)3 SourceFileCoverageImpl (org.jacoco.core.internal.analysis.SourceFileCoverageImpl)3 Collection (java.util.Collection)2 CoverageBuilder (org.jacoco.core.analysis.CoverageBuilder)2 SessionInfoStore (org.jacoco.core.data.SessionInfoStore)2 ISourceFileLocator (org.jacoco.report.ISourceFileLocator)2 ILinkable (org.jacoco.report.internal.html.ILinkable)2 Document (org.w3c.dom.Document)2 BufferedReader (java.io.BufferedReader)1 FileWriter (java.io.FileWriter)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1