diff --git a/spring-data-rest-core/src/main/java/org/springframework/data/rest/core/support/UnwrappingRepositoryInvokerFactory.java b/spring-data-rest-core/src/main/java/org/springframework/data/rest/core/support/UnwrappingRepositoryInvokerFactory.java index 8f7227fa3..216cac703 100644 --- a/spring-data-rest-core/src/main/java/org/springframework/data/rest/core/support/UnwrappingRepositoryInvokerFactory.java +++ b/spring-data-rest-core/src/main/java/org/springframework/data/rest/core/support/UnwrappingRepositoryInvokerFactory.java @@ -22,7 +22,6 @@ import java.io.Serializable; import java.lang.reflect.Method; import java.util.List; import java.util.Optional; -import java.util.function.Supplier; import org.springframework.core.convert.converter.Converter; import org.springframework.data.domain.Pageable; @@ -30,7 +29,6 @@ import org.springframework.data.domain.Sort; import org.springframework.data.repository.support.RepositoryInvoker; import org.springframework.data.repository.support.RepositoryInvokerFactory; import org.springframework.data.rest.core.util.Java8PluginRegistry; -import org.springframework.data.util.Optionals; import org.springframework.util.Assert; import org.springframework.util.MultiValueMap; @@ -91,10 +89,9 @@ public class UnwrappingRepositoryInvokerFactory implements RepositoryInvokerFact @SuppressWarnings("unchecked") public Optional invokeFindById(Object id) { - Supplier> viaLookup = () -> (Optional) lookup.flatMap(it -> it.lookupEntity(id)); - Supplier> fallback = () -> delegate.invokeFindById(id); - - return Optionals.firstNonEmpty(viaLookup, fallback); + return lookup.isPresent() // + ? (Optional) lookup.flatMap(it -> it.lookupEntity(id)) // + : delegate.invokeFindById(id); } /* diff --git a/spring-data-rest-core/src/test/java/org/springframework/data/rest/core/support/UnwrappingRepositoryInvokerFactoryUnitTests.java b/spring-data-rest-core/src/test/java/org/springframework/data/rest/core/support/UnwrappingRepositoryInvokerFactoryUnitTests.java index 0f158b316..574621f7f 100755 --- a/spring-data-rest-core/src/test/java/org/springframework/data/rest/core/support/UnwrappingRepositoryInvokerFactoryUnitTests.java +++ b/spring-data-rest-core/src/test/java/org/springframework/data/rest/core/support/UnwrappingRepositoryInvokerFactoryUnitTests.java @@ -76,7 +76,7 @@ public class UnwrappingRepositoryInvokerFactoryUnitTests { }); } - @Test // DATAREST-724 + @Test // DATAREST-724, DATAREST-1261 @SuppressWarnings("unchecked") public void usesRegisteredEntityLookup() { @@ -89,6 +89,7 @@ public class UnwrappingRepositoryInvokerFactoryUnitTests { factory.getInvokerFor(Profile.class).invokeFindById(1L); verify(lookup, times(1)).lookupEntity(eq(1L)); + verify(invoker, never()).invokeFindById(eq(1L)); // DATAREST-1261 } private static Consumer> $(Consumer> consumer) {