KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > nu > xom > tests > XIncludeExceptionTest


1 /* Copyright 2003, 2004 Elliotte Rusty Harold
2    
3    This library is free software; you can redistribute it and/or modify
4    it under the terms of version 2.1 of the GNU Lesser General Public
5    License as published by the Free Software Foundation.
6    
7    This library is distributed in the hope that it will be useful,
8    but WITHOUT ANY WARRANTY; without even the implied warranty of
9    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10    GNU Lesser General Public License for more details.
11    
12    You should have received a copy of the GNU Lesser General Public
13    License along with this library; if not, write to the
14    Free Software Foundation, Inc., 59 Temple Place, Suite 330,
15    Boston, MA 02111-1307 USA
16    
17    You can contact Elliotte Rusty Harold by sending e-mail to
18    elharo@metalab.unc.edu. Please include the word "XOM" in the
19    subject line. The XOM home page is located at http://www.xom.nu/
20 */

21
22 package nu.xom.tests;
23
24 import nu.xom.xinclude.BadParseAttributeException;
25 import nu.xom.xinclude.MisplacedFallbackException;
26 import nu.xom.xinclude.NoIncludeLocationException;
27 import nu.xom.xinclude.XIncludeException;
28
29 /**
30  * <p>
31  * Unit tests for the <code>XIncludeException</code> class.
32  * </p>
33  *
34  * @author Elliotte Rusty Harold
35  * @version 1.0
36  *
37  */

38 public class XIncludeExceptionTest extends XOMTestCase {
39     
40     private XIncludeException ex;
41     private Exception JavaDoc cause;
42     
43     
44     public XIncludeExceptionTest(String JavaDoc name) {
45         super(name);
46     }
47
48     
49     protected void setUp() {
50         ex = new XIncludeException("message");
51         cause = new Exception JavaDoc();
52     }
53     
54     
55     public void testConstructor() {
56         ex = new XIncludeException("test", "http://ex.com/");
57         assertEquals("test", ex.getMessage());
58         assertEquals("http://ex.com/", ex.getURI());
59     }
60
61     
62     public void testInitCause() {
63         
64         assertNull(ex.getCause());
65         ex.initCause(cause);
66         assertEquals(cause, ex.getCause());
67         
68         try {
69             ex.initCause(null);
70             fail("Reinitialized cause over null");
71         }
72         catch (IllegalStateException JavaDoc result) {
73             // success
74
}
75         
76         try {
77             ex.initCause(new Exception JavaDoc());
78             fail("Reinitialized cause over null");
79         }
80         catch (IllegalStateException JavaDoc result) {
81             // success
82
}
83         
84     }
85
86
87     public void testNullInitCause() {
88         
89         XIncludeException ex
90           = new XIncludeException("message", (Exception JavaDoc) null);
91         assertNull(ex.getCause());
92         
93         try {
94             ex.initCause(new Exception JavaDoc());
95             fail("Reinitialized cause over null");
96         }
97         catch (IllegalStateException JavaDoc result) {
98             // success
99
}
100
101         try {
102             ex.initCause(null);
103             fail("Reinitialized cause over null");
104         }
105         catch (IllegalStateException JavaDoc result) {
106             // success
107
}
108         
109     }
110
111     
112     public void testSelfCause() {
113         
114         try {
115             ex.initCause(ex);
116             fail("Allowed self-causation");
117         }
118         catch (IllegalArgumentException JavaDoc success) {
119             // success
120
}
121         
122     }
123
124     
125     public void testGetMessage() {
126         Exception JavaDoc ex = new XIncludeException("testing");
127         assertEquals("testing", ex.getMessage());
128     }
129     
130     
131     public void testMisplacedFallbackException() {
132         String JavaDoc message = "message";
133         Exception JavaDoc ex = new MisplacedFallbackException(message);
134         assertEquals(message, ex.getMessage());
135     }
136
137     
138     public void testBadParseAttributeException() {
139         
140         String JavaDoc message = "message";
141         Exception JavaDoc ex = new BadParseAttributeException(message);
142         assertEquals(message, ex.getMessage());
143         
144     }
145
146     
147     public void testNoIncludeLocationException() {
148         String JavaDoc message = "message";
149         XIncludeException ex = new NoIncludeLocationException(message);
150         assertEquals(message, ex.getMessage());
151         assertNull(ex.getCause());
152         
153         Exception JavaDoc cause = new Exception JavaDoc();
154         ex = new NoIncludeLocationException(message, cause);
155         assertEquals(message, ex.getMessage());
156         assertEquals(cause, ex.getCause());
157         
158     }
159
160 }
161
Popular Tags