DATACMNS-939 - Tests.

This commit is contained in:
Mark Paluch
2016-11-21 09:23:26 +01:00
committed by Oliver Gierke
parent ed11c9dbd7
commit 9316ce471b
2 changed files with 56 additions and 1 deletions
@@ -50,6 +50,7 @@ import org.springframework.data.repository.core.support.DefaultRepositoryMetadat
*
* @author Oliver Gierke
* @author Thomas Darimont
* @author Mark Paluch
*/
@RunWith(MockitoJUnitRunner.class)
public class DefaultRepositoryInformationUnitTests {
@@ -254,6 +255,36 @@ public class DefaultRepositoryInformationUnitTests {
assertThat(information.isCustomMethod(customBaseRepositoryMethod), is(true));
}
/**
* @see DATACMNS-939
*/
@Test
public void ignoresStaticMethod() throws SecurityException, NoSuchMethodException {
RepositoryMetadata metadata = new DefaultRepositoryMetadata(FooRepository.class);
RepositoryInformation information = new DefaultRepositoryInformation(metadata, CrudRepository.class,
customImplementation.getClass());
Method method = FooRepository.class.getMethod("staticMethod");
assertThat(information.getQueryMethods(), not(hasItem(method)));
}
/**
* @see DATACMNS-939
*/
@Test
public void ignoresDefaultMethod() throws SecurityException, NoSuchMethodException {
RepositoryMetadata metadata = new DefaultRepositoryMetadata(FooRepository.class);
RepositoryInformation information = new DefaultRepositoryInformation(metadata, CrudRepository.class,
customImplementation.getClass());
Method method = FooRepository.class.getMethod("defaultMethod");
assertThat(information.getQueryMethods(), not(hasItem(method)));
}
private static Method getMethodFrom(Class<?> type, String name) {
for (Method method : type.getMethods()) {
@@ -278,6 +309,10 @@ public class DefaultRepositoryInformationUnitTests {
// Not a redeclared method
User findOne(Long primaryKey);
static void staticMethod() {}
default void defaultMethod() {}
}
interface FooSuperInterfaceWithGenerics<T> {
@@ -1,5 +1,5 @@
/*
* Copyright 2011-2015 the original author or authors.
* Copyright 2011-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -67,6 +67,7 @@ import org.springframework.util.concurrent.ListenableFuture;
* Unit tests for {@link RepositoryFactorySupport}.
*
* @author Oliver Gierke
* @author Mark Paluch
*/
@RunWith(MockitoJUnitRunner.class)
public class RepositoryFactorySupportUnitTests {
@@ -325,6 +326,17 @@ public class RepositoryFactorySupportUnitTests {
factory.getTargetRepositoryViaReflection(information, entityInformation, "Foo");
}
@Test
public void callsStaticMethodOnInterface() {
ObjectRepository repository = factory.getRepository(ObjectRepository.class, customImplementation);
assertThat(repository.staticMethodDelegate(), is(equalTo("OK")));
verifyZeroInteractions(customImplementation);
verifyZeroInteractions(backingRepo);
}
private ConvertingRepository prepareConvertingRepository(final Object expectedValue) {
when(factory.queryOne.execute(Mockito.any(Object[].class))).then(new Answer<Object>() {
@@ -365,6 +377,14 @@ public class RepositoryFactorySupportUnitTests {
Object findByFoo();
Object save(Object entity);
static String staticMethod() {
return "OK";
}
default String staticMethodDelegate() {
return staticMethod();
}
}
interface ObjectRepositoryCustom {