use of org.jacoco.core.internal.analysis.MethodCoverageImpl in project jacoco by jacoco.
the class CoverageBuilderTest method testCreateClassMissed.
@Test
public void testCreateClassMissed() {
final MethodCoverageImpl method = new MethodCoverageImpl("doit", "()V", null);
method.increment(CounterImpl.COUNTER_1_0, CounterImpl.COUNTER_0_0, 6);
method.increment(CounterImpl.COUNTER_1_0, CounterImpl.COUNTER_0_0, 7);
method.increment(CounterImpl.COUNTER_1_0, CounterImpl.COUNTER_0_0, 8);
method.incrementMethodCounter();
addClass(123L, false, "Sample", null, method);
final Collection<IClassCoverage> classes = coverageBuilder.getClasses();
assertEquals(1, classes.size());
IClassCoverage c = classes.iterator().next();
assertEquals("Sample", c.getName());
assertEquals(1, c.getClassCounter().getTotalCount());
assertEquals(0, c.getClassCounter().getCoveredCount());
assertEquals(1, c.getMethodCounter().getTotalCount());
assertEquals(0, c.getMethodCounter().getCoveredCount());
assertEquals(3, c.getLineCounter().getTotalCount());
assertEquals(0, c.getLineCounter().getCoveredCount());
final Collection<IMethodCoverage> methods = c.getMethods();
assertEquals(1, methods.size());
IMethodCoverage m = methods.iterator().next();
assertEquals("doit", m.getName());
assertEquals("()V", m.getDesc());
assertEquals(1, m.getMethodCounter().getTotalCount());
assertEquals(0, m.getMethodCounter().getCoveredCount());
assertEquals(3, m.getLineCounter().getTotalCount());
assertEquals(0, m.getLineCounter().getCoveredCount());
}
use of org.jacoco.core.internal.analysis.MethodCoverageImpl in project jacoco by jacoco.
the class CoverageBuilderTest method addClass.
private void addClass(long id, boolean nomatch, String name, String source, MethodCoverageImpl... methods) {
final ClassCoverageImpl coverage = new ClassCoverageImpl(name, id, nomatch);
coverage.setSourceFileName(source);
for (MethodCoverageImpl m : methods) {
coverage.addMethod(m);
}
coverageBuilder.visitCoverage(coverage);
}
use of org.jacoco.core.internal.analysis.MethodCoverageImpl in project jacoco by jacoco.
the class CoverageBuilderTest method testCreateSourceFileDuplicateClassNameIdentical.
@Test
public void testCreateSourceFileDuplicateClassNameIdentical() {
final MethodCoverageImpl method1 = new MethodCoverageImpl("doit", "()V", null);
method1.increment(CounterImpl.COUNTER_1_0, CounterImpl.COUNTER_0_0, 3);
addClass(123L, false, "Sample", "Sample.java", method1);
final MethodCoverageImpl method2 = new MethodCoverageImpl("doit", "()V", null);
method2.increment(CounterImpl.COUNTER_1_0, CounterImpl.COUNTER_0_0, 3);
addClass(123L, false, "Sample", "Sample.java", method2);
final Collection<ISourceFileCoverage> sourcefiles = coverageBuilder.getSourceFiles();
assertEquals(1, sourcefiles.size());
ISourceFileCoverage s = sourcefiles.iterator().next();
assertEquals(1, s.getClassCounter().getTotalCount());
assertEquals(0, s.getClassCounter().getCoveredCount());
}
use of org.jacoco.core.internal.analysis.MethodCoverageImpl in project jacoco by jacoco.
the class CoverageBuilderTest method testGetBundle.
@Test
public void testGetBundle() {
final MethodCoverageImpl method1 = new MethodCoverageImpl("doit", "()V", null);
method1.increment(CounterImpl.COUNTER_1_0, CounterImpl.COUNTER_0_0, 3);
addClass(1, false, "org/jacoco/examples/Sample1", null, method1);
final MethodCoverageImpl method2 = new MethodCoverageImpl("doit", "()V", null);
method2.increment(CounterImpl.COUNTER_1_0, CounterImpl.COUNTER_0_0, 6);
addClass(2, false, "org/jacoco/examples/Sample2", null, method2);
final MethodCoverageImpl method3 = new MethodCoverageImpl("doit", "()V", null);
method3.increment(CounterImpl.COUNTER_1_0, CounterImpl.COUNTER_0_0, 1);
addClass(3, false, "Sample3", null, method3);
IBundleCoverage bundle = coverageBuilder.getBundle("testbundle");
assertEquals("testbundle", bundle.getName());
final Collection<IPackageCoverage> packages = bundle.getPackages();
assertEquals(2, packages.size());
Map<String, IPackageCoverage> packagesByName = new HashMap<String, IPackageCoverage>();
for (IPackageCoverage p : packages) {
packagesByName.put(p.getName(), p);
}
IPackageCoverage p1 = packagesByName.get("org/jacoco/examples");
assertNotNull(p1);
assertEquals(new HashSet<String>(Arrays.asList("org/jacoco/examples/Sample1", "org/jacoco/examples/Sample2")), getNames(p1.getClasses()));
IPackageCoverage p2 = packagesByName.get("");
assertNotNull(p2);
assertEquals(Collections.singleton("Sample3"), getNames(p2.getClasses()));
}
use of org.jacoco.core.internal.analysis.MethodCoverageImpl in project jacoco by jacoco.
the class CoverageBuilderTest method testIgnoreClassesWithoutCode.
@Test
public void testIgnoreClassesWithoutCode() {
final MethodCoverageImpl method = new MethodCoverageImpl("doit", "()V", null);
addClass(123L, false, "Sample", null, method);
final Collection<IClassCoverage> classes = coverageBuilder.getClasses();
assertTrue(classes.isEmpty());
}
Aggregations