e.g. Calendar Search Help
You must enter a value before pressing Search
spring

Class: org.springframework.util.ObjectUtilsTests   ©

 OK to copy?
01 /*
02  * Copyright 2002-2004 the original author or authors.
03  * 
04  * Licensed under the Apache License, Version 2.0 (the "License");
05  * you may not use this file except in compliance with the License.
06  * You may obtain a copy of the License at
07  * 
08  *      http://www.apache.org/licenses/LICENSE-2.0
09  * 
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;
20 
21 import javax.servlet.ServletException;
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() {
Rate33         assertTrue(ObjectUtils.isCheckedException(new Exception()));
34         assertTrue(ObjectUtils.isCheckedException(new ServletException()));
35         assertFalse(ObjectUtils.isCheckedException(new RuntimeException()));
36         assertFalse(ObjectUtils.isCheckedException(new BeansException("", null) {
37         }));
38         assertFalse(ObjectUtils.isCheckedException(new Throwable()));
39     }
40 
41     public void testIsCompatibleWithThrowsClause() {
42         Class[] empty = new Class[0];
43         Class[] exception = new Class[] { Exception.class };
44         Class[] servletAndIO = new Class[] { ServletException.class, IOException.class };
45         Class[] throwable = new Class[] { Throwable.class };
46 
47         assertTrue(ObjectUtils.isCompatibleWithThrowsClause(new RuntimeException(), null));
48         assertTrue(ObjectUtils.isCompatibleWithThrowsClause(new RuntimeException(), empty));
49         assertTrue(ObjectUtils.isCompatibleWithThrowsClause(new RuntimeException(), exception));
50         assertTrue(ObjectUtils.isCompatibleWithThrowsClause(new RuntimeException(), servletAndIO));
51         assertTrue(ObjectUtils.isCompatibleWithThrowsClause(new RuntimeException(), throwable));
52 
Rate53         assertFalse(ObjectUtils.isCompatibleWithThrowsClause(new Exception(), null));
Rate54         assertFalse(ObjectUtils.isCompatibleWithThrowsClause(new Exception(), empty));
Rate55         assertTrue(ObjectUtils.isCompatibleWithThrowsClause(new Exception(), exception));
Rate56         assertFalse(ObjectUtils.isCompatibleWithThrowsClause(new Exception(), servletAndIO));
Rate57         assertTrue(ObjectUtils.isCompatibleWithThrowsClause(new Exception(), throwable));
58 
59         assertFalse(ObjectUtils.isCompatibleWithThrowsClause(new ServletException(), null));
60         assertFalse(ObjectUtils.isCompatibleWithThrowsClause(new ServletException(), empty));
61         assertTrue(ObjectUtils.isCompatibleWithThrowsClause(new ServletException(), exception));
62         assertTrue(ObjectUtils.isCompatibleWithThrowsClause(new ServletException(), servletAndIO));
63         assertTrue(ObjectUtils.isCompatibleWithThrowsClause(new ServletException(), throwable));
64 
65         assertFalse(ObjectUtils.isCompatibleWithThrowsClause(new Throwable(), null));
66         assertFalse(ObjectUtils.isCompatibleWithThrowsClause(new Throwable(), empty));
67         assertFalse(ObjectUtils.isCompatibleWithThrowsClause(new Throwable(), exception));
68         assertFalse(ObjectUtils.isCompatibleWithThrowsClause(new Throwable(), servletAndIO));
69         assertTrue(ObjectUtils.isCompatibleWithThrowsClause(new Throwable(), throwable));
70     }
71 
72     public void testToObjectArray() {
73         int[] a = new int[] { 1, 2, 3, 4, 5 };
74         Integer[] wrapper = (Integer[])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 }

            
All Examples in File:
Example
Line
Rating (found
useful by...)
33 0% of 0
53 0% of 0
54 0% of 0
55 0% of 0
56 0% of 0
57 0% of 0