mirror of
https://github.com/spring-projects/spring-data-commons.git
synced 2026-05-02 19:22:27 +01:00
DATACMNS-939 - Tests.
This commit is contained in:
committed by
Oliver Gierke
parent
ed11c9dbd7
commit
9316ce471b
+35
@@ -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> {
|
||||
|
||||
+21
-1
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user