KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > csdl > jblanket > util > TestMethodCategories


1 package csdl.jblanket.util;
2
3 import csdl.jblanket.modifier.MethodCollector;
4
5 import java.io.File JavaDoc;
6
7 import junit.framework.TestCase;
8 import junit.framework.TestSuite;
9 import junit.textui.TestRunner;
10
11 /**
12  * Tests operations in the MethodCategories class.
13  * <p>
14  * If using Ant to execute this test class a 'jblanket.testdir' system property needs to be set in
15  * the build.xml file. If running test class from command line, must provide '-Djblanket.testdir'
16  * to set the system property. This value is used by both the testJar and testUnjar methods.
17  *
18  *
19  * @author Joy M. Agustin
20  * @version $Id: TestMethodCategories.java,v 1.1 2004/11/07 00:32:27 timshadel Exp $
21  */

22 public class TestMethodCategories extends TestCase {
23  
24   /** Contains the method categories for testing */
25   private MethodCategories categories;
26   
27   /** JBlanket output directory */
28   private static String JavaDoc jblanketDir;
29   
30   /** Directory separator */
31   private final String JavaDoc slash = File.separator;
32   
33   /**
34    * Required for JUnit.
35    *
36    * @param name Test case name.
37    */

38   public TestMethodCategories(String JavaDoc name) {
39     super(name);
40     
41     jblanketDir = MethodCollector.getJBlanketDir();
42   }
43
44   /**
45    * Sets up the instance variables for multiple test cases.
46    */

47   public void setUp() {
48     this.categories = MethodCategories.getInstance();
49   }
50
51   /**
52    * Tests valid/expected categories.
53    */

54   public void testValidCategories() {
55     
56     // test empty categories; this should add default file name for "total" if a previous test
57
// didn't already add it
58
assertEquals("checking totalFile category in empty categories",
59                  jblanketDir + slash + "totalMethods.xml", categories.getFileName("totalFile"));
60
61     int oldCategoriesSize = categories.getCategories().size();
62
63     // test non-empty categories
64
categories.addCategory("totalFile", "myTotalMethods.xml");
65     assertEquals("checking totalFile category in non-empty categories",
66                  jblanketDir + slash + "myTotalMethods.xml", categories.getFileName("totalFile"));
67
68     // check number of categories
69
assertEquals("checking number of categories", oldCategoriesSize,
70                  categories.getCategories().size());
71   }
72  
73   /**
74    * Tests invalid/unexpected categories.
75    */

76   public void testInvalidCategories() {
77
78     // test empty categories; this shouldn't add default file name
79
assertEquals("checking junkFile category in empty categories",
80                  null, categories.getFileName("junkFile"));
81
82     //try getting a category from non-empty categories; this should add null file name
83
categories.addCategory("junkFile");
84     assertEquals("checking junkFile category in non-empty categories",
85                  null, categories.getFileName("junkFile"));
86
87     categories.addCategory("junkFile", "myJunkMethods.xml");
88     assertEquals("checking junkFile category and file name in non-empty categories",
89                  jblanketDir + slash + "myJunkMethods.xml", categories.getFileName("junkFile"));
90     
91   }
92  
93   /**
94    * Provide stand-alone execution of this test case during initial development.
95    *
96    * @param args The command line arguments
97    */

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