KickJava   Java API By Example, From Geeks To Geeks.

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


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.xslt.XSLException;
25
26 /**
27  * <p>
28  * Unit tests for the <code>XSLException</code> class.
29  * </p>
30  *
31  * @author Elliotte Rusty Harold
32  * @version 1.0
33  *
34  */

35 public class XSLExceptionTest extends XOMTestCase {
36     
37     private XSLException ex;
38     private Exception JavaDoc cause;
39     
40     public XSLExceptionTest(String JavaDoc name) {
41         super(name);
42     }
43
44     protected void setUp() {
45         ex = new XSLException("message");
46         cause = new Exception JavaDoc();
47     }
48     
49     public void testConstructor() {
50         String JavaDoc message = "testing 1-2-3";
51         XSLException ex = new XSLException(message, cause);
52         assertEquals(message, ex.getMessage());
53         assertEquals(cause, ex.getCause());
54     }
55
56     public void testInitCause() {
57         
58         assertNull(ex.getCause());
59         ex.initCause(cause);
60         assertEquals(cause, ex.getCause());
61         
62         try {
63             ex.initCause(null);
64             fail("Reinitialized cause over null");
65         }
66         catch (IllegalStateException JavaDoc success) {
67             // success
68
assertNotNull(success.getMessage());
69         }
70         
71         try {
72             ex.initCause(new Exception JavaDoc());
73             fail("Reinitialized cause over null");
74         }
75         catch (IllegalStateException JavaDoc success) {
76             // success
77
assertNotNull(success.getMessage());
78         }
79         
80     }
81
82
83     public void testNullInitCause() {
84         
85         XSLException ex = new XSLException(null, null);
86         assertNull(ex.getCause());
87         
88         try {
89             ex.initCause(new Exception JavaDoc());
90             fail("Reinitialized cause over null");
91         }
92         catch (IllegalStateException JavaDoc result) {
93             // success
94
}
95
96         try {
97             ex.initCause(null);
98             fail("Reinitialized cause over null");
99         }
100         catch (IllegalStateException JavaDoc result) {
101             // success
102
}
103         
104     }
105
106     public void testSelfCause() {
107         
108         try {
109             ex.initCause(ex);
110             fail("Allowed self-causation");
111         }
112         catch (IllegalArgumentException JavaDoc result) {
113             // success
114
}
115         
116     }
117
118     public void testGetMessage() {
119         Exception JavaDoc ex = new XSLException("testing");
120         assertEquals("testing", ex.getMessage());
121     }
122
123 }
124
Popular Tags