### Question:
BeanUtils { public static Method getMethod(Class<?> clazz, String name, Class<?>... parameterTypes) { try { return clazz.getMethod(name, parameterTypes); } catch (NoSuchMethodException e) { throw new IllegalArgumentException(e); } catch (SecurityException e) { throw new IllegalStateException(e); } } private  BeanUtils(); static BeanInfo getBeanInfo(Class<?> clazz); static Method getMethod(Class<?> clazz, String name, Class<?>... parameterTypes); static Optional<Method> getMethod(Class<?> clazz, Predicate<Method> predicate); static Stream<Method> getMethods(Class<?> clazz, Predicate<Method> predicate); static Field getDeclaredField(Class<?> clazz, String name); static Field getField(Class<?> clazz, String name); @CheckForNull static Object getValueFromField(Object object, String name); @CheckForNull static Object getValueFromField(Object object, Field field); static String getPropertyName(Method method); static String getPropertyName(Type returnType, String methodName); static final String GET_PREFIX; static final String SET_PREFIX; static final String IS_PREFIX; }### Answer:
@Test public void testGetMethod_PublicMethodIsFound() { Optional<Method> method = BeanUtils.getMethod(Foo.class, (m) -> m.getName().equals("foo")); assertThat(method, is(present())); }
@Test public void testGetMethod_InterfaceMethodIsFound() { Optional<Method> method = BeanUtils.getMethod(Foo.class, (m) -> m.getName().equals("iFoo")); assertThat(method, is(present())); }
@Test public void testGetMethod_SuperTypeMethodIsFound() { Optional<Method> method = BeanUtils.getMethod(Foo.class, (m) -> m.getName().equals("superFoo")); assertThat(method, is(present())); }
@Test public void testGetMethod_PrivateMethodIsFound() { Optional<Method> method = BeanUtils.getMethod(Foo.class, (m) -> m.getName().equals("bar")); assertThat(method, is(present())); }
@Test public void testGetMethod_OneMatchingMethodIsFound() { Assertions.assertThrows(IllegalStateException.class, () -> { BeanUtils.getMethod(Foo.class, (m) -> m.getName().equals("baz")); }); }
@Test public void testGetMethod_NoMethodIsFound() { Optional<Method> method = BeanUtils.getMethod(Foo.class, (m) -> m.getName().equals("hammaned")); assertThat(method, is(not(present()))); }