~ubuntu-branches/ubuntu/precise/xom/precise

« back to all changes in this revision

Viewing changes to src/nu/xom/tests/ParsingExceptionTest.java

  • Committer: Bazaar Package Importer
  • Author(s): Varun Hiremath
  • Date: 2007-11-25 15:50:40 UTC
  • Revision ID: james.westby@ubuntu.com-20071125155040-r75ikcqf1vu0cei7
Tags: upstream-1.1
ImportĀ upstreamĀ versionĀ 1.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright 2003, 2004 Elliotte Rusty Harold
 
2
   
 
3
   This library is free software; you can redistribute it and/or modify
 
4
   it under the terms of version 2.1 of the GNU Lesser General Public 
 
5
   License as published by the Free Software Foundation.
 
6
   
 
7
   This library is distributed in the hope that it will be useful,
 
8
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
9
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
 
10
   GNU Lesser General Public License for more details.
 
11
   
 
12
   You should have received a copy of the GNU Lesser General Public
 
13
   License along with this library; if not, write to the 
 
14
   Free Software Foundation, Inc., 59 Temple Place, Suite 330, 
 
15
   Boston, MA 02111-1307  USA
 
16
   
 
17
   You can contact Elliotte Rusty Harold by sending e-mail to
 
18
   elharo@metalab.unc.edu. Please include the word "XOM" in the
 
19
   subject line. The XOM home page is located at http://www.xom.nu/
 
20
*/
 
21
 
 
22
package nu.xom.tests;
 
23
 
 
24
import nu.xom.ParsingException;
 
25
 
 
26
/**
 
27
 * <p>
 
28
 *   Unit tests for the <code>ParsingException</code> class.
 
29
 * </p>
 
30
 * 
 
31
 * @author Elliotte Rusty Harold
 
32
 * @version 1.1b2
 
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
    public ParsingExceptionTest(String name) {
 
44
        super(name);
 
45
    }
 
46
    
 
47
    
 
48
    protected void setUp() {
 
49
        ex = new ParsingException("message");
 
50
        cause = new Exception();
 
51
    }
 
52
 
 
53
    
 
54
    public void testConstructor() {
 
55
        ParsingException ex = new ParsingException(message, cause);
 
56
        assertEquals(message, ex.getMessage());
 
57
        assertEquals(cause, ex.getCause()); 
 
58
    }
 
59
    
 
60
    
 
61
    public void testFourArgumentConstructor() {
 
62
            
 
63
        ParsingException ex = new ParsingException(message, 100000, 400000, cause);
 
64
        assertEquals(message, ex.getMessage());
 
65
        assertEquals(cause, ex.getCause()); 
 
66
        assertEquals(100000, ex.getLineNumber()); 
 
67
        assertEquals(400000, ex.getColumnNumber()); 
 
68
 
 
69
    }
 
70
    
 
71
    
 
72
    public void testLineAndColumnNumbers() {
 
73
        ParsingException ex = new ParsingException(message, 10, 20);
 
74
        assertEquals(message, ex.getMessage());
 
75
        assertNull(ex.getCause());
 
76
        assertEquals(10, ex.getLineNumber()); 
 
77
        assertEquals(20, ex.getColumnNumber()); 
 
78
    }
 
79
    
 
80
    
 
81
    public void testLineAndColumnNumbersInToString() {
 
82
        ParsingException ex = new ParsingException(message, -1, -1);
 
83
        String result = ex.toString();
 
84
        assertEquals(-1, result.indexOf("-1"));
 
85
    }
 
86
    
 
87
    
 
88
    public void testToString() {
 
89
        ParsingException ex = new ParsingException(message, 10, 20);
 
90
        assertTrue(ex.toString().endsWith(" at line 10, column 20")); 
 
91
    }
 
92
    
 
93
    
 
94
    public void testInitCause() {
 
95
        
 
96
        assertNull(ex.getCause());
 
97
        ex.initCause(cause);
 
98
        assertEquals(cause, ex.getCause());
 
99
        
 
100
        try {
 
101
            ex.initCause(null);   
 
102
            fail("Reinitialized cause over null");   
 
103
        }
 
104
        catch (IllegalStateException result) {
 
105
            // success   
 
106
        }
 
107
        
 
108
        try {
 
109
            ex.initCause(new Exception());   
 
110
            fail("Reinitialized cause over null");   
 
111
        }
 
112
        catch (IllegalStateException result) {
 
113
            // success   
 
114
        }
 
115
        
 
116
    }
 
117
 
 
118
 
 
119
    public void testNullInitCause() {
 
120
        
 
121
        ParsingException ex = new ParsingException(null, null);
 
122
        assertNull(ex.getCause());
 
123
        
 
124
        try {
 
125
            ex.initCause(new Exception());
 
126
            fail("Reinitialized cause over null");   
 
127
        }
 
128
        catch (IllegalStateException result) {
 
129
            // success   
 
130
        }
 
131
 
 
132
        try {
 
133
            ex.initCause(null);   
 
134
            fail("Reinitialized cause over null");   
 
135
        }
 
136
        catch (IllegalStateException result) {
 
137
            // success   
 
138
        }
 
139
        
 
140
    }
 
141
 
 
142
    
 
143
    public void testSelfCause() {
 
144
        
 
145
        try {
 
146
            ex.initCause(ex);   
 
147
            fail("Allowed self-causation");   
 
148
        }
 
149
        catch (IllegalArgumentException result) {
 
150
            // success   
 
151
        }
 
152
        
 
153
    }
 
154
 
 
155
    
 
156
    public void testGetMessage() {      
 
157
        Exception ex = new ParsingException("testing");
 
158
        assertEquals("testing", ex.getMessage());
 
159
    }
 
160
 
 
161
    
 
162
    public void testGetURI() { 
 
163
        
 
164
        ParsingException ex = new ParsingException("testing", "http://www.example.org/", 32, 24);
 
165
        assertEquals("http://www.example.org/", ex.getURI());
 
166
        
 
167
        Exception cause = new Exception("test");
 
168
        ex = new ParsingException("testing", "http://www.example.org/", 32, 24, cause);
 
169
        assertEquals("http://www.example.org/", ex.getURI());
 
170
        assertEquals(cause, ex.getCause());
 
171
        
 
172
    }
 
173
 
 
174
    
 
175
    public void testURIInToString() { 
 
176
        
 
177
        ParsingException ex = new ParsingException("testing", "http://www.example.org/", 32, 24);
 
178
        assertTrue(ex.toString().indexOf("http://www.example.org/") > 1);
 
179
        
 
180
    }
 
181
 
 
182
    
 
183
}