001: /* Copyright 2003, 2004 Elliotte Rusty Harold
002:
003: This library is free software; you can redistribute it and/or modify
004: it under the terms of version 2.1 of the GNU Lesser General Public
005: License as published by the Free Software Foundation.
006:
007: This library is distributed in the hope that it will be useful,
008: but WITHOUT ANY WARRANTY; without even the implied warranty of
009: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
010: GNU Lesser General Public License for more details.
011:
012: You should have received a copy of the GNU Lesser General Public
013: License along with this library; if not, write to the
014: Free Software Foundation, Inc., 59 Temple Place, Suite 330,
015: Boston, MA 02111-1307 USA
016:
017: You can contact Elliotte Rusty Harold by sending e-mail to
018: elharo@metalab.unc.edu. Please include the word "XOM" in the
019: subject line. The XOM home page is located at http://www.xom.nu/
020: */
021:
022: package nu.xom.tests;
023:
024: import nu.xom.ParsingException;
025:
026: /**
027: * <p>
028: * Unit tests for the <code>ParsingException</code> class.
029: * </p>
030: *
031: * @author Elliotte Rusty Harold
032: * @version 1.1b2
033: *
034: */
035: public class ParsingExceptionTest extends XOMTestCase {
036:
037: private ParsingException ex;
038: private Exception cause;
039: private String message = "testing 1-2-3";
040:
041: public ParsingExceptionTest(String name) {
042: super (name);
043: }
044:
045: protected void setUp() {
046: ex = new ParsingException("message");
047: cause = new Exception();
048: }
049:
050: public void testConstructor() {
051: ParsingException ex = new ParsingException(message, cause);
052: assertEquals(message, ex.getMessage());
053: assertEquals(cause, ex.getCause());
054: }
055:
056: public void testFourArgumentConstructor() {
057:
058: ParsingException ex = new ParsingException(message, 100000,
059: 400000, cause);
060: assertEquals(message, ex.getMessage());
061: assertEquals(cause, ex.getCause());
062: assertEquals(100000, ex.getLineNumber());
063: assertEquals(400000, ex.getColumnNumber());
064:
065: }
066:
067: public void testLineAndColumnNumbers() {
068: ParsingException ex = new ParsingException(message, 10, 20);
069: assertEquals(message, ex.getMessage());
070: assertNull(ex.getCause());
071: assertEquals(10, ex.getLineNumber());
072: assertEquals(20, ex.getColumnNumber());
073: }
074:
075: public void testLineAndColumnNumbersInToString() {
076: ParsingException ex = new ParsingException(message, -1, -1);
077: String result = ex.toString();
078: assertEquals(-1, result.indexOf("-1"));
079: }
080:
081: public void testToString() {
082: ParsingException ex = new ParsingException(message, 10, 20);
083: assertTrue(ex.toString().endsWith(" at line 10, column 20"));
084: }
085:
086: public void testInitCause() {
087:
088: assertNull(ex.getCause());
089: ex.initCause(cause);
090: assertEquals(cause, ex.getCause());
091:
092: try {
093: ex.initCause(null);
094: fail("Reinitialized cause over null");
095: } catch (IllegalStateException result) {
096: // success
097: }
098:
099: try {
100: ex.initCause(new Exception());
101: fail("Reinitialized cause over null");
102: } catch (IllegalStateException result) {
103: // success
104: }
105:
106: }
107:
108: public void testNullInitCause() {
109:
110: ParsingException ex = new ParsingException(null, null);
111: assertNull(ex.getCause());
112:
113: try {
114: ex.initCause(new Exception());
115: fail("Reinitialized cause over null");
116: } catch (IllegalStateException result) {
117: // success
118: }
119:
120: try {
121: ex.initCause(null);
122: fail("Reinitialized cause over null");
123: } catch (IllegalStateException result) {
124: // success
125: }
126:
127: }
128:
129: public void testSelfCause() {
130:
131: try {
132: ex.initCause(ex);
133: fail("Allowed self-causation");
134: } catch (IllegalArgumentException result) {
135: // success
136: }
137:
138: }
139:
140: public void testGetMessage() {
141: Exception ex = new ParsingException("testing");
142: assertEquals("testing", ex.getMessage());
143: }
144:
145: public void testGetURI() {
146:
147: ParsingException ex = new ParsingException("testing",
148: "http://www.example.org/", 32, 24);
149: assertEquals("http://www.example.org/", ex.getURI());
150:
151: Exception cause = new Exception("test");
152: ex = new ParsingException("testing", "http://www.example.org/",
153: 32, 24, cause);
154: assertEquals("http://www.example.org/", ex.getURI());
155: assertEquals(cause, ex.getCause());
156:
157: }
158:
159: public void testURIInToString() {
160:
161: ParsingException ex = new ParsingException("testing",
162: "http://www.example.org/", 32, 24);
163: assertTrue(ex.toString().indexOf("http://www.example.org/") > 1);
164:
165: }
166:
167: }
|