DefaultDataProviderMethodResolver implements DataProviderMethodResolver { protected List<Method> findAnnotatedMethods(List<Class<?>> locations, Class<? extends Annotation> annotationClass) { List<Method> result = new ArrayList<Method>(); for (Class<?> location : locations) { List<Method> intermediateResult = new ArrayList<Method>(); Class<?> currentClass = location; while (currentClass != null) { for (Method method : sorted(currentClass.getDeclaredMethods())) { Annotation foundAnnotation = method.getAnnotation(annotationClass); if (foundAnnotation != null && !isMethodShadowedBy(method, intermediateResult)) { intermediateResult.add(method); } } currentClass = currentClass.getSuperclass(); } result.addAll(intermediateResult); } return result; }  @Override List<Method> resolve(DataProviderResolverContext context);  }
@Test public void testFindAnnotatedMethodsShouldNotShadowedMethodsHavingAnnotation() { final List<Class<?>> locations = Collections.<Class<?>>singletonList(ShadowingTestChild.class); List<Method> result = underTest.findAnnotatedMethods(locations, TestAnnotation.class); assertThat(result).hasSize(7) .has(name("privateWithAnnotation"), atIndex(0)) .has(name("notShadowedDueToParameterLength"), atIndex(1)) .has(name("notShadowedDueToParameterTypes"), atIndex(2)) .has(name("shadowed"), atIndex(3)) .has(name("notShadowedDueToParameterLength"), atIndex(4)) .has(name("notShadowedDueToParameterTypes"), atIndex(5)) .has(name("shadowedButChildHasNoAnnotation"), atIndex(6)) ; }
@Test public void testFindAnnotatedMethodsShouldReturnMethodsForAllLocations() { final List<Class<?>> locations = Arrays.<Class<?>>asList(ShadowingTestChild.class, ShadowingTestParent.class); List<Method> result = underTest.findAnnotatedMethods(locations, TestAnnotation.class); assertThat(result).hasSize(11); }