KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > scriptella > util > ExceptionUtilsTest


1 /*
2  * Copyright 2006-2007 The Scriptella Project Team.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package scriptella.util;
17
18 import scriptella.AbstractTestCase;
19
20 import java.sql.SQLException JavaDoc;
21
22 /**
23  * Tests for {@link ExceptionUtils}.
24  *
25  * @author Fyodor Kupolov
26  * @version 1.0
27  */

28 public class ExceptionUtilsTest extends AbstractTestCase {
29     public void testGetCause() {
30         SQLException JavaDoc e = new SQLException JavaDoc();
31         SQLException JavaDoc e2 = new SQLException JavaDoc("2");
32         e.setNextException(e2);
33         assertTrue(e2==ExceptionUtils.getCause(e));
34         assertNull(ExceptionUtils.getCause(new Throwable JavaDoc()));
35     }
36
37     public void testThrowUnchecked() {
38         Error JavaDoc er = new Error JavaDoc();
39         try {
40             ExceptionUtils.throwUnchecked(er);
41             fail("Error must be rethrown");
42         } catch (Error JavaDoc e) {
43             assertTrue(er==e);
44         }
45         RuntimeException JavaDoc re = new RuntimeException JavaDoc();
46         try {
47             ExceptionUtils.throwUnchecked(re);
48             fail("Runtime ex must be rethrown");
49         } catch (RuntimeException JavaDoc e) {
50             assertTrue(re==e);
51         }
52         try {
53             ExceptionUtils.throwUnchecked(new Exception JavaDoc());
54             fail("Runtime ex must be thrown");
55         } catch (IllegalStateException JavaDoc e) {
56         }
57
58
59     }
60
61 }
62
Popular Tags