KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jester > tests > ReportItemTest


1 package jester.tests;
2
3 import jester.*;
4 import jester.ReportItem;
5 import jester.SourceChangeException;
6 import junit.framework.*;
7
8 public class ReportItemTest extends TestCase {
9     public ReportItemTest(String JavaDoc name) {
10         super(name);
11     }
12     public static void main(String JavaDoc args[]) {
13         junit.awtui.TestRunner.main(new String JavaDoc[] { "jester.tests.ReportItemTest" });
14     }
15     public static Test suite() {
16         TestSuite suite = new TestSuite(ReportItemTest.class);
17         return suite;
18     }
19
20     private ReportItem newReportItem(String JavaDoc originalContents, String JavaDoc from, String JavaDoc to, int indexOfChange) throws ConfigurationException {
21         return new ReportItem("sourceFileName", new IgnoreListDocument(originalContents,new IgnoreList("")), indexOfChange, from, to);
22     }
23     private int lineNumberForCharacterIndex(String JavaDoc originalContents, int indexOfChange) throws ConfigurationException {
24         return newReportItem(originalContents, "from", "to", indexOfChange).lineNumber();
25     }
26     public void testXmlEncoding() throws ConfigurationException {
27         String JavaDoc fromSomethingThatNeedsXmlEncoding = "< > & \"";
28         String JavaDoc toSomethingThatNeedsXmlEncoding = fromSomethingThatNeedsXmlEncoding;
29         String JavaDoc theSameThingXmlEncoded = "&lt; &gt; &amp; &quot;";
30         String JavaDoc expectedXML = "<ChangeThatDidNotCauseTestsToFail index=\"3\" from=\""+
31                                 theSameThingXmlEncoded+
32                                 "\" to=\""+
33                                 theSameThingXmlEncoded+"\"/>";
34         String JavaDoc actualXML = newReportItem("originalContents", fromSomethingThatNeedsXmlEncoding, toSomethingThatNeedsXmlEncoding, 3).asXML();
35         assertEquals("should encode as XML as appropriate",expectedXML,actualXML);
36     }
37
38     public void testLineNumberOneLine() throws SourceChangeException {
39         String JavaDoc oneLine = "some text";
40         int indexOnOneLine = 3;
41         assertEquals("on one line", 1, lineNumberForCharacterIndex(oneLine, indexOnOneLine));
42
43         int nonExistant = -1;
44         assertEquals("non-existant", -1, lineNumberForCharacterIndex(oneLine, nonExistant));
45
46         int pastEnd = 9;
47         assertEquals("past end", -1, lineNumberForCharacterIndex(oneLine, pastEnd));
48     }
49
50     public void testLineNumberSomeLines() throws SourceChangeException {
51         String JavaDoc someLines = "once upon a time\nin a land far far away\nthere lived a giant";
52         int onFirstLine = 3;
53         assertEquals("on first line", 1, lineNumberForCharacterIndex(someLines, onFirstLine));
54
55         int onSecondLine = 18;
56         assertEquals("on second line", 2, lineNumberForCharacterIndex(someLines, onSecondLine));
57
58         int onThirdLine = 42;
59         assertEquals("on third line", 3, lineNumberForCharacterIndex(someLines, onThirdLine));
60     }
61 }
Popular Tags