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 * Marc R. Hoffmann - initial API and implementation 10 * 11 *******************************************************************************/ 12package org.jacoco.core.internal.instr; 13 14import static org.junit.Assert.assertNull; 15 16import org.junit.Before; 17import org.junit.Test; 18import org.objectweb.asm.ClassVisitor; 19import org.objectweb.asm.MethodVisitor; 20 21/** 22 * Unit tests for {@link ClassInstrumenter}. 23 */ 24public class ClassInstrumenterTest implements IProbeArrayStrategy { 25 26 private ClassInstrumenter instrumenter; 27 28 @Before 29 public void setup() { 30 instrumenter = new ClassInstrumenter(this, new ClassVisitor( 31 InstrSupport.ASM_API_VERSION) { 32 }); 33 } 34 35 @Test(expected = IllegalStateException.class) 36 public void testInstrumentInstrumentedClass1() { 37 instrumenter.visitField(InstrSupport.DATAFIELD_ACC, 38 InstrSupport.DATAFIELD_NAME, InstrSupport.DATAFIELD_DESC, null, 39 null); 40 } 41 42 @Test(expected = IllegalStateException.class) 43 public void testInstrumentInstrumentedClass2() { 44 instrumenter.visitMethod(InstrSupport.INITMETHOD_ACC, 45 InstrSupport.INITMETHOD_NAME, InstrSupport.INITMETHOD_DESC, 46 null, null); 47 } 48 49 @Test 50 public void testNoMethodVisitor() { 51 instrumenter = new ClassInstrumenter(this, new ClassVisitor( 52 InstrSupport.ASM_API_VERSION) { 53 @Override 54 public MethodVisitor visitMethod(int access, String name, 55 String desc, String signature, String[] exceptions) { 56 return null; 57 } 58 }); 59 assertNull(instrumenter.visitMethod(0, "foo", "()V", null, null)); 60 } 61 62 // === IProbeArrayStrategy === 63 64 public int storeInstance(MethodVisitor mv, boolean clinit, int variable) { 65 return 0; 66 } 67 68 public void addMembers(ClassVisitor cv, int probeCount) { 69 } 70 71} 72