Search in sources :

Example 11 with MethodCoverageImpl

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

the class CoverageBuilderTest method testDuplicateClassNameIdentical.

@Test
public void testDuplicateClassNameIdentical() {
    MethodCoverageImpl method = new MethodCoverageImpl("doit", "()V", null);
    method.increment(CounterImpl.COUNTER_1_0, CounterImpl.COUNTER_0_0, 3);
    addClass(123L, false, "Sample", null, method);
    // Add class with same id:
    method = new MethodCoverageImpl("doit", "()V", null);
    method.increment(CounterImpl.COUNTER_1_0, CounterImpl.COUNTER_0_0, 3);
    addClass(123L, false, "Sample", null, method);
    // Second add must be ignored:
    final Collection<IClassCoverage> classes = coverageBuilder.getClasses();
    assertEquals(1, classes.size());
}
Also used : MethodCoverageImpl(org.jacoco.core.internal.analysis.MethodCoverageImpl) Test(org.junit.Test)

Example 12 with MethodCoverageImpl

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

the class CoverageBuilderTest method testCreateSourceFile.

@Test
public void testCreateSourceFile() {
    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, 6);
    addClass(234L, false, "Second", "Sample.java", method2);
    final Collection<ISourceFileCoverage> sourcefiles = coverageBuilder.getSourceFiles();
    assertEquals(1, sourcefiles.size());
    ISourceFileCoverage s = sourcefiles.iterator().next();
    assertEquals(2, s.getClassCounter().getTotalCount());
    assertEquals(0, s.getClassCounter().getCoveredCount());
}
Also used : MethodCoverageImpl(org.jacoco.core.internal.analysis.MethodCoverageImpl) Test(org.junit.Test)

Example 13 with MethodCoverageImpl

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

the class CoverageBuilderTest method testGetNoMatchClasses.

@Test
public void testGetNoMatchClasses() {
    MethodCoverageImpl m = new MethodCoverageImpl("doit", "()V", null);
    m.increment(CounterImpl.COUNTER_1_0, CounterImpl.COUNTER_0_0, 1);
    addClass(1, true, "Sample1", null, m);
    m = new MethodCoverageImpl("doit", "()V", null);
    m.increment(CounterImpl.COUNTER_1_0, CounterImpl.COUNTER_0_0, 2);
    addClass(2, true, "Sample2", null, m);
    m = new MethodCoverageImpl("doit", "()V", null);
    m.increment(CounterImpl.COUNTER_1_0, CounterImpl.COUNTER_0_0, 3);
    addClass(3, false, "Sample3", null, m);
    final Set<String> actual = getNames(coverageBuilder.getNoMatchClasses());
    final Set<String> expected = new HashSet<String>(Arrays.asList("Sample1", "Sample2"));
    assertEquals(expected, actual);
}
Also used : MethodCoverageImpl(org.jacoco.core.internal.analysis.MethodCoverageImpl) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 14 with MethodCoverageImpl

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

the class CoverageBuilderTest method testDuplicateClassNameDifferent.

@Test(expected = IllegalStateException.class)
public void testDuplicateClassNameDifferent() {
    MethodCoverageImpl method = new MethodCoverageImpl("doit", "()V", null);
    method.increment(CounterImpl.COUNTER_1_0, CounterImpl.COUNTER_0_0, 3);
    addClass(123L, false, "Sample", null, method);
    // Add class with different id must fail:
    method = new MethodCoverageImpl("doit", "()V", null);
    method.increment(CounterImpl.COUNTER_1_0, CounterImpl.COUNTER_0_0, 3);
    addClass(345L, false, "Sample", null, method);
}
Also used : MethodCoverageImpl(org.jacoco.core.internal.analysis.MethodCoverageImpl) Test(org.junit.Test)

Example 15 with MethodCoverageImpl

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

the class ClassPageTest method should_generate_message_when_class_id_mismatch.

@Test
public void should_generate_message_when_class_id_mismatch() throws Exception {
    node = new ClassCoverageImpl("Foo", 123, true);
    node.addMethod(new MethodCoverageImpl("m", "()V", null));
    page = new ClassPage(node, null, new SourceLink(), rootFolder, context);
    page.render();
    final Document doc = support.parse(output.getFile("Foo.html"));
    assertEquals("A different version of class was executed at runtime.", 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)

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