001: package csdl.jblanket.util;
002:
003: import csdl.jblanket.modifier.MethodCollector;
004:
005: import java.io.File;
006:
007: import junit.framework.TestCase;
008: import junit.framework.TestSuite;
009: import junit.textui.TestRunner;
010:
011: /**
012: * Tests operations in the MethodCategories class.
013: * <p>
014: * If using Ant to execute this test class a 'jblanket.testdir' system property needs to be set in
015: * the build.xml file. If running test class from command line, must provide '-Djblanket.testdir'
016: * to set the system property. This value is used by both the testJar and testUnjar methods.
017: *
018: *
019: * @author Joy M. Agustin
020: * @version $Id: TestMethodCategories.java,v 1.1 2004/11/07 00:32:27 timshadel Exp $
021: */
022: public class TestMethodCategories extends TestCase {
023:
024: /** Contains the method categories for testing */
025: private MethodCategories categories;
026:
027: /** JBlanket output directory */
028: private static String jblanketDir;
029:
030: /** Directory separator */
031: private final String slash = File.separator;
032:
033: /**
034: * Required for JUnit.
035: *
036: * @param name Test case name.
037: */
038: public TestMethodCategories(String name) {
039: super (name);
040:
041: jblanketDir = MethodCollector.getJBlanketDir();
042: }
043:
044: /**
045: * Sets up the instance variables for multiple test cases.
046: */
047: public void setUp() {
048: this .categories = MethodCategories.getInstance();
049: }
050:
051: /**
052: * Tests valid/expected categories.
053: */
054: public void testValidCategories() {
055:
056: // test empty categories; this should add default file name for "total" if a previous test
057: // didn't already add it
058: assertEquals("checking totalFile category in empty categories",
059: jblanketDir + slash + "totalMethods.xml", categories
060: .getFileName("totalFile"));
061:
062: int oldCategoriesSize = categories.getCategories().size();
063:
064: // test non-empty categories
065: categories.addCategory("totalFile", "myTotalMethods.xml");
066: assertEquals(
067: "checking totalFile category in non-empty categories",
068: jblanketDir + slash + "myTotalMethods.xml", categories
069: .getFileName("totalFile"));
070:
071: // check number of categories
072: assertEquals("checking number of categories",
073: oldCategoriesSize, categories.getCategories().size());
074: }
075:
076: /**
077: * Tests invalid/unexpected categories.
078: */
079: public void testInvalidCategories() {
080:
081: // test empty categories; this shouldn't add default file name
082: assertEquals("checking junkFile category in empty categories",
083: null, categories.getFileName("junkFile"));
084:
085: //try getting a category from non-empty categories; this should add null file name
086: categories.addCategory("junkFile");
087: assertEquals(
088: "checking junkFile category in non-empty categories",
089: null, categories.getFileName("junkFile"));
090:
091: categories.addCategory("junkFile", "myJunkMethods.xml");
092: assertEquals(
093: "checking junkFile category and file name in non-empty categories",
094: jblanketDir + slash + "myJunkMethods.xml", categories
095: .getFileName("junkFile"));
096:
097: }
098:
099: /**
100: * Provide stand-alone execution of this test case during initial development.
101: *
102: * @param args The command line arguments
103: */
104: public static void main(String[] args) {
105:
106: System.out.println("JUnit testing MethodCategories.");
107: //Runs all no-arg methods starting with "test".
108: TestRunner.run(new TestSuite(TestMethodCategories.class));
109: }
110: }
|