Search in sources :

Example 6 with MethodCoverageImpl

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());
}
Also used : MethodCoverageImpl(org.jacoco.core.internal.analysis.MethodCoverageImpl) Test(org.junit.Test)

Example 7 with MethodCoverageImpl

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);
}
Also used : ClassCoverageImpl(org.jacoco.core.internal.analysis.ClassCoverageImpl) MethodCoverageImpl(org.jacoco.core.internal.analysis.MethodCoverageImpl)

Example 8 with MethodCoverageImpl

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());
}
Also used : MethodCoverageImpl(org.jacoco.core.internal.analysis.MethodCoverageImpl) Test(org.junit.Test)

Example 9 with MethodCoverageImpl

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()));
}
Also used : HashMap(java.util.HashMap) MethodCoverageImpl(org.jacoco.core.internal.analysis.MethodCoverageImpl) Test(org.junit.Test)

Example 10 with MethodCoverageImpl

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());
}
Also used : MethodCoverageImpl(org.jacoco.core.internal.analysis.MethodCoverageImpl) Test(org.junit.Test)

Aggregations

MethodCoverageImpl (org.jacoco.core.internal.analysis.MethodCoverageImpl)19 Test (org.junit.Test)16 ClassCoverageImpl (org.jacoco.core.internal.analysis.ClassCoverageImpl)10 Document (org.w3c.dom.Document)7 PackageCoverageImpl (org.jacoco.core.internal.analysis.PackageCoverageImpl)5 IClassCoverage (org.jacoco.core.analysis.IClassCoverage)4 ISourceFileCoverage (org.jacoco.core.analysis.ISourceFileCoverage)4 IPackageCoverage (org.jacoco.core.analysis.IPackageCoverage)2 BundleCoverageImpl (org.jacoco.core.internal.analysis.BundleCoverageImpl)2 SourceFileCoverageImpl (org.jacoco.core.internal.analysis.SourceFileCoverageImpl)2 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 IBundleCoverage (org.jacoco.core.analysis.IBundleCoverage)1 Before (org.junit.Before)1