KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > codehaus > dna > ConfigurationExceptionTestCase


1 /*
2  * Copyright (C) The DNA Group. All rights reserved.
3  *
4  * This software is published under the terms of the DNA
5  * Software License version 1.1, a copy of which has been included
6  * with this distribution in the LICENSE.txt file.
7  */

8 package org.codehaus.dna;
9
10 import org.codehaus.dna.ConfigurationException;
11
12 import junit.framework.TestCase;
13
14 /**
15  *
16  * @author Peter Donald
17  * @version $Revision: 1.2 $ $Date: 2004/05/01 09:51:48 $
18  */

19 public class ConfigurationExceptionTestCase
20     extends TestCase
21 {
22     public void testConfigurationExceptionConstruction()
23         throws Exception JavaDoc
24     {
25         final String JavaDoc message = "myMessage";
26         final String JavaDoc path = "/my/path";
27         final String JavaDoc location = "mylocation.xml:20";
28         final Throwable JavaDoc cause = new Throwable JavaDoc();
29         final ConfigurationException exception =
30             new ConfigurationException( message, path, location, cause );
31
32         assertEquals( "message", message, exception.getMessage() );
33         assertEquals( "path", path, exception.getPath() );
34         assertEquals( "location", location, exception.getLocation() );
35         assertEquals( "cause", cause, exception.getCause() );
36     }
37
38     public void testConfigurationExceptionConstructionWithNullCause()
39         throws Exception JavaDoc
40     {
41         final String JavaDoc message = "myMessage";
42         final String JavaDoc path = "/my/path";
43         final String JavaDoc location = "mylocation.xml:20";
44         final Throwable JavaDoc cause = null;
45         final ConfigurationException exception =
46             new ConfigurationException( message, path, location, cause );
47
48         assertEquals( "message", message, exception.getMessage() );
49         assertEquals( "path", path, exception.getPath() );
50         assertEquals( "location", location, exception.getLocation() );
51         assertEquals( "cause", cause, exception.getCause() );
52     }
53
54     public void testConfigurationExceptionConstructionWithNullKey()
55         throws Exception JavaDoc
56     {
57         final String JavaDoc message = "myMessage";
58         final String JavaDoc path = null;
59         final String JavaDoc location = "mylocation.xml:20";
60         final Throwable JavaDoc cause = new Throwable JavaDoc();
61         final ConfigurationException exception =
62             new ConfigurationException( message, path, location, cause );
63
64         assertEquals( "message", message, exception.getMessage() );
65         assertEquals( "path", path, exception.getPath() );
66         assertEquals( "location", location, exception.getLocation() );
67         assertEquals( "cause", cause, exception.getCause() );
68     }
69
70     public void testConfigurationExceptionConstructionWithNullMessage()
71         throws Exception JavaDoc
72     {
73         final String JavaDoc message = null;
74         final String JavaDoc path = "/my/path";
75         final String JavaDoc location = "mylocation.xml:20";
76         final Throwable JavaDoc cause = new Throwable JavaDoc();
77         final ConfigurationException exception =
78             new ConfigurationException( message, path, location, cause );
79
80         assertEquals( "message", message, exception.getMessage() );
81         assertEquals( "path", path, exception.getPath() );
82         assertEquals( "location", location, exception.getLocation() );
83         assertEquals( "cause", cause, exception.getCause() );
84     }
85
86     public void testConfigurationExceptionConstructionWithNullLocation()
87         throws Exception JavaDoc
88     {
89         final String JavaDoc message = "myMessage";
90         final String JavaDoc path = "/my/path";
91         final String JavaDoc location = null;
92         final Throwable JavaDoc cause = new Throwable JavaDoc();
93         final ConfigurationException exception =
94             new ConfigurationException( message, path, location, cause );
95
96         assertEquals( "message", message, exception.getMessage() );
97         assertEquals( "path", path, exception.getPath() );
98         assertEquals( "location", location, exception.getLocation() );
99         assertEquals( "cause", cause, exception.getCause() );
100     }
101
102     public void testConfigurationExceptionConstructionWith3ArgCtor()
103         throws Exception JavaDoc
104     {
105         final String JavaDoc message = "myMessage";
106         final String JavaDoc path = "/my/path";
107         final String JavaDoc location = "mylocation.xml:20";
108         final ConfigurationException exception =
109             new ConfigurationException( message, path, location );
110
111         assertEquals( "message", message, exception.getMessage() );
112         assertEquals( "path", path, exception.getPath() );
113         assertEquals( "location", location, exception.getLocation() );
114         assertEquals( "cause", null, exception.getCause() );
115     }
116
117     public void testConfigurationExceptionConstructionWith2ArgCtor()
118         throws Exception JavaDoc
119     {
120         final String JavaDoc message = "myMessage";
121         final Throwable JavaDoc cause = new Throwable JavaDoc();
122         final ConfigurationException exception =
123             new ConfigurationException( message, cause );
124
125         assertEquals( "message", message, exception.getMessage() );
126         assertEquals( "path", null, exception.getPath() );
127         assertEquals( "location", null, exception.getLocation() );
128         assertEquals( "cause", cause, exception.getCause() );
129     }
130
131     public void testConfigurationExceptionToString()
132         throws Exception JavaDoc
133     {
134         final String JavaDoc path = "/my/path";
135         final String JavaDoc location = "mylocation.xml:20";
136         final ConfigurationException exception =
137             new ConfigurationException( "myMessage", path, location );
138
139         final String JavaDoc expected =
140             "org.codehaus.dna.ConfigurationException: myMessage" +
141             " - " + path +
142             " @ " + location;
143
144         assertEquals( expected, exception.toString() );
145     }
146
147     public void testConfigurationExceptionToStringWithNullPath()
148         throws Exception JavaDoc
149     {
150         final String JavaDoc location = "mylocation.xml:20";
151         final ConfigurationException exception =
152             new ConfigurationException( "myMessage", null, location );
153
154         final String JavaDoc expected =
155             "org.codehaus.dna.ConfigurationException: myMessage" +
156             " @ " + location;
157
158         assertEquals( expected, exception.toString() );
159     }
160
161     public void testConfigurationExceptionToStringWithNullLocation()
162         throws Exception JavaDoc
163     {
164         final String JavaDoc path = "/my/path";
165         final ConfigurationException exception =
166             new ConfigurationException( "myMessage", path, null );
167
168         final String JavaDoc expected =
169             "org.codehaus.dna.ConfigurationException: myMessage" +
170             " - " + path;
171
172         assertEquals( expected, exception.toString() );
173     }
174
175     public void testConfigurationExceptionToStringWithNullLocationAndPath()
176         throws Exception JavaDoc
177     {
178         final ConfigurationException exception =
179             new ConfigurationException( "myMessage", null, null );
180
181         final String JavaDoc expected =
182             "org.codehaus.dna.ConfigurationException: myMessage";
183
184         assertEquals( expected, exception.toString() );
185     }
186
187     public void testConfigurationExceptionToStringWithEmptyPath()
188         throws Exception JavaDoc
189     {
190         final String JavaDoc location = "mylocation.xml:20";
191         final ConfigurationException exception =
192             new ConfigurationException( "myMessage", "", location );
193
194         final String JavaDoc expected =
195             "org.codehaus.dna.ConfigurationException: myMessage" +
196             " @ " + location;
197
198         assertEquals( expected, exception.toString() );
199     }
200
201     public void testConfigurationExceptionToStringWithEmptyLocation()
202         throws Exception JavaDoc
203     {
204         final String JavaDoc path = "/my/path";
205         final ConfigurationException exception =
206             new ConfigurationException( "myMessage", path, "" );
207
208         final String JavaDoc expected =
209             "org.codehaus.dna.ConfigurationException: myMessage" +
210             " - " + path;
211
212         assertEquals( expected, exception.toString() );
213     }
214
215     public void testConfigurationExceptionToStringWithEmptyLocationAndPath()
216         throws Exception JavaDoc
217     {
218         final ConfigurationException exception =
219             new ConfigurationException( "myMessage", "", "" );
220
221         final String JavaDoc expected =
222             "org.codehaus.dna.ConfigurationException: myMessage";
223
224         assertEquals( expected, exception.toString() );
225     }
226 }
227
Popular Tags