ConvertUtil { @SuppressWarnings("unchecked") public static List<Map<String, Object>> toListOfMap(Object obj) throws IllegalArgumentException { Object[] array = ConvertUtil.toArray(obj); List<Map<String, Object>> result = new ArrayList<Map<String, Object>>(); for (Object object : array) { Map<String, Object> map = null; if (object instanceof Map) { map = (Map<String, Object>) object; } else { try { map = PropertyUtils.describe(object); } catch (IllegalAccessException e) { throw new IllegalArgumentException(e); } catch (InvocationTargetException e) { throw new IllegalArgumentException(e); } catch (NoSuchMethodException e) { throw new IllegalArgumentException(e); } } map.remove(CLASS_FIELDNAME); result.add(map); } return result; }  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 testToListOfMap01() throws Exception { List<Map<String, Object>> actual = ConvertUtil.toListOfMap(null); assertNotNull(actual); assertTrue(actual.isEmpty()); }
@Test public void testToListOfMap02() throws Exception { List<ConvertUtil_Stub01> obj = new ArrayList<ConvertUtil_Stub01>(); ConvertUtil_Stub01 bean = new ConvertUtil_Stub01(); bean.setA("value00"); obj.add(bean); ConvertUtil_Stub01 bean02 = new ConvertUtil_Stub01(); bean02.setA("value01"); obj.add(bean02); ConvertUtil_Stub01 bean03 = new ConvertUtil_Stub01(); bean03.setA("value02"); obj.add(bean03); List<Map<String, Object>> actual = ConvertUtil.toListOfMap(obj); assertNotNull(actual); assertEquals(3, actual.size()); assertEquals("value00", actual.get(0).get("a")); assertEquals("value01", actual.get(1).get("a")); assertEquals("value02", actual.get(2).get("a")); }
@Test public void testToListOfMap03() throws Exception { ConvertUtil_Stub01 bean = new ConvertUtil_Stub01(); bean.setA("value00"); ConvertUtil_Stub01 bean02 = new ConvertUtil_Stub01(); bean02.setA("value01"); ConvertUtil_Stub01 bean03 = new ConvertUtil_Stub01(); bean03.setA("value02"); ConvertUtil_Stub01[] obj = new ConvertUtil_Stub01[] { bean, bean02, bean03 }; List<Map<String, Object>> actual = ConvertUtil.toListOfMap(obj); assertNotNull(actual); assertEquals(3, actual.size()); assertEquals("value00", actual.get(0).get("a")); assertEquals("value01", actual.get(1).get("a")); assertEquals("value02", actual.get(2).get("a")); }
@Test public void testToListOfMap04() throws Exception { List<Map<String, Object>> obj = new ArrayList<Map<String, Object>>(); Map<String, Object> row = new HashMap<String, Object>(); row.put("a", "value00"); obj.add(row); Map<String, Object> row02 = new HashMap<String, Object>(); row02.put("a", "value01"); obj.add(row02); Map<String, Object> row03 = new HashMap<String, Object>(); row03.put("a", "value02"); obj.add(row03); List<Map<String, Object>> actual = ConvertUtil.toListOfMap(obj); assertNotNull(actual); assertEquals(3, actual.size()); assertEquals("value00", actual.get(0).get("a")); assertEquals("value01", actual.get(1).get("a")); assertEquals("value02", actual.get(2).get("a")); }
@Test public void testToListOfMap05() throws Exception { Map<String, Object> row = new HashMap<String, Object>(); row.put("a", "value00"); Map<String, Object> row02 = new HashMap<String, Object>(); row02.put("a", "value01"); Map<String, Object> row03 = new HashMap<String, Object>(); row03.put("a", "value02"); @SuppressWarnings("rawtypes") Map[] obj = new Map[] { row, row02, row03 }; List<Map<String, Object>> actual = ConvertUtil.toListOfMap(obj); assertNotNull(actual); assertEquals(3, actual.size()); assertEquals("value00", actual.get(0).get("a")); assertEquals("value01", actual.get(1).get("a")); assertEquals("value02", actual.get(2).get("a")); }
@Test public void testToListOfMap06() throws Exception { ConvertUtil_Stub01 obj = new ConvertUtil_Stub01(); obj.setA("value00"); List<Map<String, Object>> actual = ConvertUtil.toListOfMap(obj); assertNotNull(actual); assertEquals(1, actual.size()); assertEquals("value00", actual.get(0).get("a")); }
@Test public void testToListOfMap08() throws Exception { ConvertUtil_Stub02 obj = new ConvertUtil_Stub02(); obj.setA("value00"); try { ConvertUtil.toListOfMap(obj); fail(); } catch (IllegalArgumentException e) { assertEquals(IllegalArgumentException.class.getName(), e.getClass() .getName()); assertTrue(e.getCause() instanceof InvocationTargetException); } }
@Test public void testToListOfMap09() throws Exception { List<ConvertUtil_Stub01> obj = new ArrayList<ConvertUtil_Stub01>(); ConvertUtil_Stub01 bean = new ConvertUtil_Stub01(); bean.setA("value00"); obj.add(bean); BeanUtilsBean beanUtilsBean = BeanUtilsBean.getInstance(); ReflectionTestUtils.setField(beanUtilsBean, "propertyUtilsBean", new ConvertUtil_PropertyUtilsBeanStub01()); try { ConvertUtil.toListOfMap(obj); fail(); } catch (IllegalArgumentException e) { assertEquals(IllegalArgumentException.class.getName(), e.getClass() .getName()); assertTrue(e.getCause() instanceof IllegalAccessException); } }
@Test public void testToListOfMap10() throws Exception { List<ConvertUtil_Stub01> obj = new ArrayList<ConvertUtil_Stub01>(); ConvertUtil_Stub01 bean = new ConvertUtil_Stub01(); bean.setA("value00"); obj.add(bean); BeanUtilsBean beanUtilsBean = BeanUtilsBean.getInstance(); ReflectionTestUtils.setField(beanUtilsBean, "propertyUtilsBean", new ConvertUtil_PropertyUtilsBeanStub02()); try { ConvertUtil.toListOfMap(obj); fail(); } catch (IllegalArgumentException e) { assertEquals(IllegalArgumentException.class.getName(), e.getClass() .getName()); assertTrue(e.getCause() instanceof NoSuchMethodException); } }