|
1 |
| |
|
2 |
| |
|
3 |
| |
|
4 |
| |
|
5 |
| |
|
6 |
| |
|
7 |
| |
|
8 |
| |
|
9 |
| |
|
10 |
| |
|
11 |
| |
|
12 |
| |
|
13 |
| |
|
14 |
| |
|
15 |
| |
|
16 |
| |
|
17 |
| |
|
18 |
| |
|
19 |
| |
|
20 |
| |
|
21 |
| |
|
22 |
| package nu.xom.tests; |
|
23 |
| |
|
24 |
| import nu.xom.ParsingException; |
|
25 |
| |
|
26 |
| |
|
27 |
| |
|
28 |
| |
|
29 |
| |
|
30 |
| |
|
31 |
| |
|
32 |
| |
|
33 |
| |
|
34 |
| |
|
35 |
| public class ParsingExceptionTest extends XOMTestCase { |
|
36 |
| |
|
37 |
| |
|
38 |
| private ParsingException ex; |
|
39 |
| private Exception cause; |
|
40 |
| private String message = "testing 1-2-3"; |
|
41 |
| |
|
42 |
| |
|
43 |
11
| public ParsingExceptionTest(String name) {
|
|
44 |
11
| super(name);
|
|
45 |
| } |
|
46 |
| |
|
47 |
| |
|
48 |
11
| protected void setUp() {
|
|
49 |
11
| ex = new ParsingException("message");
|
|
50 |
11
| cause = new Exception();
|
|
51 |
| } |
|
52 |
| |
|
53 |
| |
|
54 |
1
| public void testConstructor() {
|
|
55 |
1
| ParsingException ex = new ParsingException(message, cause);
|
|
56 |
1
| assertEquals(message, ex.getMessage());
|
|
57 |
1
| assertEquals(cause, ex.getCause());
|
|
58 |
| } |
|
59 |
| |
|
60 |
| |
|
61 |
1
| public void testFourArgumentConstructor() {
|
|
62 |
| |
|
63 |
1
| ParsingException ex = new ParsingException(message, 100000, 400000, cause);
|
|
64 |
1
| assertEquals(message, ex.getMessage());
|
|
65 |
1
| assertEquals(cause, ex.getCause());
|
|
66 |
1
| assertEquals(100000, ex.getLineNumber());
|
|
67 |
1
| assertEquals(400000, ex.getColumnNumber());
|
|
68 |
| |
|
69 |
| } |
|
70 |
| |
|
71 |
| |
|
72 |
1
| public void testLineAndColumnNumbers() {
|
|
73 |
1
| ParsingException ex = new ParsingException(message, 10, 20);
|
|
74 |
1
| assertEquals(message, ex.getMessage());
|
|
75 |
1
| assertNull(ex.getCause());
|
|
76 |
1
| assertEquals(10, ex.getLineNumber());
|
|
77 |
1
| assertEquals(20, ex.getColumnNumber());
|
|
78 |
| } |
|
79 |
| |
|
80 |
| |
|
81 |
1
| public void testLineAndColumnNumbersInToString() {
|
|
82 |
1
| ParsingException ex = new ParsingException(message, -1, -1);
|
|
83 |
1
| String result = ex.toString();
|
|
84 |
1
| assertEquals(-1, result.indexOf("-1"));
|
|
85 |
| } |
|
86 |
| |
|
87 |
| |
|
88 |
1
| public void testToString() {
|
|
89 |
1
| ParsingException ex = new ParsingException(message, 10, 20);
|
|
90 |
1
| assertTrue(ex.toString().endsWith(" at line 10, column 20"));
|
|
91 |
| } |
|
92 |
| |
|
93 |
| |
|
94 |
1
| public void testInitCause() {
|
|
95 |
| |
|
96 |
1
| assertNull(ex.getCause());
|
|
97 |
1
| ex.initCause(cause);
|
|
98 |
1
| assertEquals(cause, ex.getCause());
|
|
99 |
| |
|
100 |
1
| try {
|
|
101 |
1
| ex.initCause(null);
|
|
102 |
0
| fail("Reinitialized cause over null");
|
|
103 |
| } |
|
104 |
| catch (IllegalStateException result) { |
|
105 |
| |
|
106 |
| } |
|
107 |
| |
|
108 |
1
| try {
|
|
109 |
1
| ex.initCause(new Exception());
|
|
110 |
0
| fail("Reinitialized cause over null");
|
|
111 |
| } |
|
112 |
| catch (IllegalStateException result) { |
|
113 |
| |
|
114 |
| } |
|
115 |
| |
|
116 |
| } |
|
117 |
| |
|
118 |
| |
|
119 |
1
| public void testNullInitCause() {
|
|
120 |
| |
|
121 |
1
| ParsingException ex = new ParsingException(null, null);
|
|
122 |
1
| assertNull(ex.getCause());
|
|
123 |
| |
|
124 |
1
| try {
|
|
125 |
1
| ex.initCause(new Exception());
|
|
126 |
0
| fail("Reinitialized cause over null");
|
|
127 |
| } |
|
128 |
| catch (IllegalStateException result) { |
|
129 |
| |
|
130 |
| } |
|
131 |
| |
|
132 |
1
| try {
|
|
133 |
1
| ex.initCause(null);
|
|
134 |
0
| fail("Reinitialized cause over null");
|
|
135 |
| } |
|
136 |
| catch (IllegalStateException result) { |
|
137 |
| |
|
138 |
| } |
|
139 |
| |
|
140 |
| } |
|
141 |
| |
|
142 |
| |
|
143 |
1
| public void testSelfCause() {
|
|
144 |
| |
|
145 |
1
| try {
|
|
146 |
1
| ex.initCause(ex);
|
|
147 |
0
| fail("Allowed self-causation");
|
|
148 |
| } |
|
149 |
| catch (IllegalArgumentException result) { |
|
150 |
| |
|
151 |
| } |
|
152 |
| |
|
153 |
| } |
|
154 |
| |
|
155 |
| |
|
156 |
1
| public void testGetMessage() {
|
|
157 |
1
| Exception ex = new ParsingException("testing");
|
|
158 |
1
| assertEquals("testing", ex.getMessage());
|
|
159 |
| } |
|
160 |
| |
|
161 |
| |
|
162 |
1
| public void testGetURI() {
|
|
163 |
| |
|
164 |
1
| ParsingException ex = new ParsingException("testing", "http://www.example.org/", 32, 24);
|
|
165 |
1
| assertEquals("http://www.example.org/", ex.getURI());
|
|
166 |
| |
|
167 |
1
| Exception cause = new Exception("test");
|
|
168 |
1
| ex = new ParsingException("testing", "http://www.example.org/", 32, 24, cause);
|
|
169 |
1
| assertEquals("http://www.example.org/", ex.getURI());
|
|
170 |
1
| assertEquals(cause, ex.getCause());
|
|
171 |
| |
|
172 |
| } |
|
173 |
| |
|
174 |
| |
|
175 |
1
| public void testURIInToString() {
|
|
176 |
| |
|
177 |
1
| ParsingException ex = new ParsingException("testing", "http://www.example.org/", 32, 24);
|
|
178 |
1
| assertTrue(ex.toString().indexOf("http://www.example.org/") > 1);
|
|
179 |
| |
|
180 |
| } |
|
181 |
| |
|
182 |
| |
|
183 |
| } |