From 86c108697604979d37958eaa264fa8751dd93797 Mon Sep 17 00:00:00 2001 From: Oliver Gierke Date: Tue, 19 Jul 2016 15:03:16 +0200 Subject: [PATCH] DATACMNS-884 - Polishing. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Renamed PageableExecutionSupport to …Utils as …Support classes are usually empty adapter classes for interfaces and meant to be extended. --- ...pport.java => PageableExecutionUtils.java} | 6 ++-- ...a => PageableExecutionUtilsUnitTests.java} | 30 +++++++++++-------- 2 files changed, 21 insertions(+), 15 deletions(-) rename src/main/java/org/springframework/data/repository/support/{PageableExecutionSupport.java => PageableExecutionUtils.java} (94%) rename src/test/java/org/springframework/data/repository/support/{PageableExecutionSupportUnitTests.java => PageableExecutionUtilsUnitTests.java} (75%) diff --git a/src/main/java/org/springframework/data/repository/support/PageableExecutionSupport.java b/src/main/java/org/springframework/data/repository/support/PageableExecutionUtils.java similarity index 94% rename from src/main/java/org/springframework/data/repository/support/PageableExecutionSupport.java rename to src/main/java/org/springframework/data/repository/support/PageableExecutionUtils.java index 1f070cde2..c222ed596 100644 --- a/src/main/java/org/springframework/data/repository/support/PageableExecutionSupport.java +++ b/src/main/java/org/springframework/data/repository/support/PageableExecutionUtils.java @@ -23,15 +23,15 @@ import org.springframework.data.domain.Pageable; import org.springframework.util.Assert; /** - * Support for query execution using {@link Pageable}. Using {@link PageableExecutionSupport} assumes that data queries + * Support for query execution using {@link Pageable}. Using {@link PageableExecutionUtils} assumes that data queries * are cheaper than {@code COUNT} queries and so some cases can take advantage of optimizations. * * @author Mark Paluch * @since 1.13 */ -public abstract class PageableExecutionSupport { +public abstract class PageableExecutionUtils { - private PageableExecutionSupport() {} + private PageableExecutionUtils() {} /** * Constructs a {@link Page} based on the given {@code content}, {@link Pageable} and {@link TotalSupplier} applying diff --git a/src/test/java/org/springframework/data/repository/support/PageableExecutionSupportUnitTests.java b/src/test/java/org/springframework/data/repository/support/PageableExecutionUtilsUnitTests.java similarity index 75% rename from src/test/java/org/springframework/data/repository/support/PageableExecutionSupportUnitTests.java rename to src/test/java/org/springframework/data/repository/support/PageableExecutionUtilsUnitTests.java index c7a481d9e..fbe50ab6c 100644 --- a/src/test/java/org/springframework/data/repository/support/PageableExecutionSupportUnitTests.java +++ b/src/test/java/org/springframework/data/repository/support/PageableExecutionUtilsUnitTests.java @@ -28,15 +28,16 @@ import org.mockito.Mock; import org.mockito.runners.MockitoJUnitRunner; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageRequest; -import org.springframework.data.repository.support.PageableExecutionSupport.TotalSupplier; +import org.springframework.data.repository.support.PageableExecutionUtils.TotalSupplier; /** - * Unit tests for {@link PageableExecutionSupport}. + * Unit tests for {@link PageableExecutionUtils}. * * @author Mark Paluch + * @author Oliver Gierke */ @RunWith(MockitoJUnitRunner.class) -public class PageableExecutionSupportUnitTests { +public class PageableExecutionUtilsUnitTests { @Mock TotalSupplier totalSupplierMock; @@ -46,7 +47,7 @@ public class PageableExecutionSupportUnitTests { @Test public void firstPageRequestIsLessThanOneFullPageDoesNotRequireTotal() { - Page page = PageableExecutionSupport.getPage(Arrays.asList(1, 2, 3), new PageRequest(0, 10), + Page page = PageableExecutionUtils.getPage(Arrays.asList(1, 2, 3), new PageRequest(0, 10), totalSupplierMock); assertThat(page, hasItems(1, 2, 3)); @@ -60,10 +61,11 @@ public class PageableExecutionSupportUnitTests { @Test public void noPageableRequesDoesNotRequireTotal() { - Page page = PageableExecutionSupport.getPage(Arrays.asList(1, 2, 3), null, totalSupplierMock); + Page page = PageableExecutionUtils.getPage(Arrays.asList(1, 2, 3), null, totalSupplierMock); assertThat(page, hasItems(1, 2, 3)); assertThat(page.getTotalElements(), is(3L)); + verifyZeroInteractions(totalSupplierMock); } @@ -73,11 +75,12 @@ public class PageableExecutionSupportUnitTests { @Test public void subsequentPageRequestIsLessThanOneFullPageDoesNotRequireTotal() { - Page page = PageableExecutionSupport.getPage(Arrays.asList(1, 2, 3), new PageRequest(5, 10), + Page page = PageableExecutionUtils.getPage(Arrays.asList(1, 2, 3), new PageRequest(5, 10), totalSupplierMock); assertThat(page, hasItems(1, 2, 3)); assertThat(page.getTotalElements(), is(53L)); + verifyZeroInteractions(totalSupplierMock); } @@ -87,13 +90,14 @@ public class PageableExecutionSupportUnitTests { @Test public void firstPageRequestHitsUpperBoundRequiresTotal() { - when(totalSupplierMock.get()).thenReturn(4L); + doReturn(4L).when(totalSupplierMock).get(); - Page page = PageableExecutionSupport.getPage(Arrays.asList(1, 2, 3), new PageRequest(0, 3), + Page page = PageableExecutionUtils.getPage(Arrays.asList(1, 2, 3), new PageRequest(0, 3), totalSupplierMock); assertThat(page, hasItems(1, 2, 3)); assertThat(page.getTotalElements(), is(4L)); + verify(totalSupplierMock).get(); } @@ -103,13 +107,14 @@ public class PageableExecutionSupportUnitTests { @Test public void subsequentPageRequestHitsUpperBoundRequiresTotal() { - when(totalSupplierMock.get()).thenReturn(7L); + doReturn(7L).when(totalSupplierMock).get(); - Page page = PageableExecutionSupport.getPage(Arrays.asList(1, 2, 3), new PageRequest(1, 3), + Page page = PageableExecutionUtils.getPage(Arrays.asList(1, 2, 3), new PageRequest(1, 3), totalSupplierMock); assertThat(page, hasItems(1, 2, 3)); assertThat(page.getTotalElements(), is(7L)); + verify(totalSupplierMock).get(); } @@ -119,11 +124,12 @@ public class PageableExecutionSupportUnitTests { @Test public void subsequentPageRequestWithoutResultRequiresRequireTotal() { - when(totalSupplierMock.get()).thenReturn(7L); - Page page = PageableExecutionSupport.getPage(Collections. emptyList(), new PageRequest(5, 10), + doReturn(7L).when(totalSupplierMock).get(); + Page page = PageableExecutionUtils.getPage(Collections.emptyList(), new PageRequest(5, 10), totalSupplierMock); assertThat(page.getTotalElements(), is(7L)); + verify(totalSupplierMock).get(); } }