aboutsummaryrefslogtreecommitdiff
path: root/org.jacoco.core.test/src
diff options
context:
space:
mode:
authorEvgeny Mandrikov <Godin@users.noreply.github.com>2017-04-03 19:35:02 +0200
committerMarc R. Hoffmann <hoffmann@mountainminds.com>2017-04-03 19:35:02 +0200
commite94c7af58000b3421bc63a252ee054c08a863568 (patch)
tree385b540d48297b3b66947e349f61fb2f4cd72030 /org.jacoco.core.test/src
parent7f719c8365b3ac8853cfc8b62fd48d2eabddfc4c (diff)
downloadjacoco-e94c7af58000b3421bc63a252ee054c08a863568.tar.gz
Use new filtering API for existing filter of methods in enums (#512)
Diffstat (limited to 'org.jacoco.core.test/src')
-rw-r--r--org.jacoco.core.test/src/org/jacoco/core/internal/analysis/ClassAnalyzerTest.java44
-rw-r--r--org.jacoco.core.test/src/org/jacoco/core/internal/analysis/MethodAnalyzerTest.java4
-rw-r--r--org.jacoco.core.test/src/org/jacoco/core/internal/analysis/filter/EnumFilterTest.java97
-rw-r--r--org.jacoco.core.test/src/org/jacoco/core/internal/analysis/filter/LombokGeneratedFilterTest.java6
-rw-r--r--org.jacoco.core.test/src/org/jacoco/core/internal/analysis/filter/SynchronizedFilterTest.java6
-rw-r--r--org.jacoco.core.test/src/org/jacoco/core/internal/analysis/filter/SyntheticFilterTest.java12
-rw-r--r--org.jacoco.core.test/src/org/jacoco/core/test/validation/targets/EnumImplicitMethods.java4
7 files changed, 113 insertions, 60 deletions
diff --git a/org.jacoco.core.test/src/org/jacoco/core/internal/analysis/ClassAnalyzerTest.java b/org.jacoco.core.test/src/org/jacoco/core/internal/analysis/ClassAnalyzerTest.java
index 6da24ff9..c71e52f9 100644
--- a/org.jacoco.core.test/src/org/jacoco/core/internal/analysis/ClassAnalyzerTest.java
+++ b/org.jacoco.core.test/src/org/jacoco/core/internal/analysis/ClassAnalyzerTest.java
@@ -59,48 +59,4 @@ public class ClassAnalyzerTest {
assertEquals(0, coverage.getMethods().size());
}
- @Test
- public void testMethodFilter_EnumValues() {
- analyzer.visit(Opcodes.V1_5, Opcodes.ACC_PUBLIC, "Foo", null,
- "java/lang/Enum", null);
- final MethodProbesVisitor mv = analyzer.visitMethod(0, "values",
- "()[LFoo;", null, null);
- assertNull(mv);
- assertTrue(coverage.getMethods().isEmpty());
- }
-
- @Test
- public void testMethodFilter_EnumNonValues() {
- analyzer.visit(Opcodes.V1_5, Opcodes.ACC_PUBLIC, "Foo", null,
- "java/lang/Enum", null);
- final MethodProbesVisitor mv = analyzer.visitMethod(0, "values", "()V",
- null, null);
- mv.visitCode();
- mv.visitInsn(Opcodes.RETURN);
- mv.visitEnd();
- assertEquals(1, coverage.getMethods().size());
- }
-
- @Test
- public void testMethodFilter_EnumValueOf() {
- analyzer.visit(Opcodes.V1_5, Opcodes.ACC_PUBLIC, "Foo", null,
- "java/lang/Enum", null);
- final MethodProbesVisitor mv = analyzer.visitMethod(0, "valueOf",
- "(Ljava/lang/String;)LFoo;", null, null);
- assertNull(mv);
- assertTrue(coverage.getMethods().isEmpty());
- }
-
- @Test
- public void testMethodFilter_EnumNonValueOf() {
- analyzer.visit(Opcodes.V1_5, Opcodes.ACC_PUBLIC, "Foo", null,
- "java/lang/Enum", null);
- final MethodProbesVisitor mv = analyzer.visitMethod(0, "valueOf", "()V",
- null, null);
- mv.visitCode();
- mv.visitInsn(Opcodes.RETURN);
- mv.visitEnd();
- assertEquals(1, coverage.getMethods().size());
- }
-
}
diff --git a/org.jacoco.core.test/src/org/jacoco/core/internal/analysis/MethodAnalyzerTest.java b/org.jacoco.core.test/src/org/jacoco/core/internal/analysis/MethodAnalyzerTest.java
index 6bcbd630..dbe0af63 100644
--- a/org.jacoco.core.test/src/org/jacoco/core/internal/analysis/MethodAnalyzerTest.java
+++ b/org.jacoco.core.test/src/org/jacoco/core/internal/analysis/MethodAnalyzerTest.java
@@ -580,8 +580,8 @@ public class MethodAnalyzerTest implements IProbeIdGenerator {
private void runMethodAnalzer() {
LabelFlowAnalyzer.markLabels(method);
- final MethodAnalyzer analyzer = new MethodAnalyzer("doit", "()V", null,
- probes);
+ final MethodAnalyzer analyzer = new MethodAnalyzer("Foo",
+ "java/lang/Object", "doit", "()V", null, probes);
final MethodProbesAdapter probesAdapter = new MethodProbesAdapter(
analyzer, this);
// note that CheckMethodAdapter verifies that this test does not violate
diff --git a/org.jacoco.core.test/src/org/jacoco/core/internal/analysis/filter/EnumFilterTest.java b/org.jacoco.core.test/src/org/jacoco/core/internal/analysis/filter/EnumFilterTest.java
new file mode 100644
index 00000000..149990f5
--- /dev/null
+++ b/org.jacoco.core.test/src/org/jacoco/core/internal/analysis/filter/EnumFilterTest.java
@@ -0,0 +1,97 @@
+/*******************************************************************************
+ * Copyright (c) 2009, 2017 Mountainminds GmbH & Co. KG and Contributors
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Evgeny Mandrikov - initial API and implementation
+ *
+ *******************************************************************************/
+package org.jacoco.core.internal.analysis.filter;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+
+import org.jacoco.core.internal.instr.InstrSupport;
+import org.junit.Test;
+import org.objectweb.asm.Opcodes;
+import org.objectweb.asm.tree.AbstractInsnNode;
+import org.objectweb.asm.tree.MethodNode;
+
+public class EnumFilterTest implements IFilterOutput {
+
+ private final EnumFilter filter = new EnumFilter();
+
+ private AbstractInsnNode fromInclusive;
+ private AbstractInsnNode toInclusive;
+
+ @Test
+ public void testValues() {
+ final MethodNode m = new MethodNode(InstrSupport.ASM_API_VERSION, 0,
+ "values", "()[LFoo;", null, null);
+ m.visitInsn(Opcodes.NOP);
+
+ filter.filter("Foo", "java/lang/Enum", m, this);
+
+ assertEquals(m.instructions.getFirst(), fromInclusive);
+ assertEquals(m.instructions.getLast(), toInclusive);
+ }
+
+ @Test
+ public void testNonValues() {
+ final MethodNode m = new MethodNode(InstrSupport.ASM_API_VERSION, 0,
+ "values", "()V", null, null);
+ m.visitInsn(Opcodes.NOP);
+
+ filter.filter("Foo", "java/lang/Enum", m, this);
+
+ assertNull(fromInclusive);
+ assertNull(toInclusive);
+ }
+
+ @Test
+ public void testValueOf() {
+ final MethodNode m = new MethodNode(InstrSupport.ASM_API_VERSION, 0,
+ "valueOf", "(Ljava/lang/String;)LFoo;", null, null);
+ m.visitInsn(Opcodes.NOP);
+
+ filter.filter("Foo", "java/lang/Enum", m, this);
+
+ assertEquals(m.instructions.getFirst(), fromInclusive);
+ assertEquals(m.instructions.getLast(), toInclusive);
+ }
+
+ @Test
+ public void testNonValueOf() {
+ final MethodNode m = new MethodNode(InstrSupport.ASM_API_VERSION, 0,
+ "valueOf", "()V", null, null);
+ m.visitInsn(Opcodes.NOP);
+
+ filter.filter("Foo", "java/lang/Enum", m, this);
+
+ assertNull(fromInclusive);
+ assertNull(toInclusive);
+ }
+
+ @Test
+ public void testNonEnum() {
+ final MethodNode m = new MethodNode(InstrSupport.ASM_API_VERSION, 0,
+ "values", "()[LFoo;", null, null);
+ m.visitInsn(Opcodes.NOP);
+
+ filter.filter("Foo", "java/lang/Object", m, this);
+
+ assertNull(fromInclusive);
+ assertNull(toInclusive);
+ }
+
+ public void ignore(final AbstractInsnNode fromInclusive,
+ final AbstractInsnNode toInclusive) {
+ assertNull(this.fromInclusive);
+ this.fromInclusive = fromInclusive;
+ this.toInclusive = toInclusive;
+ }
+
+}
diff --git a/org.jacoco.core.test/src/org/jacoco/core/internal/analysis/filter/LombokGeneratedFilterTest.java b/org.jacoco.core.test/src/org/jacoco/core/internal/analysis/filter/LombokGeneratedFilterTest.java
index a1fdcae9..58f93fb1 100644
--- a/org.jacoco.core.test/src/org/jacoco/core/internal/analysis/filter/LombokGeneratedFilterTest.java
+++ b/org.jacoco.core.test/src/org/jacoco/core/internal/analysis/filter/LombokGeneratedFilterTest.java
@@ -38,7 +38,7 @@ public class LombokGeneratedFilterTest implements IFilterOutput {
m.visitInsn(Opcodes.ICONST_0);
m.visitInsn(Opcodes.IRETURN);
- filter.filter(m, this);
+ filter.filter("Foo", "java/lang/Object", m, this);
assertNull(fromInclusive);
assertNull(toInclusive);
@@ -53,7 +53,7 @@ public class LombokGeneratedFilterTest implements IFilterOutput {
m.visitInsn(Opcodes.ICONST_0);
m.visitInsn(Opcodes.IRETURN);
- filter.filter(m, this);
+ filter.filter("Foo", "java/lang/Object", m, this);
assertNull(fromInclusive);
assertNull(toInclusive);
@@ -68,7 +68,7 @@ public class LombokGeneratedFilterTest implements IFilterOutput {
m.visitInsn(Opcodes.ICONST_0);
m.visitInsn(Opcodes.IRETURN);
- filter.filter(m, this);
+ filter.filter("Foo", "java/lang/Object", m, this);
assertEquals(m.instructions.getFirst(), fromInclusive);
assertEquals(m.instructions.getLast(), toInclusive);
diff --git a/org.jacoco.core.test/src/org/jacoco/core/internal/analysis/filter/SynchronizedFilterTest.java b/org.jacoco.core.test/src/org/jacoco/core/internal/analysis/filter/SynchronizedFilterTest.java
index b315dda5..b0f5d1b0 100644
--- a/org.jacoco.core.test/src/org/jacoco/core/internal/analysis/filter/SynchronizedFilterTest.java
+++ b/org.jacoco.core.test/src/org/jacoco/core/internal/analysis/filter/SynchronizedFilterTest.java
@@ -63,7 +63,7 @@ public class SynchronizedFilterTest implements IFilterOutput {
m.visitLabel(exit);
m.visitInsn(Opcodes.RETURN);
- filter.filter(m, this);
+ filter.filter("Foo", "java/lang/Object", m, this);
assertEquals(handler.info, fromInclusive);
assertEquals(((LabelNode) exit.info).getPrevious(), toInclusive);
}
@@ -116,7 +116,7 @@ public class SynchronizedFilterTest implements IFilterOutput {
m.visitLabel(exit);
m.visitInsn(Opcodes.RETURN);
- filter.filter(m, this);
+ filter.filter("Foo", "java/lang/Object", m, this);
assertNull(fromInclusive);
}
@@ -151,7 +151,7 @@ public class SynchronizedFilterTest implements IFilterOutput {
m.visitLabel(exit);
m.visitInsn(Opcodes.RETURN);
- filter.filter(m, this);
+ filter.filter("Foo", "java/lang/Object", m, this);
assertEquals(handler.info, fromInclusive);
assertEquals(((LabelNode) exit.info).getPrevious(), toInclusive);
}
diff --git a/org.jacoco.core.test/src/org/jacoco/core/internal/analysis/filter/SyntheticFilterTest.java b/org.jacoco.core.test/src/org/jacoco/core/internal/analysis/filter/SyntheticFilterTest.java
index 75648dc9..319caef5 100644
--- a/org.jacoco.core.test/src/org/jacoco/core/internal/analysis/filter/SyntheticFilterTest.java
+++ b/org.jacoco.core.test/src/org/jacoco/core/internal/analysis/filter/SyntheticFilterTest.java
@@ -11,15 +11,15 @@
*******************************************************************************/
package org.jacoco.core.internal.analysis.filter;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+
import org.jacoco.core.internal.instr.InstrSupport;
import org.junit.Test;
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.tree.AbstractInsnNode;
import org.objectweb.asm.tree.MethodNode;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNull;
-
public class SyntheticFilterTest implements IFilterOutput {
private final SyntheticFilter filter = new SyntheticFilter();
@@ -33,7 +33,7 @@ public class SyntheticFilterTest implements IFilterOutput {
"name", "()V", null, null);
m.visitInsn(Opcodes.NOP);
- filter.filter(m, this);
+ filter.filter("Foo", "java/lang/Object", m, this);
assertNull(fromInclusive);
assertNull(toInclusive);
@@ -45,7 +45,7 @@ public class SyntheticFilterTest implements IFilterOutput {
Opcodes.ACC_SYNTHETIC, "name", "()V", null, null);
m.visitInsn(Opcodes.NOP);
- filter.filter(m, this);
+ filter.filter("Foo", "java/lang/Object", m, this);
assertEquals(m.instructions.getFirst(), fromInclusive);
assertEquals(m.instructions.getLast(), toInclusive);
@@ -57,7 +57,7 @@ public class SyntheticFilterTest implements IFilterOutput {
Opcodes.ACC_SYNTHETIC, "lambda$1", "()V", null, null);
m.visitInsn(Opcodes.NOP);
- filter.filter(m, this);
+ filter.filter("Foo", "java/lang/Object", m, this);
assertNull(fromInclusive);
assertNull(toInclusive);
diff --git a/org.jacoco.core.test/src/org/jacoco/core/test/validation/targets/EnumImplicitMethods.java b/org.jacoco.core.test/src/org/jacoco/core/test/validation/targets/EnumImplicitMethods.java
index aaa5e987..69a2ed9f 100644
--- a/org.jacoco.core.test/src/org/jacoco/core/test/validation/targets/EnumImplicitMethods.java
+++ b/org.jacoco.core.test/src/org/jacoco/core/test/validation/targets/EnumImplicitMethods.java
@@ -29,7 +29,7 @@ public enum EnumImplicitMethods { // $line-classdef$
/**
* This method should not be excluded from analysis unlike implicitly
* created {@link #valueOf(String)} method that refers to the line of enum
- * definition.
+ * definition in case of javac and to the first line in case of ECJ.
*/
public void valueOf() {
} // $line-customValueOfMethod$
@@ -37,7 +37,7 @@ public enum EnumImplicitMethods { // $line-classdef$
/**
* This method should not be excluded from analysis unlike implicitly
* created {@link #values()} method that refers to the line of enum
- * definition.
+ * definition in case of javac and to the first line in case of ECJ.
*/
public void values(Object o) {
} // $line-customValuesMethod$