KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > util > ObjectUtilsTests


1 /*
2  * Copyright 2002-2005 the original author or authors.
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
17 package org.springframework.util;
18
19 import java.io.IOException JavaDoc;
20
21 import javax.servlet.ServletException JavaDoc;
22
23 import org.springframework.beans.BeansException;
24
25 import junit.framework.TestCase;
26
27 /**
28  * @author Rod Johnson
29  */

30 public class ObjectUtilsTests extends TestCase {
31
32     public void testIsCheckedException() {
33         assertTrue(ObjectUtils.isCheckedException(new Exception JavaDoc()));
34         assertTrue(ObjectUtils.isCheckedException(new ServletException JavaDoc()));
35         assertFalse(ObjectUtils.isCheckedException(new RuntimeException JavaDoc()));
36         assertFalse(ObjectUtils.isCheckedException(new BeansException("", null) {
37         }));
38         assertFalse(ObjectUtils.isCheckedException(new Throwable JavaDoc()));
39     }
40
41     public void testIsCompatibleWithThrowsClause() {
42         Class JavaDoc[] empty = new Class JavaDoc[0];
43         Class JavaDoc[] exception = new Class JavaDoc[] { Exception JavaDoc.class };
44         Class JavaDoc[] servletAndIO = new Class JavaDoc[] { ServletException JavaDoc.class, IOException JavaDoc.class };
45         Class JavaDoc[] throwable = new Class JavaDoc[] { Throwable JavaDoc.class };
46
47         assertTrue(ObjectUtils.isCompatibleWithThrowsClause(new RuntimeException JavaDoc(), null));
48         assertTrue(ObjectUtils.isCompatibleWithThrowsClause(new RuntimeException JavaDoc(), empty));
49         assertTrue(ObjectUtils.isCompatibleWithThrowsClause(new RuntimeException JavaDoc(), exception));
50         assertTrue(ObjectUtils.isCompatibleWithThrowsClause(new RuntimeException JavaDoc(), servletAndIO));
51         assertTrue(ObjectUtils.isCompatibleWithThrowsClause(new RuntimeException JavaDoc(), throwable));
52
53         assertFalse(ObjectUtils.isCompatibleWithThrowsClause(new Exception JavaDoc(), null));
54         assertFalse(ObjectUtils.isCompatibleWithThrowsClause(new Exception JavaDoc(), empty));
55         assertTrue(ObjectUtils.isCompatibleWithThrowsClause(new Exception JavaDoc(), exception));
56         assertFalse(ObjectUtils.isCompatibleWithThrowsClause(new Exception JavaDoc(), servletAndIO));
57         assertTrue(ObjectUtils.isCompatibleWithThrowsClause(new Exception JavaDoc(), throwable));
58
59         assertFalse(ObjectUtils.isCompatibleWithThrowsClause(new ServletException JavaDoc(), null));
60         assertFalse(ObjectUtils.isCompatibleWithThrowsClause(new ServletException JavaDoc(), empty));
61         assertTrue(ObjectUtils.isCompatibleWithThrowsClause(new ServletException JavaDoc(), exception));
62         assertTrue(ObjectUtils.isCompatibleWithThrowsClause(new ServletException JavaDoc(), servletAndIO));
63         assertTrue(ObjectUtils.isCompatibleWithThrowsClause(new ServletException JavaDoc(), throwable));
64
65         assertFalse(ObjectUtils.isCompatibleWithThrowsClause(new Throwable JavaDoc(), null));
66         assertFalse(ObjectUtils.isCompatibleWithThrowsClause(new Throwable JavaDoc(), empty));
67         assertFalse(ObjectUtils.isCompatibleWithThrowsClause(new Throwable JavaDoc(), exception));
68         assertFalse(ObjectUtils.isCompatibleWithThrowsClause(new Throwable JavaDoc(), servletAndIO));
69         assertTrue(ObjectUtils.isCompatibleWithThrowsClause(new Throwable JavaDoc(), throwable));
70     }
71
72     public void testToObjectArray() {
73         int[] a = new int[] { 1, 2, 3, 4, 5 };
74         Integer JavaDoc[] wrapper = (Integer JavaDoc[])ObjectUtils.toObjectArray(a);
75         assertTrue(wrapper.length == 5);
76         for (int i = 0; i < wrapper.length; i++) {
77             assertEquals(a[i], wrapper[i].intValue());
78         }
79     }
80 }
Popular Tags