Skip to content

Commit e85ea1d

Browse files
committed
Add tests to verify custom finders can handle PageRequest as method parameter.
Spring Data Commons patched handling subclasses of special parameter types through spring-projects/spring-data-commons#2626. This commit adds test cases ensuring things work properly with Spring Data JPA. See #2013.
1 parent 7cb16de commit e85ea1d

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

spring-data-jpa/src/test/java/org/springframework/data/jpa/repository/UserRepositoryTests.java

+26
Original file line numberDiff line numberDiff line change
@@ -1709,6 +1709,32 @@ void findByEmptyCollectionOfIntegers() {
17091709
assertThat(users).hasSize(0);
17101710
}
17111711

1712+
@Test // GH-2013
1713+
void findByCollectionWithPageable() {
1714+
1715+
flushTestUsers();
1716+
1717+
Page<User> userPage = repository.findByAgeIn(List.of(28, 35), (Pageable) PageRequest.of(0, 2));
1718+
1719+
assertThat(userPage).hasSize(2);
1720+
assertThat(userPage.getTotalElements()).isEqualTo(2);
1721+
assertThat(userPage.getTotalPages()).isEqualTo(1);
1722+
assertThat(userPage.getContent()).containsExactlyInAnyOrder(firstUser, secondUser);
1723+
}
1724+
1725+
@Test // GH-2013
1726+
void findByCollectionWithPageRequest() {
1727+
1728+
flushTestUsers();
1729+
1730+
Page<User> userPage = repository.findByAgeIn(List.of(28, 35), (PageRequest) PageRequest.of(0, 2));
1731+
1732+
assertThat(userPage).hasSize(2);
1733+
assertThat(userPage.getTotalElements()).isEqualTo(2);
1734+
assertThat(userPage.getTotalPages()).isEqualTo(1);
1735+
assertThat(userPage.getContent()).containsExactlyInAnyOrder(firstUser, secondUser);
1736+
}
1737+
17121738
@Test // DATAJPA-606
17131739
void findByEmptyArrayOfIntegers() {
17141740

spring-data-jpa/src/test/java/org/springframework/data/jpa/repository/sample/UserRepository.java

+8
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import jakarta.persistence.QueryHint;
2828

2929
import org.springframework.data.domain.Page;
30+
import org.springframework.data.domain.PageRequest;
3031
import org.springframework.data.domain.Pageable;
3132
import org.springframework.data.domain.Slice;
3233
import org.springframework.data.domain.Sort;
@@ -52,6 +53,7 @@
5253
* @author Jeff Sheets
5354
* @author Andrey Kovalev
5455
* @author JyotirmoyVS
56+
* @author Greg Turnquist
5557
*/
5658
public interface UserRepository
5759
extends JpaRepository<User, Integer>, JpaSpecificationExecutor<User>, UserRepositoryCustom {
@@ -504,6 +506,12 @@ List<User> findUsersByFirstnameForSpELExpressionWithParameterIndexOnlyWithEntity
504506
// DATAJPA-606
505507
List<User> findByAgeIn(Collection<Integer> ages);
506508

509+
// GH-2013
510+
Page<User> findByAgeIn(Collection<Integer> ages, Pageable pageable);
511+
512+
// GH-2013
513+
Page<User> findByAgeIn(Collection<Integer> ages, PageRequest pageable);
514+
507515
// DATAJPA-606
508516
List<User> queryByAgeIn(Integer[] ages);
509517

0 commit comments

Comments
 (0)