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.xslt.XSLException;
025:
026: /**
027: * <p>
028: * Unit tests for the <code>XSLException</code> class.
029: * </p>
030: *
031: * @author Elliotte Rusty Harold
032: * @version 1.1d2
033: *
034: */
035: public class XSLExceptionTest extends XOMTestCase {
036:
037: private XSLException ex;
038: private Exception cause;
039:
040: public XSLExceptionTest(String name) {
041: super (name);
042: }
043:
044: protected void setUp() {
045: ex = new XSLException("message");
046: cause = new Exception();
047: }
048:
049: public void testConstructor() {
050: String message = "testing 1-2-3";
051: XSLException ex = new XSLException(message, cause);
052: assertEquals(message, ex.getMessage());
053: assertEquals(cause, ex.getCause());
054: }
055:
056: public void testInitCause() {
057:
058: assertNull(ex.getCause());
059: ex.initCause(cause);
060: assertEquals(cause, ex.getCause());
061:
062: try {
063: ex.initCause(null);
064: fail("Reinitialized cause over null");
065: } catch (IllegalStateException success) {
066: assertNotNull(success.getMessage());
067: }
068:
069: try {
070: ex.initCause(new Exception());
071: fail("Reinitialized cause over null");
072: } catch (IllegalStateException success) {
073: assertNotNull(success.getMessage());
074: }
075:
076: }
077:
078: public void testNullInitCause() {
079:
080: XSLException ex = new XSLException(null, null);
081: assertNull(ex.getCause());
082:
083: try {
084: ex.initCause(new Exception());
085: fail("Reinitialized cause over null");
086: } catch (IllegalStateException success) {
087: assertNotNull(success.getMessage());
088: }
089:
090: try {
091: ex.initCause(null);
092: fail("Reinitialized cause over null");
093: } catch (IllegalStateException success) {
094: assertNotNull(success.getMessage());
095: }
096:
097: }
098:
099: public void testSelfCause() {
100:
101: try {
102: ex.initCause(ex);
103: fail("Allowed self-causation");
104: } catch (IllegalArgumentException success) {
105: assertNotNull(success.getMessage());
106: }
107:
108: }
109:
110: public void testGetMessage() {
111: Exception ex = new XSLException("testing");
112: assertEquals("testing", ex.getMessage());
113: }
114:
115: }
|