GetterMethodFilter implements ReflectionUtils.MethodFilter { @Override public boolean matches(Method method) { return method.getName().matches("get[A-Z].*") && !void.class.equals(method.getReturnType()) && method.getParameterTypes().length == 0; }  @Override boolean matches(Method method);  }
@Test public void testFailures() throws Exception { final GetterMethodFilter filter = new GetterMethodFilter(); assertThat(filter.matches(SampleClass.class.getDeclaredMethod("getProperty")), is(false)); assertThat(filter.matches(SampleClass.class.getDeclaredMethod("getProperty", int.class)), is(false)); assertThat(filter.matches(SampleClass.class.getDeclaredMethod("hasProperty")), is(false)); assertThat(filter.matches(SampleClass.class.getDeclaredMethod("getProperty", String.class)), is(false)); assertThat(filter.matches(SampleClass.class.getDeclaredMethod("hasProperty", String.class)), is(false)); assertThat(filter.matches(SampleClass.class.getDeclaredMethod("hasState")), is(false)); assertThat(filter.matches(SampleClass.class.getDeclaredMethod("getterMethod")), is(false)); }
@Test public void testProperGetter() throws Exception { final GetterMethodFilter filter = new GetterMethodFilter(); assertThat(filter.matches(SampleClass.class.getDeclaredMethod("getValue")), is(true)); }