DATACMNS-912 - Fixed generic method detection for overrides using generic methods.

We now correctly check the bounds of generic methods if we deal with a type variable found as method parameter. Introduced different code paths for type and method level generics so that the latter is explicitly checking all bounds available.
This commit is contained in:
Oliver Gierke
2016-09-16 00:43:21 +02:00
parent db62390de9
commit f44c238784
2 changed files with 61 additions and 20 deletions

View File

@@ -239,6 +239,21 @@ public class DefaultRepositoryInformationUnitTests {
assertThat(information.getTargetClassMethod(source), is(expected));
}
/**
* @see DATACMNS-912
*/
@Test
public void discoversCustomlyImplementedCrudMethodWithGenericParameters() throws Exception {
SampleRepositoryImpl customImplementation = new SampleRepositoryImpl();
RepositoryMetadata metadata = new DefaultRepositoryMetadata(SampleRepository.class);
RepositoryInformation information = new DefaultRepositoryInformation(metadata, RepositoryFactorySupport.class,
customImplementation.getClass());
Method customBaseRepositoryMethod = SampleRepository.class.getMethod("save", Object.class);
assertThat(information.isCustomMethod(customBaseRepositoryMethod), is(true));
}
private static Method getMethodFrom(Class<?> type, String name) {
for (Method method : type.getMethods()) {
@@ -288,7 +303,7 @@ public class DefaultRepositoryInformationUnitTests {
@Override
public Iterator<User> iterator() {
return Collections.<User> emptySet().iterator();
return Collections.<User>emptySet().iterator();
}
}
@@ -340,4 +355,15 @@ public class DefaultRepositoryInformationUnitTests {
@MyQuery
List<User> findAll();
}
interface SampleRepository extends CrudRepository<Sample, Long> {}
static class SampleRepositoryImpl {
public <S extends Sample> S save(S entity) {
return entity;
}
}
static class Sample {}
}