KickJava   Java API By Example, From Geeks To Geeks.

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


1 package csdl.jblanket.modifier;
2
3 import csdl.jblanket.methodset.MethodSet;
4 import csdl.jblanket.methodset.MethodSetManager;
5 import csdl.jblanket.util.MethodCategories;
6
7 import java.io.File JavaDoc;
8
9 import junit.framework.TestCase;
10
11 import org.apache.tools.ant.util.FileUtils;
12
13 /**
14  * Tests the ClassModifier class.
15  *
16  * @author Joy M. Agustin
17  * @version $Id: TestClassModifier.java,v 1.2 2005/02/19 05:55:19 timshadel Exp $
18  */

19 public class TestClassModifier extends TestCase {
20
21   /** Input File */
22   private File JavaDoc inFile;
23
24   /** MethodCounter object */
25   private MethodCounter counter;
26
27   /** ClassModifier object */
28   private ClassModifier modifier;
29
30   /**
31    * Constructor required by JUnit.
32    *
33    * @param name the name of this test class.
34    */

35   public TestClassModifier(String JavaDoc name) {
36     super(name);
37   }
38
39   /**
40    * Sets up the instance variables for each test case.
41    *
42    * @throws Exception when unable to complete a setup.
43    */

44   public void setUp() throws Exception JavaDoc {
45     // Directory separator
46
final String JavaDoc slash = File.separator;
47     
48     // original file
49
File JavaDoc dir = new File JavaDoc(System.getProperty("jblanket.data.dir"));
50     File JavaDoc originalDir = new File JavaDoc(dir, "unjar" + slash + "edu" + slash + "hawaii" + slash + "stack");
51     File JavaDoc originalFile = new File JavaDoc(originalDir, "Stack.class");
52     
53     // input file
54
File JavaDoc inDir = new File JavaDoc(System.getProperty("jblanket.testdir"), "testclassmodifier");
55     this.inFile = new File JavaDoc(inDir, "Stack.class");
56     
57     // copy original file to input file
58
FileUtils fileUtils = FileUtils.newFileUtils();
59     fileUtils.copyFile(originalFile, this.inFile);
60     
61     this.counter = new MethodCounter();
62     this.modifier = new ClassModifier(false, "Test*.class", true, true, false,
63                                       this.counter, this.inFile);
64   }
65
66   /**
67    * Tests the modifyMethods and isModified methods.
68    */

69   public void testModifyMethods() {
70     
71     assertEquals("Checking if class already modified", false, this.modifier.isModified());
72     
73     try {
74       this.modifier.modifyMethods();
75     }
76     catch (Exception JavaDoc e) {
77       fail("Unable to store modified methods");
78     }
79         
80     assertEquals("Checking if class already modified", true, this.modifier.isModified());
81   }
82   
83   /**
84    * Tests the excludeMethods method with the constructor
85    * ClassModifier(boolean, MethodCounter, File).
86    */

87   public void testExcludeMethods() {
88     
89     try {
90       this.modifier = new ClassModifier(false, this.counter, this.inFile);
91     }
92     catch (Exception JavaDoc e) {
93       fail("Unable to construct new object");
94     }
95     
96     this.modifier.excludeMethods();
97     
98     String JavaDoc fileName = MethodCategories.getInstance().getFileName("excludedFile");
99     MethodSet methodSet = MethodSetManager.getInstance().getMethodSet(fileName);
100     assertEquals("Checking size of exclude MethodSet", 8, methodSet.size());
101   }
102 }
Popular Tags