KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > incava > analysis > TestContextReport


1 package org.incava.analysis;
2
3 import java.io.*;
4 import java.util.*;
5 import junit.framework.TestCase;
6 import org.incava.qualog.ANSIColor;
7
8
9 public class TestContextReport extends TestCase
10 {
11     private final static String JavaDoc EOLN = System.getProperty("line.separator");
12
13     public TestContextReport(String JavaDoc name)
14     {
15         super(name);
16     }
17
18     public void testReportOrder()
19     {
20         StringWriter sw;
21         Report r;
22
23         String JavaDoc content = ("As fast as thou shalt wane, so fast thou grow'st\n" +
24                           "In one of thine, from that which thou departest;\n" +
25                           "And that fresh blood which youngly thou bestow'st,\r\n" +
26                           "Thou mayst call thine when thou from youth convertest.\n" +
27                           "Herein lives wisdom, beauty, and increase;\n" +
28                           "Without this folly, age, and cold decay:\r" +
29                           "If all were minded so, the times should cease\r" +
30                           "And threescore year would make the world away.\n" +
31                           "Let those whom nature hath not made for store,\n" +
32                           "Harsh, featureless, and rude, barrenly perish:\n" +
33                           "Look whom she best endow'd, she gave the more;\n" +
34                           "Which bounteous gift thou shouldst in bounty cherish:\n" +
35                           "She carv'd thee for her seal, and meant thereby,\n" +
36                           "Thou shouldst print more, not let that copy die.\n");
37         
38         sw = new StringWriter();
39         r = new ContextReport(sw, content);
40         
41         r.addViolation(new Violation("msg", 3, 5, 4, 6));
42         r.addViolation(new Violation("msg2", 5, 3, 6, 4));
43         assertEquals(2, r.getViolations().size());
44         r.flush();
45         
46         String JavaDoc str0 = sw.toString();
47         tr.Ace.log("str0: " + str0);
48
49         sw = new StringWriter();
50         r = new ContextReport(sw, content);
51         r.addViolation(new Violation("msg2", 5, 3, 6, 4));
52         r.addViolation(new Violation("msg", 3, 5, 4, 6));
53         assertEquals(2, r.getViolations().size());
54         r.flush();
55         
56         String JavaDoc str1 = sw.toString();
57         tr.Ace.log("str1: " + str1);
58
59         assertEquals("order of reported violations", str0, str1);
60     }
61
62     public void testSinglePointOutput()
63     {
64         String JavaDoc content = ("As fast as thou shalt wane, so fast thou grow'st\n" +
65                           "In one of thine, from that which thou departest;\n" +
66                           "And that fresh blood which youngly thou bestow'st,\r\n" +
67                           "Thou mayst call thine when thou from youth convertest.\n" +
68                           "Herein lives wisdom, beauty, and increase;\n" +
69                           "Without this folly, age, and cold decay:\r" +
70                           "If all were minded so, the times should cease\r" +
71                           "And threescore year would make the world away.\n" +
72                           "Let those whom nature hath not made for store,\n" +
73                           "Harsh, featureless, and rude, barrenly perish:\n" +
74                           "Look whom she best endow'd, she gave the more;\n" +
75                           "Which bounteous gift thou shouldst in bounty cherish:\n" +
76                           "She carv'd thee for her seal, and meant thereby,\n" +
77                           "Thou shouldst print more, not let that copy die.\n");
78         
79         StringWriter sw = new StringWriter();
80         Report r = new ContextReport(sw, content);
81         r.addViolation(new Violation("msg", 5, 9, 5, 9));
82         assertEquals(1, r.getViolations().size());
83         r.flush();
84         String JavaDoc str = sw.toString();
85         tr.Ace.log("str: " + str);
86         
87         // end of line gets "fixed" to whatever is appropriate for this system.
88
assertEquals("In " + ANSIColor.BOLD + ANSIColor.REVERSE + "-" + ANSIColor.RESET + ":" + EOLN + EOLN +
89                      " 5. Herein lives wisdom, beauty, and increase;" + EOLN +
90                      " ^" + EOLN +
91                      "*** msg" + EOLN +
92                      EOLN,
93                      str);
94     }
95
96     public void testSingleLineOutput()
97     {
98         String JavaDoc content = ("How heavy do I journey on the way,\n" +
99                           "When what I seek, my weary travel's end,\n" +
100                           "Doth teach that ease and that repose to say,\r" +
101                           "'Thus far the miles are measured from thy friend!'\n" +
102                           "The beast that bears me, tired with my woe,\r" +
103                           "Plods dully on, to bear that weight in me,\r\n" +
104                           "As if by some instinct the wretch did know\r" +
105                           "His rider lov'd not speed being made from thee.\n" +
106                           "The bloody spur cannot provoke him on,\n" +
107                           "That sometimes anger thrusts into his hide,\n" +
108                           "Which heavily he answers with a groan,\n" +
109                           "More sharp to me than spurring to his side;\n" +
110                           "For that same groan doth put this in my mind,\n" +
111                           "My grief lies onward, and my joy behind.\n");
112         
113         StringWriter sw = new StringWriter();
114         Report r = new ContextReport(sw, content);
115         r.addViolation(new Violation("msg", 10, 16, 10, 20));
116         assertEquals(1, r.getViolations().size());
117         r.flush();
118         String JavaDoc str = sw.toString();
119         tr.Ace.log("str: " + str);
120         
121         // end of line gets "fixed" to whatever is appropriate for this system.
122
assertEquals("In " + ANSIColor.BOLD + ANSIColor.REVERSE + "-" + ANSIColor.RESET + ":" + EOLN + EOLN +
123                      " 10. That sometimes anger thrusts into his hide," + EOLN +
124                      " <--->" + EOLN +
125                      "*** msg" + EOLN +
126                      EOLN,
127                      str);
128     }
129
130     public void testMultiLineOutput()
131     {
132         String JavaDoc content = ("Against that time, if ever that time come,\n" +
133                           "When I shall see thee frown on my defects,\r\n" +
134                           "When as thy love hath cast his utmost sum,\n" +
135                           "Called to that audit by advis'd respects;\r" +
136                           "Against that time when thou shalt strangely pass,\n" +
137                           "And scarcely greet me with that sun, thine eye,\n" +
138                           "When love, converted from the thing it was,\n" +
139                           "Shall reasons find of settled gravity;\n" +
140                           "Against that time do I ensconce me here,\n" +
141                           "Within the knowledge of mine own desert,\n" +
142                           "And this my hand, against my self uprear,\n" +
143                           "To guard the lawful reasons on thy part: \n" +
144                           "To leave poor me thou hast the strength of laws,\n" +
145                           "Since why to love I can allege no cause.\n");
146         
147         StringWriter sw = new StringWriter();
148         Report r = new ContextReport(sw, content);
149         r.addViolation(new Violation("msg", 2, 23, 8, 13));
150         assertEquals(1, r.getViolations().size());
151         r.flush();
152         String JavaDoc str = sw.toString();
153         tr.Ace.log("str: " + str);
154         
155         // end of line gets "fixed" to whatever is appropriate for this system.
156
assertEquals("In " + ANSIColor.BOLD + ANSIColor.REVERSE + "-" + ANSIColor.RESET + ":" + EOLN + EOLN +
157                      " <-------------------" + EOLN +
158                      " 2. When I shall see thee frown on my defects," + EOLN +
159                      " 3. When as thy love hath cast his utmost sum," + EOLN +
160                      " 4. Called to that audit by advis'd respects;" + EOLN +
161                      " 5. Against that time when thou shalt strangely pass," + EOLN +
162                      " 6. And scarcely greet me with that sun, thine eye," + EOLN +
163                      " 7. When love, converted from the thing it was," + EOLN +
164                      " 8. Shall reasons find of settled gravity;" + EOLN +
165                      " ------------>" + EOLN +
166                      "*** msg" + EOLN +
167                      EOLN,
168                      str);
169     }
170
171
172     public void testSingleLineWithTabs()
173     {
174         String JavaDoc content = ("\tMine eye hath play'd the painter and hath steel'd,\n" +
175                           "\tThy beauty's form in table of my heart;\n" +
176                           "\tMy body is the frame wherein 'tis held,\n" +
177                           "\tAnd perspective it is best painter's art.\r" +
178                           "\tFor through the painter must you see his skill,\n" +
179                           "\tTo find where your true image pictur'd lies,\n" +
180                           "\tWhich in my bosom's shop is hanging still,\r" +
181                           "\tThat hath his windows glazed with thine eyes.\n" +
182                           "\tNow see what good turns eyes for eyes have done:\n" +
183                           "\tMine eyes have drawn thy shape, and thine for me\r\n" +
184                           "\tAre windows to my breast, where-through the sun\n" +
185                           "\tDelights to peep, to gaze therein on thee; \n" +
186                           "\tYet eyes this cunning want to grace their art,\n" +
187                           "\tThey draw but what they see, know not the heart.\n");
188         
189         StringWriter sw = new StringWriter();
190         Report r = new ContextReport(sw, content);
191         r.addViolation(new Violation("msg", 2, 23, 2, 25));
192         assertEquals(1, r.getViolations().size());
193         r.flush();
194         String JavaDoc str = sw.toString();
195         tr.Ace.log("str: " + str);
196         
197         assertEquals("In " + ANSIColor.BOLD + ANSIColor.REVERSE + "-" + ANSIColor.RESET + ":" + EOLN + EOLN +
198                      " 2. \tThy beauty's form in table of my heart;" + EOLN +
199                      " <->" + EOLN +
200                      "*** msg" + EOLN +
201                      EOLN,
202                      str);
203     }
204
205 }
206
Popular Tags