diff --git a/src/test/java/org/springframework/data/repository/core/support/DefaultRepositoryInformationUnitTests.java b/src/test/java/org/springframework/data/repository/core/support/DefaultRepositoryInformationUnitTests.java index 875d65475..75db82480 100644 --- a/src/test/java/org/springframework/data/repository/core/support/DefaultRepositoryInformationUnitTests.java +++ b/src/test/java/org/springframework/data/repository/core/support/DefaultRepositoryInformationUnitTests.java @@ -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 { diff --git a/src/test/java/org/springframework/data/repository/core/support/RepositoryFactorySupportUnitTests.java b/src/test/java/org/springframework/data/repository/core/support/RepositoryFactorySupportUnitTests.java index 86c0eb3a4..30be9eb26 100644 --- a/src/test/java/org/springframework/data/repository/core/support/RepositoryFactorySupportUnitTests.java +++ b/src/test/java/org/springframework/data/repository/core/support/RepositoryFactorySupportUnitTests.java @@ -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() { @@ -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 {