1 4 package csdl.jblanket.modifier; 5 6 import java.io.File ; 7 import java.util.Date ; 8 9 import junit.framework.TestCase; 10 11 import org.apache.bcel.classfile.ClassParser; 12 import org.apache.bcel.classfile.JavaClass; 13 import org.apache.bcel.classfile.Method; 14 import org.apache.bcel.generic.ConstantPoolGen; 15 import org.apache.bcel.generic.MethodGen; 16 17 import csdl.jblanket.methodset.MethodSet; 18 import csdl.jblanket.methodset.MethodSetManager; 19 import csdl.jblanket.util.MethodCategories; 20 21 24 public class TestMethodCounter extends TestCase { 25 26 27 private MethodCounter counter; 28 29 30 private JavaClass clazz; 31 32 33 private Method[] methods; 34 35 36 private static final String SLASH = File.separator; 37 38 public TestMethodCounter(String name) { 39 super(name); 40 } 41 42 47 public void testCounter() throws Exception { 48 49 String testDir = System.getProperty("jblanket.data.dir"); 50 File dir = new File (testDir, "unjar"); 51 File classDir = new File (dir, "csdl" + SLASH + "foo"); 52 File inFile = new File (classDir, "TestBar.class"); 53 54 this.counter = new MethodCounter(); 55 56 this.clazz = (new ClassParser(inFile.getAbsolutePath())).parse(); 58 this.methods = clazz.getMethods(); 59 MethodCategories categories = MethodCategories.getInstance(); 60 MethodSetManager manager = MethodSetManager.getInstance(); 61 MethodSet untestableSet = manager.getMethodSet(categories.getFileName("untestableFile")); 62 ConstantPoolGen pool = new ConstantPoolGen(clazz.getConstantPool()); 63 for (int i = 0; i < methods.length; i++) { 64 MethodGen method = new MethodGen(methods[i], clazz.getClassName(), pool); 65 MethodModifier modifier = new MethodModifier(false, "Test*.class", true, false, true, method); 66 Method processedMethod = modifier.processMethod(pool, true); 67 } 68 assertEquals("Wrong number of untestable methods", 2, untestableSet.size()); 69 MethodCollector.storeMethodData(untestableSet, categories.getFileName("untestableFile"), 70 clazz.getClassName(), new Date ()); 71 } 72 73 } 74 | Popular Tags |