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