Search in sources :

Example 1 with IPackageCoverage

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

the class BundleCoverageImplTest method testCounters.

@Test
public void testCounters() {
    Collection<IClassCoverage> classes = Collections.emptySet();
    Collection<ISourceFileCoverage> sourcefiles = Collections.emptySet();
    final IPackageCoverage p1 = new PackageCoverageImpl("p1", classes, sourcefiles) {

        {
            classCounter = CounterImpl.getInstance(1, 0);
            methodCounter = CounterImpl.getInstance(2, 0);
            branchCounter = CounterImpl.getInstance(3, 0);
            instructionCounter = CounterImpl.getInstance(4, 0);
            lineCounter = CounterImpl.getInstance(5, 0);
        }
    };
    final IPackageCoverage p2 = new PackageCoverageImpl("p1", classes, sourcefiles) {

        {
            classCounter = CounterImpl.getInstance(1, 0);
            methodCounter = CounterImpl.getInstance(2, 0);
            branchCounter = CounterImpl.getInstance(3, 0);
            instructionCounter = CounterImpl.getInstance(4, 0);
            lineCounter = CounterImpl.getInstance(5, 0);
        }
    };
    BundleCoverageImpl bundle = new BundleCoverageImpl("testbundle", Arrays.asList(p1, p2));
    assertEquals(CounterImpl.getInstance(2, 0), bundle.getClassCounter());
    assertEquals(CounterImpl.getInstance(4, 0), bundle.getMethodCounter());
    assertEquals(CounterImpl.getInstance(6, 0), bundle.getBranchCounter());
    assertEquals(CounterImpl.getInstance(8, 0), bundle.getInstructionCounter());
    assertEquals(CounterImpl.getInstance(10, 0), bundle.getLineCounter());
}
Also used : IPackageCoverage(org.jacoco.core.analysis.IPackageCoverage) IClassCoverage(org.jacoco.core.analysis.IClassCoverage) ISourceFileCoverage(org.jacoco.core.analysis.ISourceFileCoverage) Test(org.junit.Test)

Example 2 with IPackageCoverage

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

the class BundleCoverageImplTest method testGroupByPackage.

@Test
public void testGroupByPackage() {
    ClassCoverageImpl ca = new ClassCoverageImpl("p1/A", 1, false);
    ca.setSourceFileName("A.java");
    ClassCoverageImpl cb = new ClassCoverageImpl("p2/B", 2, false);
    cb.setSourceFileName("B.java");
    ISourceFileCoverage sb = new SourceFileCoverageImpl("B.java", "p2");
    ISourceFileCoverage sc = new SourceFileCoverageImpl("C.java", "p3");
    BundleCoverageImpl bundle = new BundleCoverageImpl("bundle", Arrays.asList((IClassCoverage) ca, (IClassCoverage) cb), Arrays.asList(sb, sc));
    Collection<IPackageCoverage> packages = bundle.getPackages();
    assertEquals(3, packages.size(), 0.0);
    IPackageCoverage p1 = findPackage("p1", packages);
    assertNotNull(p1);
    assertEquals(Collections.singletonList(ca), p1.getClasses());
    assertTrue(p1.getSourceFiles().isEmpty());
    IPackageCoverage p2 = findPackage("p2", packages);
    assertNotNull(p2);
    assertEquals(Collections.singletonList(cb), p2.getClasses());
    assertEquals(Collections.singletonList(sb), p2.getSourceFiles());
    IPackageCoverage p3 = findPackage("p3", packages);
    assertNotNull(p3);
    assertTrue(p3.getClasses().isEmpty());
    assertEquals(Collections.singletonList(sc), p3.getSourceFiles());
}
Also used : IPackageCoverage(org.jacoco.core.analysis.IPackageCoverage) ISourceFileCoverage(org.jacoco.core.analysis.ISourceFileCoverage) IClassCoverage(org.jacoco.core.analysis.IClassCoverage) Test(org.junit.Test)

Example 3 with IPackageCoverage

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

the class BundleCoverageImpl method groupByPackage.

private static Collection<IPackageCoverage> groupByPackage(final Collection<IClassCoverage> classes, final Collection<ISourceFileCoverage> sourcefiles) {
    final Map<String, Collection<IClassCoverage>> classesByPackage = new HashMap<String, Collection<IClassCoverage>>();
    for (final IClassCoverage c : classes) {
        addByName(classesByPackage, c.getPackageName(), c);
    }
    final Map<String, Collection<ISourceFileCoverage>> sourceFilesByPackage = new HashMap<String, Collection<ISourceFileCoverage>>();
    for (final ISourceFileCoverage s : sourcefiles) {
        addByName(sourceFilesByPackage, s.getPackageName(), s);
    }
    final Set<String> packageNames = new HashSet<String>();
    packageNames.addAll(classesByPackage.keySet());
    packageNames.addAll(sourceFilesByPackage.keySet());
    final Collection<IPackageCoverage> result = new ArrayList<IPackageCoverage>();
    for (final String name : packageNames) {
        Collection<IClassCoverage> c = classesByPackage.get(name);
        if (c == null) {
            c = Collections.emptyList();
        }
        Collection<ISourceFileCoverage> s = sourceFilesByPackage.get(name);
        if (s == null) {
            s = Collections.emptyList();
        }
        result.add(new PackageCoverageImpl(name, c, s));
    }
    return result;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) IPackageCoverage(org.jacoco.core.analysis.IPackageCoverage) IClassCoverage(org.jacoco.core.analysis.IClassCoverage) ISourceFileCoverage(org.jacoco.core.analysis.ISourceFileCoverage) Collection(java.util.Collection) HashSet(java.util.HashSet)

Example 4 with IPackageCoverage

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

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

the class BundleChecker method checkBundle.

public void checkBundle(final IBundleCoverage bundleCoverage) {
    final String name = bundleCoverage.getName();
    checkRules(bundleCoverage, bundleRules, "bundle", name);
    if (traversePackages) {
        for (final IPackageCoverage p : bundleCoverage.getPackages()) {
            check(p);
        }
    }
}
Also used : IPackageCoverage(org.jacoco.core.analysis.IPackageCoverage)

Aggregations

IPackageCoverage (org.jacoco.core.analysis.IPackageCoverage)7 IClassCoverage (org.jacoco.core.analysis.IClassCoverage)5 ISourceFileCoverage (org.jacoco.core.analysis.ISourceFileCoverage)5 Collection (java.util.Collection)2 Test (org.junit.Test)2 FileWriter (java.io.FileWriter)1 PrintWriter (java.io.PrintWriter)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1 TreeMap (java.util.TreeMap)1 IBundleCoverage (org.jacoco.core.analysis.IBundleCoverage)1 ICounter (org.jacoco.core.analysis.ICounter)1 IMethodCoverage (org.jacoco.core.analysis.IMethodCoverage)1 BundleCoverageImpl (org.jacoco.core.internal.analysis.BundleCoverageImpl)1 ClassCoverageImpl (org.jacoco.core.internal.analysis.ClassCoverageImpl)1 MethodCoverageImpl (org.jacoco.core.internal.analysis.MethodCoverageImpl)1 PackageCoverageImpl (org.jacoco.core.internal.analysis.PackageCoverageImpl)1