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: import nu.xom.ValidityException;
026:
027: /**
028: * <p>
029: * Unit tests for the <code>ValidityException</code> class.
030: * </p>
031: *
032: * @author Elliotte Rusty Harold
033: * @version 1.0
034: *
035: */
036: public class ValidityExceptionTest extends XOMTestCase {
037:
038: private ValidityException ex = new ValidityException("message");
039: private Exception cause = new Exception();
040: private String message = "testing 1-2-3";
041:
042: public ValidityExceptionTest(String name) {
043: super (name);
044: }
045:
046: public void testConstructor() {
047: ParsingException ex = new ValidityException(message, cause);
048: assertEquals(message, ex.getMessage());
049: assertEquals(cause, ex.getCause());
050: }
051:
052: public void testFourArgumentConstructor() {
053:
054: ParsingException ex = new ValidityException(message, 10000,
055: 40000, cause);
056: assertEquals(message, ex.getMessage());
057: assertEquals(cause, ex.getCause());
058: assertEquals(10000, ex.getLineNumber());
059: assertEquals(40000, ex.getColumnNumber());
060:
061: }
062:
063: public void testAnotherFourArgumentConstructor() {
064:
065: ParsingException ex = new ValidityException(message,
066: "http://www.example.com/", 10000, 40000);
067: assertEquals(message, ex.getMessage());
068: assertNull(ex.getCause());
069: assertEquals(10000, ex.getLineNumber());
070: assertEquals(40000, ex.getColumnNumber());
071: assertEquals("http://www.example.com/", ex.getURI());
072:
073: }
074:
075: public void testLineAndColumnNumbers() {
076:
077: ValidityException ex = new ValidityException(message, 10, 20);
078: assertEquals(message, ex.getMessage());
079: assertNull(ex.getCause());
080: assertEquals(10, ex.getLineNumber());
081: assertEquals(20, ex.getColumnNumber());
082:
083: }
084:
085: public void testInitCause() {
086:
087: assertNull(ex.getCause());
088: ex.initCause(cause);
089: assertEquals(cause, ex.getCause());
090:
091: try {
092: ex.initCause(null);
093: fail("Reinitialized cause over null");
094: } catch (IllegalStateException success) {
095: // success
096: }
097:
098: try {
099: ex.initCause(new Exception());
100: fail("Reinitialized cause over null");
101: } catch (IllegalStateException success) {
102: // success
103: }
104:
105: }
106:
107: public void testNullInitCause() {
108:
109: ValidityException ex = new ValidityException(null, null);
110: assertNull(ex.getCause());
111: assertNull(ex.getMessage());
112: assertEquals(-1, ex.getLineNumber());
113: assertEquals(-1, ex.getColumnNumber());
114:
115: try {
116: ex.initCause(new Exception());
117: fail("Reinitialized cause over null");
118: } catch (IllegalStateException result) {
119: // success
120: }
121:
122: try {
123: ex.initCause(null);
124: fail("Reinitialized cause over null");
125: } catch (IllegalStateException result) {
126: // success
127: }
128:
129: }
130:
131: public void testSelfCause() {
132:
133: try {
134: ex.initCause(ex);
135: fail("Allowed self-causation");
136: } catch (IllegalArgumentException result) {
137: // success
138: }
139:
140: }
141:
142: public void testGetMessage() {
143: Exception ex = new ValidityException("testing");
144: assertEquals("testing", ex.getMessage());
145: }
146:
147: }
|