DATACMNS-867 - Cleanups in Pageable API.

Dropped Pageable.NONE in favor of ….unpaged() for consistency with Sort.unsorted(). Extracted the implementation for the value backing it into an Unpaged enum instance. Introduced defaulted isPaged() / isUnpaged() to avoid having to compare instances.

JavaDoc in Sort and a couple of API polishes.
This commit is contained in:
Oliver Gierke
2017-02-24 12:43:27 +01:00
parent a5c4be5f0a
commit 8372e34adf
13 changed files with 236 additions and 78 deletions

View File

@@ -72,7 +72,7 @@ public class PageImplUnitTests {
assertThat(page.isFirst()).isTrue();
assertThat(page.hasPrevious()).isFalse();
assertThat(page.previousPageable()).isEqualTo(Pageable.NONE);
assertThat(page.previousPageable().isPaged()).isFalse();
assertThat(page.isLast()).isFalse();
assertThat(page.hasNext()).isTrue();
@@ -90,7 +90,7 @@ public class PageImplUnitTests {
assertThat(page.isLast()).isTrue();
assertThat(page.hasNext()).isFalse();
assertThat(page.nextPageable()).isEqualTo(Pageable.NONE);
assertThat(page.nextPageable().isPaged()).isFalse();
}
@Test
@@ -158,7 +158,7 @@ public class PageImplUnitTests {
@Test // DATACMNS-713
public void doesNotAdapttotalIfPageIsEmpty() {
assertThat(new PageImpl<>(Collections.<String>emptyList(), PageRequest.of(1, 10), 0).getTotalElements())
assertThat(new PageImpl<>(Collections.<String> emptyList(), PageRequest.of(1, 10), 0).getTotalElements())
.isEqualTo(0L);
}
}

View File

@@ -71,7 +71,7 @@ public class SimpleParameterAccessorUnitTests {
ParameterAccessor accessor = new ParametersParameterAccessor(parameters, new Object[] { "test" });
assertThat(accessor.getPageable()).isEqualTo(Pageable.NONE);
assertThat(accessor.getPageable().isPaged()).isFalse();
assertThat(accessor.getSort().isSorted()).isFalse();
}
@@ -82,7 +82,7 @@ public class SimpleParameterAccessorUnitTests {
ParameterAccessor accessor = new ParametersParameterAccessor(sortParameters, new Object[] { "test", sort });
assertThat(accessor.getSort()).isEqualTo(sort);
assertThat(accessor.getPageable()).isEqualTo(Pageable.NONE);
assertThat(accessor.getPageable().isPaged()).isFalse();
}
@Test

View File

@@ -39,6 +39,7 @@ import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.data.repository.core.RepositoryMetadata;
import org.springframework.data.repository.core.support.DefaultRepositoryMetadata;
import org.springframework.data.repository.query.Param;
import org.springframework.data.repository.support.RepositoryInvocationTestUtils.VerifyingMethodInterceptor;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.format.annotation.DateTimeFormat.ISO;
import org.springframework.format.support.DefaultFormattingConversionService;
@@ -95,7 +96,7 @@ public class CrudRepositoryInvokerUnitTests {
Method method = CrudRepository.class.getMethod("findAll");
getInvokerFor(orderRepository, expectInvocationOf(method)).invokeFindAll(Pageable.NONE);
getInvokerFor(orderRepository, expectInvocationOf(method)).invokeFindAll(Pageable.unpaged());
getInvokerFor(orderRepository, expectInvocationOf(method)).invokeFindAll(Sort.unsorted());
}
@@ -108,7 +109,7 @@ public class CrudRepositoryInvokerUnitTests {
getInvokerFor(repository, expectInvocationOf(findAllWithSort)).invokeFindAll(Sort.unsorted());
getInvokerFor(repository, expectInvocationOf(findAllWithSort)).invokeFindAll(PageRequest.of(0, 10));
getInvokerFor(repository, expectInvocationOf(findAllWithSort)).invokeFindAll(Pageable.NONE);
getInvokerFor(repository, expectInvocationOf(findAllWithSort)).invokeFindAll(Pageable.unpaged());
}
@Test // DATACMNS-589
@@ -118,7 +119,7 @@ public class CrudRepositoryInvokerUnitTests {
Method findAllWithPageable = CrudWithFindAllWithPageable.class.getMethod("findAll", Pageable.class);
getInvokerFor(repository, expectInvocationOf(findAllWithPageable)).invokeFindAll(Pageable.NONE);
getInvokerFor(repository, expectInvocationOf(findAllWithPageable)).invokeFindAll(Pageable.unpaged());
getInvokerFor(repository, expectInvocationOf(findAllWithPageable)).invokeFindAll(PageRequest.of(0, 10));
}

View File

@@ -55,7 +55,7 @@ public class PageableExecutionUtilsUnitTests {
@Test // DATAMCNS-884
public void noPageableRequestDoesNotRequireTotal() {
Page<Integer> page = PageableExecutionUtils.getPage(Arrays.asList(1, 2, 3), Pageable.NONE, totalSupplierMock);
Page<Integer> page = PageableExecutionUtils.getPage(Arrays.asList(1, 2, 3), Pageable.unpaged(), totalSupplierMock);
assertThat(page).contains(1, 2, 3);
assertThat(page.getTotalElements()).isEqualTo(3L);
@@ -107,7 +107,7 @@ public class PageableExecutionUtilsUnitTests {
public void subsequentPageRequestWithoutResultRequiresRequireTotal() {
doReturn(7L).when(totalSupplierMock).getAsLong();
Page<Integer> page = PageableExecutionUtils.getPage(Collections.<Integer>emptyList(), PageRequest.of(5, 10),
Page<Integer> page = PageableExecutionUtils.getPage(Collections.<Integer> emptyList(), PageRequest.of(5, 10),
totalSupplierMock);
assertThat(page.getTotalElements()).isEqualTo(7L);

View File

@@ -29,6 +29,7 @@ import org.springframework.data.domain.Sort;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.data.repository.core.RepositoryMetadata;
import org.springframework.data.repository.core.support.DefaultRepositoryMetadata;
import org.springframework.data.repository.support.RepositoryInvocationTestUtils.VerifyingMethodInterceptor;
import org.springframework.format.support.DefaultFormattingConversionService;
/**
@@ -45,7 +46,7 @@ public class PaginginAndSortingRepositoryInvokerUnitTests {
Method method = PagingAndSortingRepository.class.getMethod("findAll", Pageable.class);
getInvokerFor(repository, expectInvocationOf(method)).invokeFindAll(PageRequest.of(0, 10));
getInvokerFor(repository, expectInvocationOf(method)).invokeFindAll(Pageable.NONE);
getInvokerFor(repository, expectInvocationOf(method)).invokeFindAll(Pageable.unpaged());
}
@Test // DATACMNS-589
@@ -65,7 +66,7 @@ public class PaginginAndSortingRepositoryInvokerUnitTests {
Method method = RepositoryWithRedeclaredFindAllWithPageable.class.getMethod("findAll", Pageable.class);
getInvokerFor(repository, expectInvocationOf(method)).invokeFindAll(PageRequest.of(0, 10));
getInvokerFor(repository, expectInvocationOf(method)).invokeFindAll(Pageable.NONE);
getInvokerFor(repository, expectInvocationOf(method)).invokeFindAll(Pageable.unpaged());
}
@Test // DATACMNS-589

View File

@@ -45,6 +45,7 @@ import org.springframework.data.repository.core.support.DefaultRepositoryMetadat
import org.springframework.data.repository.query.Param;
import org.springframework.data.repository.support.CrudRepositoryInvokerUnitTests.Person;
import org.springframework.data.repository.support.CrudRepositoryInvokerUnitTests.PersonRepository;
import org.springframework.data.repository.support.RepositoryInvocationTestUtils.VerifyingMethodInterceptor;
import org.springframework.format.support.DefaultFormattingConversionService;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
@@ -103,7 +104,7 @@ public class ReflectionRepositoryInvokerUnitTests {
Method method = ManualCrudRepository.class.getMethod("findAll");
ManualCrudRepository repository = mock(ManualCrudRepository.class);
getInvokerFor(repository, expectInvocationOf(method)).invokeFindAll(Pageable.NONE);
getInvokerFor(repository, expectInvocationOf(method)).invokeFindAll(Pageable.unpaged());
getInvokerFor(repository, expectInvocationOf(method)).invokeFindAll(PageRequest.of(0, 10));
getInvokerFor(repository, expectInvocationOf(method)).invokeFindAll(Sort.unsorted());
getInvokerFor(repository, expectInvocationOf(method)).invokeFindAll(Sort.by("foo"));
@@ -115,7 +116,7 @@ public class ReflectionRepositoryInvokerUnitTests {
Method method = RepoWithFindAllWithSort.class.getMethod("findAll", Sort.class);
RepoWithFindAllWithSort repository = mock(RepoWithFindAllWithSort.class);
getInvokerFor(repository, expectInvocationOf(method)).invokeFindAll(Pageable.NONE);
getInvokerFor(repository, expectInvocationOf(method)).invokeFindAll(Pageable.unpaged());
getInvokerFor(repository, expectInvocationOf(method)).invokeFindAll(PageRequest.of(0, 10));
getInvokerFor(repository, expectInvocationOf(method)).invokeFindAll(Sort.unsorted());
getInvokerFor(repository, expectInvocationOf(method)).invokeFindAll(Sort.by("foo"));
@@ -127,7 +128,7 @@ public class ReflectionRepositoryInvokerUnitTests {
Method method = RepoWithFindAllWithPageable.class.getMethod("findAll", Pageable.class);
RepoWithFindAllWithPageable repository = mock(RepoWithFindAllWithPageable.class);
getInvokerFor(repository, expectInvocationOf(method)).invokeFindAll(Pageable.NONE);
getInvokerFor(repository, expectInvocationOf(method)).invokeFindAll(Pageable.unpaged());
getInvokerFor(repository, expectInvocationOf(method)).invokeFindAll(PageRequest.of(0, 10));
}
@@ -140,7 +141,7 @@ public class ReflectionRepositoryInvokerUnitTests {
Method method = PersonRepository.class.getMethod("findByFirstName", String.class, Pageable.class);
PersonRepository repository = mock(PersonRepository.class);
getInvokerFor(repository, expectInvocationOf(method)).invokeQueryMethod(method, parameters, Pageable.NONE,
getInvokerFor(repository, expectInvocationOf(method)).invokeQueryMethod(method, parameters, Pageable.unpaged(),
Sort.unsorted());
}
@@ -153,7 +154,7 @@ public class ReflectionRepositoryInvokerUnitTests {
Method method = PersonRepository.class.getMethod("findByCreatedUsingISO8601Date", Date.class, Pageable.class);
PersonRepository repository = mock(PersonRepository.class);
getInvokerFor(repository, expectInvocationOf(method)).invokeQueryMethod(method, parameters, Pageable.NONE,
getInvokerFor(repository, expectInvocationOf(method)).invokeQueryMethod(method, parameters, Pageable.unpaged(),
Sort.unsorted());
}
@@ -213,7 +214,7 @@ public class ReflectionRepositoryInvokerUnitTests {
Method method = PersonRepository.class.getMethod("findByIdIn", Collection.class);
PersonRepository repository = mock(PersonRepository.class);
getInvokerFor(repository, expectInvocationOf(method)).invokeQueryMethod(method, parameters, Pageable.NONE,
getInvokerFor(repository, expectInvocationOf(method)).invokeQueryMethod(method, parameters, Pageable.unpaged(),
Sort.unsorted());
}
}
@@ -229,7 +230,7 @@ public class ReflectionRepositoryInvokerUnitTests {
Method method = SimpleRepository.class.getMethod("findByClass", int.class);
try {
invoker.invokeQueryMethod(method, parameters, Pageable.NONE, Sort.unsorted());
invoker.invokeQueryMethod(method, parameters, Pageable.unpaged(), Sort.unsorted());
} catch (QueryMethodParameterConversionException o_O) {
assertThat(o_O.getParameter()).isEqualTo(new MethodParameters(method).getParameters().get(0));