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.canonical.CanonicalizationException;
025:
026: /**
027: * <p>
028: * Unit tests for the <code>CanonicalizationException</code> class.
029: * </p>
030: *
031: * @author Elliotte Rusty Harold
032: * @version 1.1d7
033: *
034: */
035: public class CanonicalizationExceptionTest extends XOMTestCase {
036:
037: private CanonicalizationException ex;
038: private Exception cause;
039:
040: public CanonicalizationExceptionTest(String name) {
041: super (name);
042: }
043:
044: protected void setUp() {
045: ex = new CanonicalizationException("message");
046: cause = new Exception();
047: }
048:
049: public void testConstructor() {
050: String message = "testing 1-2-3";
051: CanonicalizationException ex = new CanonicalizationException(
052: message);
053: assertEquals(message, ex.getMessage());
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: CanonicalizationException ex = new CanonicalizationException(
081: null);
082: ex.initCause(null);
083: assertNull(ex.getCause());
084:
085: try {
086: ex.initCause(new Exception());
087: fail("Reinitialized cause over null");
088: } catch (IllegalStateException success) {
089: assertNotNull(success.getMessage());
090: }
091:
092: try {
093: ex.initCause(null);
094: fail("Reinitialized cause over null");
095: } catch (IllegalStateException success) {
096: assertNotNull(success.getMessage());
097: }
098:
099: }
100:
101: public void testSelfCause() {
102:
103: try {
104: ex.initCause(ex);
105: fail("Allowed self-causation");
106: } catch (IllegalArgumentException success) {
107: assertNotNull(success.getMessage());
108: }
109:
110: }
111:
112: public void testGetMessage() {
113: Exception ex = new CanonicalizationException("testing");
114: assertEquals("testing", ex.getMessage());
115: }
116:
117: }
|