001: package csdl.jblanket.modifier;
002:
003: import csdl.jblanket.methodset.MethodSet;
004: import csdl.jblanket.methodset.MethodSetManager;
005: import csdl.jblanket.util.MethodCategories;
006:
007: import java.io.File;
008:
009: import junit.framework.TestCase;
010:
011: import org.apache.tools.ant.util.FileUtils;
012:
013: /**
014: * Tests the ClassModifier class.
015: *
016: * @author Joy M. Agustin
017: * @version $Id: TestClassModifier.java,v 1.2 2005/02/19 05:55:19 timshadel Exp $
018: */
019: public class TestClassModifier extends TestCase {
020:
021: /** Input File */
022: private File inFile;
023:
024: /** MethodCounter object */
025: private MethodCounter counter;
026:
027: /** ClassModifier object */
028: private ClassModifier modifier;
029:
030: /**
031: * Constructor required by JUnit.
032: *
033: * @param name the name of this test class.
034: */
035: public TestClassModifier(String name) {
036: super (name);
037: }
038:
039: /**
040: * Sets up the instance variables for each test case.
041: *
042: * @throws Exception when unable to complete a setup.
043: */
044: public void setUp() throws Exception {
045: // Directory separator
046: final String slash = File.separator;
047:
048: // original file
049: File dir = new File(System.getProperty("jblanket.data.dir"));
050: File originalDir = new File(dir, "unjar" + slash + "edu"
051: + slash + "hawaii" + slash + "stack");
052: File originalFile = new File(originalDir, "Stack.class");
053:
054: // input file
055: File inDir = new File(System.getProperty("jblanket.testdir"),
056: "testclassmodifier");
057: this .inFile = new File(inDir, "Stack.class");
058:
059: // copy original file to input file
060: FileUtils fileUtils = FileUtils.newFileUtils();
061: fileUtils.copyFile(originalFile, this .inFile);
062:
063: this .counter = new MethodCounter();
064: this .modifier = new ClassModifier(false, "Test*.class", true,
065: true, false, this .counter, this .inFile);
066: }
067:
068: /**
069: * Tests the modifyMethods and isModified methods.
070: */
071: public void testModifyMethods() {
072:
073: assertEquals("Checking if class already modified", false,
074: this .modifier.isModified());
075:
076: try {
077: this .modifier.modifyMethods();
078: } catch (Exception e) {
079: fail("Unable to store modified methods");
080: }
081:
082: assertEquals("Checking if class already modified", true,
083: this .modifier.isModified());
084: }
085:
086: /**
087: * Tests the excludeMethods method with the constructor
088: * ClassModifier(boolean, MethodCounter, File).
089: */
090: public void testExcludeMethods() {
091:
092: try {
093: this .modifier = new ClassModifier(false, this .counter,
094: this .inFile);
095: } catch (Exception e) {
096: fail("Unable to construct new object");
097: }
098:
099: this .modifier.excludeMethods();
100:
101: String fileName = MethodCategories.getInstance().getFileName(
102: "excludedFile");
103: MethodSet methodSet = MethodSetManager.getInstance()
104: .getMethodSet(fileName);
105: assertEquals("Checking size of exclude MethodSet", 8, methodSet
106: .size());
107: }
108: }
|