001: package csdl.jblanket.methodset;
002:
003: import java.util.ArrayList;
004: import java.util.List;
005:
006: import java.io.File;
007:
008: import junit.framework.TestCase;
009: import junit.framework.TestSuite;
010: import junit.textui.TestRunner;
011:
012: /**
013: * Tests the Singleton MethodSetManager.
014: *
015: * @author Joy M. Agustin
016: * @version $Id: TestMethodSetManager.java,v 1.1 2004/11/07 00:32:40 timshadel Exp $
017: */
018: public class TestMethodSetManager extends TestCase {
019:
020: /** Name of XML file to retrieve*/
021: private final String xmlFile1 = "xmlFile1.xml";
022:
023: /** MethodSet object 1 */
024: private MethodSet methodSet1;
025: /** MethodSet object 2 */
026: private MethodSet methodSet2;
027:
028: /** MethodInfo object with 2 parameters */
029: private MethodInfo methodInfo1;
030: /** MethodInfo object with no parameters */
031: private MethodInfo methodInfo2;
032:
033: /** Fully qualified class name for first class*/
034: private final String class1 = "java.lang.String";
035: /** Fully qualified class name for second class*/
036: private final String class2 = "java.lang.Boolean";
037: /** Fully qualified class name for third class */
038: private final String class3 = "foo.bar.Baz";
039: /** Fully qualified class name for fourth class */
040: private final String class4 = "foo.bar.Foo";
041:
042: /** Name of first method */
043: private final String method1 = "getQux";
044: /** Name of second method */
045: private final String method2 = "setQux";
046:
047: /** Directory seperator */
048: private final String slash = File.separator;
049:
050: /**
051: * Required for JUnit.
052: *
053: * @param name test case name.
054: */
055: public TestMethodSetManager(String name) {
056: super (name);
057: }
058:
059: /**
060: * Sets up variables for testing.
061: */
062: public void setUp() {
063: // Create MethodInfo instances.
064: List params = new ArrayList();
065: params.add(class1);
066: params.add(class2);
067: methodInfo1 = new MethodInfo(class3, method1, params);
068:
069: methodInfo2 = new MethodInfo(class4, method2, new ArrayList());
070:
071: // Create MethodSets instances
072: methodSet1 = new MethodSet();
073: methodSet2 = new MethodSet();
074: }
075:
076: /**
077: * Tests the <code>getMethodSet</code> method from the MethodSetManager class.
078: *
079: * @throws Exception if problems occur.
080: */
081: public void testMethodSetManager() throws Exception {
082:
083: // get a MethodSet instance for xmlFile1
084: MethodSetManager manager = MethodSetManager.getInstance();
085: methodSet1 = manager.getMethodSet(xmlFile1);
086:
087: // alter MethodSet instance
088: methodSet1.add(methodInfo1);
089: methodSet1.add(methodInfo2);
090:
091: // make sure retrieve the same MethodSet instance from MethodSetManager
092: methodSet2 = manager.getMethodSet(xmlFile1);
093: assertTrue("checking that only one instance per file name",
094: methodSet1.equals(methodSet2));
095: }
096:
097: /**
098: * Provide stand-alone execution of this test case during initial development.
099: *
100: * @param args the command line arguments
101: */
102: public static void main(String[] args) {
103: System.out.println("JUnit testing MethodSetManager.");
104: //Runs all no-arg methods starting with "test".
105: TestRunner.run(new TestSuite(TestMethodSet.class));
106: }
107: }
|