1/******************************************************************************* 2 * Copyright (c) 2009, 2017 Mountainminds GmbH & Co. KG and Contributors 3 * All rights reserved. This program and the accompanying materials 4 * are made available under the terms of the Eclipse Public License v1.0 5 * which accompanies this distribution, and is available at 6 * http://www.eclipse.org/legal/epl-v10.html 7 * 8 * Contributors: 9 * Evgeny Mandrikov - initial API and implementation 10 * 11 *******************************************************************************/ 12package org.jacoco.core.internal.analysis.filter; 13 14import static org.junit.Assert.assertEquals; 15import static org.junit.Assert.assertNull; 16 17import org.jacoco.core.internal.instr.InstrSupport; 18import org.junit.Test; 19import org.objectweb.asm.Opcodes; 20import org.objectweb.asm.tree.AbstractInsnNode; 21import org.objectweb.asm.tree.MethodNode; 22 23public class EnumFilterTest implements IFilterOutput { 24 25 private final EnumFilter filter = new EnumFilter(); 26 27 private AbstractInsnNode fromInclusive; 28 private AbstractInsnNode toInclusive; 29 30 @Test 31 public void testValues() { 32 final MethodNode m = new MethodNode(InstrSupport.ASM_API_VERSION, 0, 33 "values", "()[LFoo;", null, null); 34 m.visitInsn(Opcodes.NOP); 35 36 filter.filter("Foo", "java/lang/Enum", m, this); 37 38 assertEquals(m.instructions.getFirst(), fromInclusive); 39 assertEquals(m.instructions.getLast(), toInclusive); 40 } 41 42 @Test 43 public void testNonValues() { 44 final MethodNode m = new MethodNode(InstrSupport.ASM_API_VERSION, 0, 45 "values", "()V", null, null); 46 m.visitInsn(Opcodes.NOP); 47 48 filter.filter("Foo", "java/lang/Enum", m, this); 49 50 assertNull(fromInclusive); 51 assertNull(toInclusive); 52 } 53 54 @Test 55 public void testValueOf() { 56 final MethodNode m = new MethodNode(InstrSupport.ASM_API_VERSION, 0, 57 "valueOf", "(Ljava/lang/String;)LFoo;", null, null); 58 m.visitInsn(Opcodes.NOP); 59 60 filter.filter("Foo", "java/lang/Enum", m, this); 61 62 assertEquals(m.instructions.getFirst(), fromInclusive); 63 assertEquals(m.instructions.getLast(), toInclusive); 64 } 65 66 @Test 67 public void testNonValueOf() { 68 final MethodNode m = new MethodNode(InstrSupport.ASM_API_VERSION, 0, 69 "valueOf", "()V", null, null); 70 m.visitInsn(Opcodes.NOP); 71 72 filter.filter("Foo", "java/lang/Enum", m, this); 73 74 assertNull(fromInclusive); 75 assertNull(toInclusive); 76 } 77 78 @Test 79 public void testNonEnum() { 80 final MethodNode m = new MethodNode(InstrSupport.ASM_API_VERSION, 0, 81 "values", "()[LFoo;", null, null); 82 m.visitInsn(Opcodes.NOP); 83 84 filter.filter("Foo", "java/lang/Object", m, this); 85 86 assertNull(fromInclusive); 87 assertNull(toInclusive); 88 } 89 90 public void ignore(final AbstractInsnNode fromInclusive, 91 final AbstractInsnNode toInclusive) { 92 assertNull(this.fromInclusive); 93 this.fromInclusive = fromInclusive; 94 this.toInclusive = toInclusive; 95 } 96 97} 98