KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > csdl > jblanket > methodset > TestMethodSetManager


1 package csdl.jblanket.methodset;
2
3 import java.util.ArrayList JavaDoc;
4 import java.util.List JavaDoc;
5
6 import java.io.File JavaDoc;
7
8 import junit.framework.TestCase;
9 import junit.framework.TestSuite;
10 import junit.textui.TestRunner;
11
12 /**
13  * Tests the Singleton MethodSetManager.
14  *
15  * @author Joy M. Agustin
16  * @version $Id: TestMethodSetManager.java,v 1.1 2004/11/07 00:32:40 timshadel Exp $
17  */

18 public class TestMethodSetManager extends TestCase {
19
20   /** Name of XML file to retrieve*/
21   private final String JavaDoc xmlFile1 = "xmlFile1.xml";
22
23   /** MethodSet object 1 */
24   private MethodSet methodSet1;
25   /** MethodSet object 2 */
26   private MethodSet methodSet2;
27
28   /** MethodInfo object with 2 parameters */
29   private MethodInfo methodInfo1;
30   /** MethodInfo object with no parameters */
31   private MethodInfo methodInfo2;
32
33   /** Fully qualified class name for first class*/
34   private final String JavaDoc class1 = "java.lang.String";
35   /** Fully qualified class name for second class*/
36   private final String JavaDoc class2 = "java.lang.Boolean";
37   /** Fully qualified class name for third class */
38   private final String JavaDoc class3 = "foo.bar.Baz";
39   /** Fully qualified class name for fourth class */
40   private final String JavaDoc class4 = "foo.bar.Foo";
41
42   /** Name of first method */
43   private final String JavaDoc method1 = "getQux";
44   /** Name of second method */
45   private final String JavaDoc method2 = "setQux";
46
47   /** Directory seperator */
48   private final String JavaDoc slash = File.separator;
49
50   /**
51    * Required for JUnit.
52    *
53    * @param name test case name.
54    */

55   public TestMethodSetManager(String JavaDoc name) {
56     super(name);
57   }
58
59   /**
60    * Sets up variables for testing.
61    */

62   public void setUp() {
63     // Create MethodInfo instances.
64
List JavaDoc params = new ArrayList JavaDoc();
65     params.add(class1);
66     params.add(class2);
67     methodInfo1 = new MethodInfo(class3, method1, params);
68
69     methodInfo2 = new MethodInfo(class4, method2, new ArrayList JavaDoc());
70
71     // Create MethodSets instances
72
methodSet1 = new MethodSet();
73     methodSet2 = new MethodSet();
74   }
75
76   /**
77    * Tests the <code>getMethodSet</code> method from the MethodSetManager class.
78    *
79    * @throws Exception if problems occur.
80    */

81   public void testMethodSetManager() throws Exception JavaDoc {
82
83     // get a MethodSet instance for xmlFile1
84
MethodSetManager manager = MethodSetManager.getInstance();
85     methodSet1 = manager.getMethodSet(xmlFile1);
86
87     // alter MethodSet instance
88
methodSet1.add(methodInfo1);
89     methodSet1.add(methodInfo2);
90
91     // make sure retrieve the same MethodSet instance from MethodSetManager
92
methodSet2 = manager.getMethodSet(xmlFile1);
93     assertTrue("checking that only one instance per file name", methodSet1.equals(methodSet2));
94   }
95
96   /**
97    * Provide stand-alone execution of this test case during initial development.
98    *
99    * @param args the command line arguments
100    */

101   public static void main(String JavaDoc[] args) {
102     System.out.println("JUnit testing MethodSetManager.");
103     //Runs all no-arg methods starting with "test".
104
TestRunner.run(new TestSuite(TestMethodSet.class));
105   }
106 }
107
Popular Tags