Search in sources :

Example 6 with IClassCoverage

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

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

the class ClassRowWriterTest method TestRow.

@Test
public void TestRow() throws Exception {
    IClassCoverage node = new ClassCoverageImpl("test/package/Foo", 123, false) {

        {
            instructionCounter = CounterImpl.getInstance(1, 11);
            branchCounter = CounterImpl.getInstance(2, 22);
            lineCounter = CounterImpl.getInstance(3, 33);
            complexityCounter = CounterImpl.getInstance(4, 44);
            methodCounter = CounterImpl.getInstance(5, 55);
            classCounter = CounterImpl.getInstance(6, 66);
        }
    };
    writer.writeRow("group", "test/package", node);
    BufferedReader reader = getResultReader();
    reader.readLine();
    assertEquals("group,test/package,test/package/Foo,1,11,2,22,3,33,4,44,5,55", reader.readLine());
}
Also used : IClassCoverage(org.jacoco.core.analysis.IClassCoverage) ClassCoverageImpl(org.jacoco.core.internal.analysis.ClassCoverageImpl) BufferedReader(java.io.BufferedReader) Test(org.junit.Test)

Example 8 with IClassCoverage

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

the class AnalysisTimeScenario method getInstrumentedCallable.

@Override
protected Callable<Void> getInstrumentedCallable() throws Exception {
    final byte[] bytes = TargetLoader.getClassDataAsBytes(target);
    final ExecutionDataStore executionData = new ExecutionDataStore();
    ICoverageVisitor visitor = new ICoverageVisitor() {

        public void visitCoverage(IClassCoverage coverage) {
        }
    };
    final Analyzer analyzer = new Analyzer(executionData, visitor);
    return new Callable<Void>() {

        public Void call() throws Exception {
            for (int i = 0; i < count; i++) {
                analyzer.analyzeClass(bytes, target.getName());
            }
            return null;
        }
    };
}
Also used : ExecutionDataStore(org.jacoco.core.data.ExecutionDataStore) IClassCoverage(org.jacoco.core.analysis.IClassCoverage) Analyzer(org.jacoco.core.analysis.Analyzer) ICoverageVisitor(org.jacoco.core.analysis.ICoverageVisitor) Callable(java.util.concurrent.Callable)

Example 9 with IClassCoverage

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

the class BundleChecker method check.

private void check(final IPackageCoverage packageCoverage) {
    final String name = names.getPackageName(packageCoverage.getName());
    checkRules(packageCoverage, packageRules, "package", name);
    if (traverseClasses) {
        for (final IClassCoverage c : packageCoverage.getClasses()) {
            check(c);
        }
    }
    if (traverseSourceFiles) {
        for (final ISourceFileCoverage s : packageCoverage.getSourceFiles()) {
            check(s);
        }
    }
}
Also used : IClassCoverage(org.jacoco.core.analysis.IClassCoverage) ISourceFileCoverage(org.jacoco.core.analysis.ISourceFileCoverage)

Example 10 with IClassCoverage

use of org.jacoco.core.analysis.IClassCoverage in project sonar-java by SonarSource.

the class JacocoReportReader method logNoMatchClasses.

private static void logNoMatchClasses(Collection<IClassCoverage> noMatchClasses) {
    if (noMatchClasses.isEmpty()) {
        return;
    }
    LOG.warn("The following class(es) did not match with execution data:");
    for (IClassCoverage iClassCoverage : noMatchClasses) {
        LOG.warn(String.format("> '%s'", iClassCoverage.getName()));
    }
    LOG.warn("In order to have accurate coverage measures, the same class files must be used as at runtime for report generation.");
}
Also used : IClassCoverage(org.jacoco.core.analysis.IClassCoverage)

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