### Question:
Reflection { public Method[] findMethods( String methodName, boolean caseSensitive ) { Pattern pattern = caseSensitive ? Pattern.compile(methodName) : Pattern.compile(methodName, Pattern.CASE_INSENSITIVE); return findMethods(pattern); } Reflection( Class<?> targetClass ); static Class<?>[] buildArgumentClasses( Object... arguments ); static List<Class<?>> buildArgumentClassList( Object... arguments ); static List<Class<?>> convertArgumentClassesToPrimitives( Class<?>... arguments ); static String getClassName( final Class<?> clazz ); Class<?> getTargetClass(); Method[] findMethods( String methodName,
                                 boolean caseSensitive ); Method[] findMethods( Pattern methodNamePattern ); Method[] findGetterMethods(); String[] findGetterPropertyNames(); Method findFirstMethod( String methodName,
                                   boolean caseSensitive ); Method findFirstMethod( Pattern methodNamePattern ); Object invokeBestMethodOnTarget( String[] methodNames,
                                            Object target,
                                            Object... arguments ); Object invokeSetterMethodOnTarget( String javaPropertyName,
                                              Object target,
                                              Object argument ); Object invokeGetterMethodOnTarget( String javaPropertyName,
                                              Object target ); Method findBestMethodOnTarget( String methodName,
                                          Object... arguments ); Method findBestMethodWithSignature( String methodName,
                                               Class<?>... argumentsClasses ); Property getProperty( Object target,
                                 String propertyName,
                                 String label,
                                 String category,
                                 String description,
                                 Object... allowedValues ); Property getProperty( Object target,
                                 String propertyName,
                                 String description ); Property getProperty( Object target,
                                 String propertyName ); List<Property> getAllPropertiesOn( Object target ); Map<String, Property> getAllPropertiesByNameOn( Object target ); void setProperty( Object target,
                             Property property,
                             Object value ); Object getProperty( Object target,
                               Property property ); String getPropertyAsString( Object target,
                                       Property property );  }### Answer:
@Test public void shouldFindMethodsWithExactMatchingName() { Method[] stringMethods = stringReflection.findMethods("indexOf", true); assertThat(stringMethods.length, is(4)); for (Method method : stringMethods) { assertThat(method.getName(), is("indexOf")); } stringMethods = stringReflection.findMethods("length", true); assertThat(stringMethods.length, is(1)); for (Method method : stringMethods) { assertThat(method.getName(), is("length")); } }
@Test public void shouldFindMethodsWithNameMatchingRegularExpression() { Method[] stringMethods = stringReflection.findMethods("indexO.", true); assertThat(stringMethods.length, is(4)); for (Method method : stringMethods) { assertThat(method.getName(), is("indexOf")); } stringMethods = stringReflection.findMethods(".+gth", true); assertThat(stringMethods.length, is(1)); for (Method method : stringMethods) { assertThat(method.getName(), is("length")); } }
@Test public void shouldNotFindMethodsWhenThereAreNoMethodsWithThatName() { assertThat(stringReflection.findMethods("size", true).length, is(0)); assertThat(stringListReflection.findMethods("argleBargle", true).length, is(0)); }