ConvertUtil { public static <T> T convertIfNotNull(Object obj, Class<T> clazz) throws IllegalArgumentException { return convert(obj, clazz, false); }  static Object[] toArray(Object obj); @SuppressWarnings("unchecked") static List<E> toList(Object obj, Class<E> elementClass); static T convert(Object obj, Class<T> clazz); static T convertIfNotNull(Object obj, Class<T> clazz); @SuppressWarnings("unchecked") static T convert(
            Object obj, Class<T> clazz, boolean allowsNull); static Object convertPrimitiveArrayToList(Object value); @SuppressWarnings("unchecked") static List<Map<String, Object>> toListOfMap(Object obj); static final String CLASS_FIELDNAME; }
@Test public void testConvertIfNotNull01() throws Exception { try { ConvertUtil.convertIfNotNull("object", null); fail("IllegalArgumentExceptionがスローされませんでした。"); } catch (IllegalArgumentException e) { assertEquals(IllegalArgumentException.class.getName(), e.getClass() .getName()); assertEquals("Argument 'clazz' (" + Object.class.getName() + ") is null", e.getMessage()); } }
@Test public void testConvertIfNotNull02() throws Exception { try { ConvertUtil.convertIfNotNull(null, Object.class); fail("IllegalArgumentExceptionがスローされませんでした。"); } catch (IllegalArgumentException e) { assertEquals(IllegalArgumentException.class.getName(), e.getClass() .getName()); assertEquals("Unable to cast 'null' to '" + Object.class.getName() + "'", e.getMessage()); assertEquals(ClassCastException.class.getName(), e.getCause() .getClass().getName()); assertEquals("Unable to cast 'null' to '" + Object.class.getName() + "'", e.getCause().getMessage()); } }
@Test public void testConvertIfNotNull03() throws Exception { List<?> list = new ArrayList<Object>(); List<?> result = ConvertUtil.convertIfNotNull(list, ArrayList.class); assertSame(list, result); }