001: /*
002: * Copyright (C) The DNA Group. All rights reserved.
003: *
004: * This software is published under the terms of the DNA
005: * Software License version 1.1, a copy of which has been included
006: * with this distribution in the LICENSE.txt file.
007: */
008: package org.codehaus.dna;
009:
010: import org.codehaus.dna.ConfigurationException;
011:
012: import junit.framework.TestCase;
013:
014: /**
015: *
016: * @author Peter Donald
017: * @version $Revision: 1.2 $ $Date: 2004/05/01 09:51:48 $
018: */
019: public class ConfigurationExceptionTestCase extends TestCase {
020: public void testConfigurationExceptionConstruction()
021: throws Exception {
022: final String message = "myMessage";
023: final String path = "/my/path";
024: final String location = "mylocation.xml:20";
025: final Throwable cause = new Throwable();
026: final ConfigurationException exception = new ConfigurationException(
027: message, path, location, cause);
028:
029: assertEquals("message", message, exception.getMessage());
030: assertEquals("path", path, exception.getPath());
031: assertEquals("location", location, exception.getLocation());
032: assertEquals("cause", cause, exception.getCause());
033: }
034:
035: public void testConfigurationExceptionConstructionWithNullCause()
036: throws Exception {
037: final String message = "myMessage";
038: final String path = "/my/path";
039: final String location = "mylocation.xml:20";
040: final Throwable cause = null;
041: final ConfigurationException exception = new ConfigurationException(
042: message, path, location, cause);
043:
044: assertEquals("message", message, exception.getMessage());
045: assertEquals("path", path, exception.getPath());
046: assertEquals("location", location, exception.getLocation());
047: assertEquals("cause", cause, exception.getCause());
048: }
049:
050: public void testConfigurationExceptionConstructionWithNullKey()
051: throws Exception {
052: final String message = "myMessage";
053: final String path = null;
054: final String location = "mylocation.xml:20";
055: final Throwable cause = new Throwable();
056: final ConfigurationException exception = new ConfigurationException(
057: message, path, location, cause);
058:
059: assertEquals("message", message, exception.getMessage());
060: assertEquals("path", path, exception.getPath());
061: assertEquals("location", location, exception.getLocation());
062: assertEquals("cause", cause, exception.getCause());
063: }
064:
065: public void testConfigurationExceptionConstructionWithNullMessage()
066: throws Exception {
067: final String message = null;
068: final String path = "/my/path";
069: final String location = "mylocation.xml:20";
070: final Throwable cause = new Throwable();
071: final ConfigurationException exception = new ConfigurationException(
072: message, path, location, cause);
073:
074: assertEquals("message", message, exception.getMessage());
075: assertEquals("path", path, exception.getPath());
076: assertEquals("location", location, exception.getLocation());
077: assertEquals("cause", cause, exception.getCause());
078: }
079:
080: public void testConfigurationExceptionConstructionWithNullLocation()
081: throws Exception {
082: final String message = "myMessage";
083: final String path = "/my/path";
084: final String location = null;
085: final Throwable cause = new Throwable();
086: final ConfigurationException exception = new ConfigurationException(
087: message, path, location, cause);
088:
089: assertEquals("message", message, exception.getMessage());
090: assertEquals("path", path, exception.getPath());
091: assertEquals("location", location, exception.getLocation());
092: assertEquals("cause", cause, exception.getCause());
093: }
094:
095: public void testConfigurationExceptionConstructionWith3ArgCtor()
096: throws Exception {
097: final String message = "myMessage";
098: final String path = "/my/path";
099: final String location = "mylocation.xml:20";
100: final ConfigurationException exception = new ConfigurationException(
101: message, path, location);
102:
103: assertEquals("message", message, exception.getMessage());
104: assertEquals("path", path, exception.getPath());
105: assertEquals("location", location, exception.getLocation());
106: assertEquals("cause", null, exception.getCause());
107: }
108:
109: public void testConfigurationExceptionConstructionWith2ArgCtor()
110: throws Exception {
111: final String message = "myMessage";
112: final Throwable cause = new Throwable();
113: final ConfigurationException exception = new ConfigurationException(
114: message, cause);
115:
116: assertEquals("message", message, exception.getMessage());
117: assertEquals("path", null, exception.getPath());
118: assertEquals("location", null, exception.getLocation());
119: assertEquals("cause", cause, exception.getCause());
120: }
121:
122: public void testConfigurationExceptionToString() throws Exception {
123: final String path = "/my/path";
124: final String location = "mylocation.xml:20";
125: final ConfigurationException exception = new ConfigurationException(
126: "myMessage", path, location);
127:
128: final String expected = "org.codehaus.dna.ConfigurationException: myMessage"
129: + " - " + path + " @ " + location;
130:
131: assertEquals(expected, exception.toString());
132: }
133:
134: public void testConfigurationExceptionToStringWithNullPath()
135: throws Exception {
136: final String location = "mylocation.xml:20";
137: final ConfigurationException exception = new ConfigurationException(
138: "myMessage", null, location);
139:
140: final String expected = "org.codehaus.dna.ConfigurationException: myMessage"
141: + " @ " + location;
142:
143: assertEquals(expected, exception.toString());
144: }
145:
146: public void testConfigurationExceptionToStringWithNullLocation()
147: throws Exception {
148: final String path = "/my/path";
149: final ConfigurationException exception = new ConfigurationException(
150: "myMessage", path, null);
151:
152: final String expected = "org.codehaus.dna.ConfigurationException: myMessage"
153: + " - " + path;
154:
155: assertEquals(expected, exception.toString());
156: }
157:
158: public void testConfigurationExceptionToStringWithNullLocationAndPath()
159: throws Exception {
160: final ConfigurationException exception = new ConfigurationException(
161: "myMessage", null, null);
162:
163: final String expected = "org.codehaus.dna.ConfigurationException: myMessage";
164:
165: assertEquals(expected, exception.toString());
166: }
167:
168: public void testConfigurationExceptionToStringWithEmptyPath()
169: throws Exception {
170: final String location = "mylocation.xml:20";
171: final ConfigurationException exception = new ConfigurationException(
172: "myMessage", "", location);
173:
174: final String expected = "org.codehaus.dna.ConfigurationException: myMessage"
175: + " @ " + location;
176:
177: assertEquals(expected, exception.toString());
178: }
179:
180: public void testConfigurationExceptionToStringWithEmptyLocation()
181: throws Exception {
182: final String path = "/my/path";
183: final ConfigurationException exception = new ConfigurationException(
184: "myMessage", path, "");
185:
186: final String expected = "org.codehaus.dna.ConfigurationException: myMessage"
187: + " - " + path;
188:
189: assertEquals(expected, exception.toString());
190: }
191:
192: public void testConfigurationExceptionToStringWithEmptyLocationAndPath()
193: throws Exception {
194: final ConfigurationException exception = new ConfigurationException(
195: "myMessage", "", "");
196:
197: final String expected = "org.codehaus.dna.ConfigurationException: myMessage";
198:
199: assertEquals(expected, exception.toString());
200: }
201: }
|