1 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 30 public class ObjectUtilsTests extends TestCase { 31 32 public void testIsCheckedException() { 33 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 53 assertFalse(ObjectUtils.isCompatibleWithThrowsClause(new Exception (), null)); 54 assertFalse(ObjectUtils.isCompatibleWithThrowsClause(new Exception (), empty)); 55 assertTrue(ObjectUtils.isCompatibleWithThrowsClause(new Exception (), exception)); 56 assertFalse(ObjectUtils.isCompatibleWithThrowsClause(new Exception (), servletAndIO)); 57 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 } | Popular Tags |