Search in sources :

Example 1 with MethodCoverageImpl

use of org.jacoco.core.internal.analysis.MethodCoverageImpl in project jacoco by jacoco.

the class BundlePageTest method should_render_non_empty_packages.

@Test
public void should_render_non_empty_packages() throws Exception {
    final ClassCoverageImpl classCoverage = new ClassCoverageImpl("example/Class", 0, false);
    final MethodCoverageImpl methodCoverage = new MethodCoverageImpl("m", "()V", null);
    methodCoverage.increment(CounterImpl.COUNTER_1_0, CounterImpl.COUNTER_0_0, 42);
    classCoverage.addMethod(methodCoverage);
    final IPackageCoverage nonEmptyPackage = new PackageCoverageImpl("example", Collections.<IClassCoverage>singleton(classCoverage), Collections.<ISourceFileCoverage>emptySet());
    final IPackageCoverage emptyPackage = new PackageCoverageImpl("empty", Collections.<IClassCoverage>emptySet(), Collections.<ISourceFileCoverage>emptySet());
    final IBundleCoverage node = new BundleCoverageImpl("bundle", Arrays.asList(nonEmptyPackage, emptyPackage));
    final BundlePage page = new BundlePage(node, null, null, rootFolder, context);
    page.render();
    final Document doc = support.parse(output.getFile("index.html"));
    assertEquals("el_package", support.findStr(doc, "/html/body/table[1]/tbody/tr[1]/td[1]/a/@class"));
    assertEquals("example", support.findStr(doc, "/html/body/table[1]/tbody/tr[1]/td[1]/a"));
    assertEquals("1", support.findStr(doc, "count(/html/body/table[1]/tbody/tr)"));
}
Also used : IPackageCoverage(org.jacoco.core.analysis.IPackageCoverage) PackageCoverageImpl(org.jacoco.core.internal.analysis.PackageCoverageImpl) BundleCoverageImpl(org.jacoco.core.internal.analysis.BundleCoverageImpl) ClassCoverageImpl(org.jacoco.core.internal.analysis.ClassCoverageImpl) IBundleCoverage(org.jacoco.core.analysis.IBundleCoverage) MethodCoverageImpl(org.jacoco.core.internal.analysis.MethodCoverageImpl) Document(org.w3c.dom.Document) Test(org.junit.Test)

Example 2 with MethodCoverageImpl

use of org.jacoco.core.internal.analysis.MethodCoverageImpl in project jacoco by jacoco.

the class ClassPageTest method should_generate_message_with_default_package_when_SourceFileName_present_but_no_SourceFilePage.

@Test
public void should_generate_message_with_default_package_when_SourceFileName_present_but_no_SourceFilePage() throws Exception {
    final MethodCoverageImpl m = new MethodCoverageImpl("a", "()V", null);
    m.increment(CounterImpl.COUNTER_1_0, CounterImpl.COUNTER_0_0, 42);
    node = new ClassCoverageImpl("Foo", 123, false);
    node.addMethod(m);
    node.setSourceFileName("Foo.java");
    page = new ClassPage(node, null, null, rootFolder, context);
    page.render();
    final Document doc = support.parse(output.getFile("Foo.html"));
    assertEquals("Source file \"Foo.java\" was not found during generation of report.", support.findStr(doc, "/html/body/p[1]"));
}
Also used : ClassCoverageImpl(org.jacoco.core.internal.analysis.ClassCoverageImpl) MethodCoverageImpl(org.jacoco.core.internal.analysis.MethodCoverageImpl) Document(org.w3c.dom.Document) Test(org.junit.Test)

Example 3 with MethodCoverageImpl

use of org.jacoco.core.internal.analysis.MethodCoverageImpl in project jacoco by jacoco.

the class ClassPageTest method setup.

@Before
@Override
public void setup() throws Exception {
    super.setup();
    final MethodCoverageImpl m = new MethodCoverageImpl("a", "()V", null);
    m.increment(CounterImpl.COUNTER_1_0, CounterImpl.COUNTER_0_0, 42);
    node = new ClassCoverageImpl("org/jacoco/example/Foo", 123, false);
    node.addMethod(m);
    node.addMethod(new MethodCoverageImpl("b", "()V", null));
    node.addMethod(new MethodCoverageImpl("c", "()V", null));
}
Also used : ClassCoverageImpl(org.jacoco.core.internal.analysis.ClassCoverageImpl) MethodCoverageImpl(org.jacoco.core.internal.analysis.MethodCoverageImpl) Before(org.junit.Before)

Example 4 with MethodCoverageImpl

use of org.jacoco.core.internal.analysis.MethodCoverageImpl 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 MethodCoverageImpl

use of org.jacoco.core.internal.analysis.MethodCoverageImpl in project jacoco by jacoco.

the class CoverageBuilderTest method testCreateClassCovered.

@Test
public void testCreateClassCovered() {
    final MethodCoverageImpl method = new MethodCoverageImpl("doit", "()V", null);
    method.increment(CounterImpl.COUNTER_0_1, CounterImpl.COUNTER_0_0, 6);
    method.increment(CounterImpl.COUNTER_0_1, CounterImpl.COUNTER_0_0, 7);
    method.increment(CounterImpl.COUNTER_0_1, 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(1, c.getClassCounter().getCoveredCount());
    assertEquals(1, c.getMethodCounter().getTotalCount());
    assertEquals(1, c.getMethodCounter().getCoveredCount());
    assertEquals(3, c.getLineCounter().getTotalCount());
    assertEquals(3, 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(1, m.getMethodCounter().getCoveredCount());
    assertEquals(3, m.getLineCounter().getTotalCount());
    assertEquals(3, m.getLineCounter().getCoveredCount());
}
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