01: /*
02: * Created on Nov 7, 2004
03: */
04: package csdl.jblanket.modifier;
05:
06: import java.io.File;
07: import java.util.Date;
08:
09: 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: /**
22: * @author Tim
23: */
24: public class TestMethodCounter extends TestCase {
25:
26: /** MethodCounter object */
27: private MethodCounter counter;
28:
29: /** Stack.class */
30: private JavaClass clazz;
31:
32: /** Array of methods in Stack.class */
33: private Method[] methods;
34:
35: /** Directory separator */
36: private static final String SLASH = File.separator;
37:
38: public TestMethodCounter(String name) {
39: super (name);
40: }
41:
42: /**
43: * Sets up the instance variables for each test case.
44: *
45: * @throws Exception when unable to complete a setup.
46: */
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: // retrieve class byte code -- throws IOException
57: this .clazz = (new ClassParser(inFile.getAbsolutePath()))
58: .parse();
59: this .methods = clazz.getMethods();
60: MethodCategories categories = MethodCategories.getInstance();
61: MethodSetManager manager = MethodSetManager.getInstance();
62: MethodSet untestableSet = manager.getMethodSet(categories
63: .getFileName("untestableFile"));
64: ConstantPoolGen pool = new ConstantPoolGen(clazz
65: .getConstantPool());
66: for (int i = 0; i < methods.length; i++) {
67: MethodGen method = new MethodGen(methods[i], clazz
68: .getClassName(), pool);
69: MethodModifier modifier = new MethodModifier(false,
70: "Test*.class", true, false, true, method);
71: Method processedMethod = modifier.processMethod(pool, true);
72: }
73: assertEquals("Wrong number of untestable methods", 2,
74: untestableSet.size());
75: MethodCollector.storeMethodData(untestableSet, categories
76: .getFileName("untestableFile"), clazz.getClassName(),
77: new Date());
78: }
79:
80: }
|