GenericPropertyUtil { protected static Method getMethod(Object bean, String name) throws IllegalArgumentException { PropertyDescriptor descriptor = null; try { descriptor = PropertyUtils.getPropertyDescriptor(bean, name); } catch (IllegalAccessException e) { throw new IllegalArgumentException("Failed to detect getter for " + bean.getClass().getName() + "#" + name, e); } catch (InvocationTargetException e) { throw new IllegalArgumentException("Failed to detect getter for " + bean.getClass().getName() + "#" + name, e); } catch (NoSuchMethodException e) { throw new IllegalArgumentException("Failed to detect getter for " + bean.getClass().getName() + "#" + name, e); } Method method = null; if (descriptor != null) { method = descriptor.getReadMethod(); } if (method == null) { throw new IllegalArgumentException(bean.getClass().getName() + " has no getter for property " + name); } return method; }  static Class<?> resolveCollectionType(Object bean,
            String name); static Class<?> resolveType(Object bean, String name,
            Class<?> genericClass,
            int index);  }
@Test public void testGetMethod01() throws Exception { try { GenericPropertyUtil.getMethod(new GenericPropertyUtil_Stub02(), "string"); fail("例外がスローされませんでした。"); } catch (IllegalArgumentException e) { String message = GenericPropertyUtil_Stub02.class.getName() + " has no getter for property string"; assertEquals(message, e.getMessage()); assertEquals(IllegalArgumentException.class.getName(), e.getClass() .getName()); } }
@Test public void testGetMethod02() throws Exception { try { GenericPropertyUtil.getMethod(new GenericPropertyUtil_Stub02(), "string1"); fail("例外がスローされませんでした。"); } catch (IllegalArgumentException e) { String message = GenericPropertyUtil_Stub02.class.getName() + " has no getter for property string1"; assertEquals(message, e.getMessage()); assertEquals(IllegalArgumentException.class.getName(), e.getClass() .getName()); } }
@Test public void testGetMethod03() throws Exception { Method actual = GenericPropertyUtil.getMethod( new GenericPropertyUtil_Stub02(), "string2"); Method expected = GenericPropertyUtil_Stub02.class.getDeclaredMethod( "getString2", new Class[0]); assertEquals(expected, actual); }
@Test public void testGetMethod04() throws Exception { try { GenericPropertyUtil.getMethod(new GenericPropertyUtil_Stub02(), "bean1.string"); fail("例外がスローされませんでした。"); } catch (IllegalArgumentException e) { String message = "Failed to detect getter for " + GenericPropertyUtil_Stub02.class.getName() + "#bean1.string"; assertEquals(message, e.getMessage()); assertEquals(IllegalArgumentException.class.getName(), e.getClass() .getName()); assertTrue(e.getCause() instanceof NoSuchMethodException); } }
@Test public void testGetMethod05() throws Exception { try { GenericPropertyUtil.getMethod(new GenericPropertyUtil_Stub02(), "bean2.string"); fail("例外がスローされませんでした。"); } catch (IllegalArgumentException e) { String message = "Failed to detect getter for " + GenericPropertyUtil_Stub02.class.getName() + "#bean2.string"; assertEquals(message, e.getMessage()); assertEquals(IllegalArgumentException.class.getName(), e.getClass() .getName()); assertTrue(e.getCause() instanceof InvocationTargetException); } }
@Test public void testGetMethod06() throws Exception { BeanUtilsBean beanUtilsBean = BeanUtilsBean.getInstance(); ReflectionTestUtils.setField(beanUtilsBean, "propertyUtilsBean", new GenericPropertyUtil_PropertyUtilsBeanStub01()); try { GenericPropertyUtil.getMethod(new GenericPropertyUtil_Stub02(), "string2"); fail("例外がスローされませんでした。"); } catch (IllegalArgumentException e) { String message = "Failed to detect getter for " + GenericPropertyUtil_Stub02.class.getName() + "#string2"; assertEquals(message, e.getMessage()); assertEquals(IllegalArgumentException.class.getName(), e.getClass() .getName()); assertTrue(e.getCause() instanceof IllegalAccessException); } }