BeanUtil { public static Class<?> getBeanPropertyType(Object bean, String property) throws PropertyAccessException { try { Class<?> type = null; if (bean instanceof DynaBean) { DynaProperty descriptor = ((DynaBean) bean).getDynaClass() .getDynaProperty(property); if (descriptor != null){ type = descriptor.getType(); } } else{ type = PropertyUtils.getPropertyType(bean, property); } return type; } catch (IllegalArgumentException e) { throw new PropertyAccessException(e); } catch (IllegalAccessException e) { throw new PropertyAccessException(e); } catch (InvocationTargetException e) { throw new PropertyAccessException(e); } catch (NoSuchMethodException e) { throw new PropertyAccessException(e); } }  static void setBeanProperty(Object bean, String property,
            Object value); static Object getBeanProperty(Object bean, String property); static Class<?> getBeanPropertyType(Object bean, String property);  }
@Test public void testGetBeanPropertyType01() throws Exception { BeanUtil_BeanStub01 bean = new BeanUtil_BeanStub01(); try { BeanUtil.getBeanPropertyType(bean, "param1(0)."); fail(); } catch (PropertyAccessException e) { assertSame(InvocationTargetException.class, e.getCause() .getClass()); } }
@Test public void testGetBeanPropertyType02() throws Exception { BeanUtil_BeanStub01 bean = new BeanUtil_BeanStub01(); assertNull(BeanUtil.getBeanPropertyType(bean, "param3")); }
@Test public void testGetBeanPropertyType03() throws Exception { try { BeanUtil.getBeanPropertyType(null, "param1"); fail(); } catch (PropertyAccessException e) { assertEquals(IllegalArgumentException.class.getName(), e.getCause() .getClass().getName()); } }
@Test public void testGetBeanPropertyType04() throws Exception { BeanUtil_BeanStub01 bean = new BeanUtil_BeanStub01(); try { BeanUtil.getBeanPropertyType(bean, null); fail(); } catch (PropertyAccessException e) { assertEquals(IllegalArgumentException.class.getName(), e.getCause() .getClass().getName()); } }
@Test public void testGetBeanPropertyType05() throws Exception { BeanUtil_BeanStub01 bean = new BeanUtil_BeanStub01(); bean.setParam2("PARAM2"); assertSame(String.class, BeanUtil.getBeanPropertyType(bean, "param2")); }
@Test public void testGetBeanPropertyType06() throws Exception { BeanUtil_BeanStub01 bean = new BeanUtil_BeanStub01(); assertSame(String.class, BeanUtil.getBeanPropertyType(bean, "param2")); }
@Test public void testGetBeanPropertyType07() throws Exception { @SuppressWarnings("rawtypes") Map<?, ?> map = new HashMap(); try { BeanUtil.getBeanPropertyType(map, "aa.(a)"); fail(); } catch (PropertyAccessException e) { assertEquals(NestedNullException.class.getName(), e.getCause() .getClass().getName()); } }
@Test public void testGetBeanPropertyType08() throws Exception { DynaProperty dynaProperty = new DynaProperty("testString", String.class); BeanUtil_DynaClassImpl01 dynaClass = new BeanUtil_DynaClassImpl01(); dynaClass.setDynaProperty(dynaProperty); DynaBean bean = new BeanUtil_DynaBeanImpl01(dynaClass); assertEquals(String.class, BeanUtil.getBeanPropertyType(bean, "testString")); }
@Test public void testGetBeanPropertyType09() throws Exception { DynaProperty dynaProperty = new DynaProperty("testArray", String[].class); BeanUtil_DynaClassImpl01 dynaClass = new BeanUtil_DynaClassImpl01(); dynaClass.setDynaProperty(dynaProperty); DynaBean bean = new BeanUtil_DynaBeanImpl01(dynaClass); assertEquals(String[].class, BeanUtil.getBeanPropertyType(bean, "testArray")); }
@Test public void testGetBeanPropertyType10() throws Exception { BeanUtil_DynaClassImpl01 dynaClass = new BeanUtil_DynaClassImpl01(); dynaClass.setDynaProperty(null); DynaBean bean = new BeanUtil_DynaBeanImpl01(dynaClass); assertEquals(null, BeanUtil.getBeanPropertyType(bean, "testNull")); }