KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > csdl > jblanket > modifier > TestMethodCounter


1 /*
2  * Created on Nov 7, 2004
3  */

4 package csdl.jblanket.modifier;
5
6 import java.io.File JavaDoc;
7 import java.util.Date JavaDoc;
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 /**
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 JavaDoc SLASH = File.separator;
37
38     public TestMethodCounter(String JavaDoc 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 JavaDoc {
48
49       String JavaDoc testDir = System.getProperty("jblanket.data.dir");
50       File JavaDoc dir = new File JavaDoc(testDir, "unjar");
51       File JavaDoc classDir = new File JavaDoc(dir, "csdl" + SLASH + "foo");
52       File JavaDoc inFile = new File JavaDoc(classDir, "TestBar.class");
53
54       this.counter = new MethodCounter();
55
56       // retrieve class byte code -- throws IOException
57
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 JavaDoc());
71     }
72
73 }
74
Popular Tags