KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jester > makealljesterchanges > MakeAllJesterChangesTest


1 package jester.makealljesterchanges;
2
3 import java.io.BufferedWriter JavaDoc;
4 import java.io.File JavaDoc;
5 import java.io.FileWriter JavaDoc;
6 import java.io.IOException JavaDoc;
7
8 import junit.framework.TestCase;
9
10 /*
11  * Created on 19-Feb-2005
12  *
13  */

14
15 /**
16  * @author Simon Lever
17  *
18  * JUnit test case that contains all the tests performed on the
19  * MakeAllJesterChanges object
20  */

21 public class MakeAllJesterChangesTest extends TestCase {
22
23     /*
24      * private test variables (not really needed as all methods in the class
25      * under test are static, but good to have in case instance methods are
26      * added in the future and thus corresponding tests should be added here).
27      */

28     MakeAllJesterChanges changeObject = null;
29
30     /**
31      * Main method for running tests via the command line
32      *
33      * @param args
34      */

35     public static void main(String JavaDoc args[]) {
36         junit.textui.TestRunner.run(MakeAllJesterChangesTest.class);
37     }
38
39     /*
40      * Called before every test
41      *
42      * @see TestCase#setUp()
43      */

44     protected void setUp() throws Exception JavaDoc {
45         super.setUp();
46         //create a reference for the changeObject
47
changeObject = new MakeAllJesterChanges();
48     }
49
50     /*
51      * Called after every test
52      *
53      * @see TestCase#tearDown()
54      */

55     protected void tearDown() throws Exception JavaDoc {
56         super.tearDown();
57         changeObject = null; //reset the object to have no reference
58
}
59
60     /*
61      * makes sure that the algorithm fails if the "jesterReport.xml" file is not
62      * in the same directory as the MakeAllJesterChanges class file
63      */

64     public void testMainAndParseXMLAndApplyChangesFileNotFoundException() {
65         MakeAllJesterChanges.main(null);
66         /*
67          * if we get here the FileNotFoundException was caught and handled and
68          * hence the algorithm is correctly handling this error condition
69          */

70         assertTrue("The FileNotFoundException was not caught and dealt "
71                 + "with if you can see this message", true);
72     }
73
74     /*
75      * makes sure that the MakeAllJesterChanges.parseFileName(String) is
76      * correctly functioning
77      */

78     public void testParseFileName() {
79         String JavaDoc testString = "directory/folder/file.java";
80         String JavaDoc returnString = MakeAllJesterChanges.parseFileName(testString);
81         /*
82          * if working then the path should be maintained with only the .java
83          * replaced by .jester
84          */

85         assertEquals("directory/folder/file.jester", returnString);
86     }
87
88     /*
89      * tests the MakeAllJesterChanges.getContents(File) method where the file
90      * exists
91      */

92     public void testGetContentsWhereFileExists() throws IOException JavaDoc {
93         //create a file with some contents
94
File JavaDoc file = new File JavaDoc("aFile.file");
95         BufferedWriter JavaDoc newOutBuff = new BufferedWriter JavaDoc(new FileWriter JavaDoc(file));
96         newOutBuff
97                 .write("This is some contents written by a BufferedWriter...");
98         newOutBuff.close(); //close the buffer
99

100         //invoke the getContents method
101
String JavaDoc returnString = MakeAllJesterChanges.getContents(file);
102
103         /*
104          * make sure that the Strings are equal where in fact the getContents
105          * method should append on a native OS newline character on the end
106          */

107         assertEquals("This is some contents written by a BufferedWriter..."
108                 + System.getProperty("line.separator"), returnString);
109
110         //make sure that the file is then deleted
111
file.delete();
112     }
113 }
Popular Tags