diff --git a/spring-data-commons-core/src/main/java/org/springframework/data/repository/query/QueryMethod.java b/spring-data-commons-core/src/main/java/org/springframework/data/repository/query/QueryMethod.java index fd12c20b8..e4ad7d057 100644 --- a/spring-data-commons-core/src/main/java/org/springframework/data/repository/query/QueryMethod.java +++ b/spring-data-commons-core/src/main/java/org/springframework/data/repository/query/QueryMethod.java @@ -150,8 +150,7 @@ public class QueryMethod { public boolean isCollectionQuery() { Class returnType = method.getReturnType(); - return org.springframework.util.ClassUtils.isAssignable(List.class, - returnType); + return !isPageQuery() && org.springframework.util.ClassUtils.isAssignable(Iterable.class, returnType); } diff --git a/spring-data-commons-core/src/test/java/org/springframework/data/repository/query/QueryMethodUnitTests.java b/spring-data-commons-core/src/test/java/org/springframework/data/repository/query/QueryMethodUnitTests.java index b2719c272..ac11c4d21 100644 --- a/spring-data-commons-core/src/test/java/org/springframework/data/repository/query/QueryMethodUnitTests.java +++ b/spring-data-commons-core/src/test/java/org/springframework/data/repository/query/QueryMethodUnitTests.java @@ -15,6 +15,9 @@ */ package org.springframework.data.repository.query; +import static org.junit.Assert.*; +import static org.hamcrest.CoreMatchers.*; + import java.lang.reflect.Method; import org.junit.Test; @@ -37,7 +40,7 @@ public class QueryMethodUnitTests { RepositoryMetadata metadata; @Test(expected = IllegalStateException.class) - public void rejectsPagingMethodWithInvalidaReturnType() throws SecurityException, NoSuchMethodException { + public void rejectsPagingMethodWithInvalidReturnType() throws Exception { Method method = SampleRepository.class.getMethod("pagingMethodWithInvalidReturnType", Pageable.class); new QueryMethod(method, metadata); @@ -50,10 +53,25 @@ public class QueryMethodUnitTests { } @Test - public void setsUpSimpleQueryMethodCorrectly() throws NoSuchMethodException, SecurityException { + public void setsUpSimpleQueryMethodCorrectly() throws Exception { Method method = SampleRepository.class.getMethod("findByUsername", String.class); new QueryMethod(method, metadata); } + + @Test + public void considersIterableMethodForCollectionQuery() throws Exception { + Method method = SampleRepository.class.getMethod("sampleMethod"); + QueryMethod queryMethod = new QueryMethod(method, metadata); + assertThat(queryMethod.isCollectionQuery(), is(true)); + } + + @Test + public void doesNotConsiderPageMethodCollectionQuery() throws Exception { + Method method = SampleRepository.class.getMethod("anotherSampleMethod", Pageable.class); + QueryMethod queryMethod = new QueryMethod(method, metadata); + assertThat(queryMethod.isPageQuery(), is(true)); + assertThat(queryMethod.isCollectionQuery(), is(false)); + } interface SampleRepository { String pagingMethodWithInvalidReturnType(Pageable pageable); @@ -61,5 +79,8 @@ public class QueryMethodUnitTests { Page pagingMethodWithoutPageable(); String findByUsername(String username); + + Iterable sampleMethod(); + Page anotherSampleMethod(Pageable pageable); } }