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());
}
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());
}
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;
}
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));
}
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);
}
}
}
Aggregations