|
64 | 64 | * @author Christoph Strobl
|
65 | 65 | * @author Malte Mauelshagen
|
66 | 66 | * @author Greg Turnquist
|
| 67 | + * @author Anatoliy Golubev |
67 | 68 | */
|
68 | 69 | @ExtendWith(SpringExtension.class)
|
69 | 70 | @ContextConfiguration({ "classpath:infrastructure.xml" })
|
@@ -517,6 +518,80 @@ void findByFluentPredicateWithComplexPropertyPathsDoesntLoadsRequestedPaths() {
|
517 | 518 | assertThat(users).allMatch(u -> u.getRoles().isEmpty());
|
518 | 519 | }
|
519 | 520 |
|
| 521 | + @Test // GH-2691 |
| 522 | + void shouldSupportSortByWithUnpagedPageable() { |
| 523 | + |
| 524 | + // "unpaged" pageable implementation with sort |
| 525 | + @Data |
| 526 | + class UnpageableWithSort implements Pageable { |
| 527 | + private final Sort sort; |
| 528 | + |
| 529 | + @Override |
| 530 | + public boolean isPaged() { |
| 531 | + return false; |
| 532 | + } |
| 533 | + |
| 534 | + @Override |
| 535 | + public Pageable previousOrFirst() { |
| 536 | + return this; |
| 537 | + } |
| 538 | + |
| 539 | + @Override |
| 540 | + public Pageable next() { |
| 541 | + return this; |
| 542 | + } |
| 543 | + |
| 544 | + @Override |
| 545 | + public boolean hasPrevious() { |
| 546 | + return false; |
| 547 | + } |
| 548 | + |
| 549 | + @Override |
| 550 | + public Sort getSort() { |
| 551 | + return sort; |
| 552 | + } |
| 553 | + |
| 554 | + @Override |
| 555 | + public int getPageSize() { |
| 556 | + throw new UnsupportedOperationException(); |
| 557 | + } |
| 558 | + |
| 559 | + @Override |
| 560 | + public int getPageNumber() { |
| 561 | + throw new UnsupportedOperationException(); |
| 562 | + } |
| 563 | + |
| 564 | + @Override |
| 565 | + public long getOffset() { |
| 566 | + throw new UnsupportedOperationException(); |
| 567 | + } |
| 568 | + |
| 569 | + @Override |
| 570 | + public Pageable first() { |
| 571 | + return this; |
| 572 | + } |
| 573 | + |
| 574 | + @Override |
| 575 | + public Pageable withPage(int pageNumber) { |
| 576 | + if (pageNumber == 0) { |
| 577 | + return this; |
| 578 | + } else { |
| 579 | + throw new UnsupportedOperationException(); |
| 580 | + } |
| 581 | + } |
| 582 | + } |
| 583 | + |
| 584 | + Predicate lastnameContainsE = user.lastname.contains("e"); |
| 585 | + |
| 586 | + Page<User> result = predicateExecutor.findAll(lastnameContainsE, new UnpageableWithSort(Sort.by("lastname").ascending())); |
| 587 | + |
| 588 | + assertThat(result).containsExactly(carter, dave, oliver); |
| 589 | + |
| 590 | + result = predicateExecutor.findAll(lastnameContainsE, new UnpageableWithSort(Sort.by("lastname").descending())); |
| 591 | + |
| 592 | + assertThat(result).containsExactly(oliver, dave, carter); |
| 593 | + } |
| 594 | + |
520 | 595 | private interface UserProjectionInterfaceBased {
|
521 | 596 | String getFirstname();
|
522 | 597 |
|
|
0 commit comments