DATACMNS-867 - Second draft.
This commit is contained in:
@@ -23,7 +23,6 @@ import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.core.convert.converter.Converter;
|
||||
|
||||
/**
|
||||
* Unit test for {@link PageImpl}.
|
||||
@@ -35,76 +34,76 @@ public class PageImplUnitTests {
|
||||
@Test
|
||||
public void assertEqualsForSimpleSetup() throws Exception {
|
||||
|
||||
PageImpl<String> page = new PageImpl<String>(Arrays.asList("Foo"));
|
||||
PageImpl<String> page = new PageImpl<>(Arrays.asList("Foo"));
|
||||
|
||||
assertEqualsAndHashcode(page, page);
|
||||
assertEqualsAndHashcode(page, new PageImpl<String>(Arrays.asList("Foo")));
|
||||
assertEqualsAndHashcode(page, new PageImpl<>(Arrays.asList("Foo")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void assertEqualsForComplexSetup() throws Exception {
|
||||
|
||||
Pageable pageable = new PageRequest(0, 10);
|
||||
Pageable pageable = PageRequest.of(0, 10);
|
||||
List<String> content = Arrays.asList("Foo");
|
||||
|
||||
PageImpl<String> page = new PageImpl<String>(content, pageable, 100);
|
||||
PageImpl<String> page = new PageImpl<>(content, pageable, 100);
|
||||
|
||||
assertEqualsAndHashcode(page, page);
|
||||
assertEqualsAndHashcode(page, new PageImpl<String>(content, pageable, 100));
|
||||
assertNotEqualsAndHashcode(page, new PageImpl<String>(content, pageable, 90));
|
||||
assertNotEqualsAndHashcode(page, new PageImpl<String>(content, new PageRequest(1, 10), 100));
|
||||
assertNotEqualsAndHashcode(page, new PageImpl<String>(content, new PageRequest(0, 15), 100));
|
||||
assertEqualsAndHashcode(page, new PageImpl<>(content, pageable, 100));
|
||||
assertNotEqualsAndHashcode(page, new PageImpl<>(content, pageable, 90));
|
||||
assertNotEqualsAndHashcode(page, new PageImpl<>(content, PageRequest.of(1, 10), 100));
|
||||
assertNotEqualsAndHashcode(page, new PageImpl<>(content, PageRequest.of(0, 15), 100));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void preventsNullContentForSimpleSetup() throws Exception {
|
||||
new PageImpl<Object>(null);
|
||||
new PageImpl<>(null);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void preventsNullContentForAdvancedSetup() throws Exception {
|
||||
new PageImpl<Object>(null, null, 0);
|
||||
new PageImpl<>(null, null, 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void returnsNextPageable() {
|
||||
|
||||
Page<Object> page = new PageImpl<Object>(Arrays.asList(new Object()), new PageRequest(0, 1), 10);
|
||||
Page<Object> page = new PageImpl<>(Arrays.asList(new Object()), PageRequest.of(0, 1), 10);
|
||||
|
||||
assertThat(page.isFirst()).isTrue();
|
||||
assertThat(page.hasPrevious()).isFalse();
|
||||
assertThat(page.previousPageable()).isNull();
|
||||
assertThat(page.previousPageable()).isEqualTo(Pageable.NONE);
|
||||
|
||||
assertThat(page.isLast()).isFalse();
|
||||
assertThat(page.hasNext()).isTrue();
|
||||
assertThat(page.nextPageable()).isEqualTo((Pageable) new PageRequest(1, 1));
|
||||
assertThat(page.nextPageable()).isEqualTo((Pageable) PageRequest.of(1, 1));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void returnsPreviousPageable() {
|
||||
|
||||
Page<Object> page = new PageImpl<Object>(Arrays.asList(new Object()), new PageRequest(1, 1), 2);
|
||||
Page<Object> page = new PageImpl<>(Arrays.asList(new Object()), PageRequest.of(1, 1), 2);
|
||||
|
||||
assertThat(page.isFirst()).isFalse();
|
||||
assertThat(page.hasPrevious()).isTrue();
|
||||
assertThat(page.previousPageable()).isEqualTo((Pageable) new PageRequest(0, 1));
|
||||
assertThat(page.previousPageable()).isEqualTo((Pageable) PageRequest.of(0, 1));
|
||||
|
||||
assertThat(page.isLast()).isTrue();
|
||||
assertThat(page.hasNext()).isFalse();
|
||||
assertThat(page.nextPageable()).isNull();
|
||||
assertThat(page.nextPageable()).isEqualTo(Pageable.NONE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createsPageForEmptyContentCorrectly() {
|
||||
|
||||
List<String> list = Collections.emptyList();
|
||||
Page<String> page = new PageImpl<String>(list);
|
||||
Page<String> page = new PageImpl<>(list);
|
||||
|
||||
assertThat(page.getContent()).isEqualTo(list);
|
||||
assertThat(page.getNumber()).isEqualTo(0);
|
||||
assertThat(page.getNumberOfElements()).isEqualTo(0);
|
||||
assertThat(page.getSize()).isEqualTo(0);
|
||||
assertThat(page.getSort()).isEqualTo((Sort) null);
|
||||
assertThat(page.getSort()).isEqualTo(Sort.unsorted());
|
||||
assertThat(page.getTotalElements()).isEqualTo(0L);
|
||||
assertThat(page.getTotalPages()).isEqualTo(1);
|
||||
assertThat(page.hasNext()).isFalse();
|
||||
@@ -117,7 +116,7 @@ public class PageImplUnitTests {
|
||||
@Test // DATACMNS-323
|
||||
public void returnsCorrectTotalPages() {
|
||||
|
||||
Page<String> page = new PageImpl<String>(Arrays.asList("a"));
|
||||
Page<String> page = new PageImpl<>(Arrays.asList("a"));
|
||||
|
||||
assertThat(page.getTotalPages()).isEqualTo(1);
|
||||
assertThat(page.hasNext()).isFalse();
|
||||
@@ -127,13 +126,8 @@ public class PageImplUnitTests {
|
||||
@Test // DATACMNS-635
|
||||
public void transformsPageCorrectly() {
|
||||
|
||||
Page<Integer> transformed = new PageImpl<String>(Arrays.asList("foo", "bar"), new PageRequest(0, 2), 10)
|
||||
.map(new Converter<String, Integer>() {
|
||||
@Override
|
||||
public Integer convert(String source) {
|
||||
return source.length();
|
||||
}
|
||||
});
|
||||
Page<Integer> transformed = new PageImpl<>(Arrays.asList("foo", "bar"), PageRequest.of(0, 2), 10)
|
||||
.map(source -> source.length());
|
||||
|
||||
assertThat(transformed.getContent()).hasSize(2);
|
||||
assertThat(transformed.getContent()).contains(3, 3);
|
||||
@@ -141,32 +135,30 @@ public class PageImplUnitTests {
|
||||
|
||||
@Test // DATACMNS-713
|
||||
public void adaptsTotalForLastPageOnIntermediateDeletion() {
|
||||
assertThat(new PageImpl<String>(Arrays.asList("foo", "bar"), new PageRequest(0, 5), 3).getTotalElements())
|
||||
.isEqualTo(2L);
|
||||
assertThat(new PageImpl<>(Arrays.asList("foo", "bar"), PageRequest.of(0, 5), 3).getTotalElements()).isEqualTo(2L);
|
||||
}
|
||||
|
||||
@Test // DATACMNS-713
|
||||
public void adaptsTotalForLastPageOnIntermediateInsertion() {
|
||||
assertThat(new PageImpl<String>(Arrays.asList("foo", "bar"), new PageRequest(0, 5), 1).getTotalElements())
|
||||
.isEqualTo(2L);
|
||||
assertThat(new PageImpl<>(Arrays.asList("foo", "bar"), PageRequest.of(0, 5), 1).getTotalElements()).isEqualTo(2L);
|
||||
}
|
||||
|
||||
@Test // DATACMNS-713
|
||||
public void adaptsTotalForLastPageOnIntermediateDeletionOnLastPate() {
|
||||
assertThat(new PageImpl<String>(Arrays.asList("foo", "bar"), new PageRequest(1, 10), 13).getTotalElements())
|
||||
assertThat(new PageImpl<>(Arrays.asList("foo", "bar"), PageRequest.of(1, 10), 13).getTotalElements())
|
||||
.isEqualTo(12L);
|
||||
}
|
||||
|
||||
@Test // DATACMNS-713
|
||||
public void adaptsTotalForLastPageOnIntermediateInsertionOnLastPate() {
|
||||
assertThat(new PageImpl<String>(Arrays.asList("foo", "bar"), new PageRequest(1, 10), 11).getTotalElements())
|
||||
assertThat(new PageImpl<>(Arrays.asList("foo", "bar"), PageRequest.of(1, 10), 11).getTotalElements())
|
||||
.isEqualTo(12L);
|
||||
}
|
||||
|
||||
@Test // DATACMNS-713
|
||||
public void doesNotAdapttotalIfPageIsEmpty() {
|
||||
|
||||
assertThat(new PageImpl<String>(Collections.<String> emptyList(), new PageRequest(1, 10), 0).getTotalElements())
|
||||
assertThat(new PageImpl<>(Collections.<String>emptyList(), PageRequest.of(1, 10), 0).getTotalElements())
|
||||
.isEqualTo(0L);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,32 +33,32 @@ public class PageRequestUnitTests extends AbstractPageRequestUnitTests {
|
||||
*/
|
||||
@Override
|
||||
public AbstractPageRequest newPageRequest(int page, int size) {
|
||||
return this.newPageRequest(page, size, null);
|
||||
return PageRequest.of(page, size);
|
||||
}
|
||||
|
||||
public AbstractPageRequest newPageRequest(int page, int size, Sort sort) {
|
||||
return new PageRequest(page, size, sort);
|
||||
return PageRequest.of(page, size, sort);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void equalsRegardsSortCorrectly() {
|
||||
|
||||
Sort sort = new Sort(Direction.DESC, "foo");
|
||||
AbstractPageRequest request = new PageRequest(0, 10, sort);
|
||||
AbstractPageRequest request = PageRequest.of(0, 10, sort);
|
||||
|
||||
// Equals itself
|
||||
assertEqualsAndHashcode(request, request);
|
||||
|
||||
// Equals another instance with same setup
|
||||
assertEqualsAndHashcode(request, new PageRequest(0, 10, sort));
|
||||
assertEqualsAndHashcode(request, PageRequest.of(0, 10, sort));
|
||||
|
||||
// Equals without sort entirely
|
||||
assertEqualsAndHashcode(new PageRequest(0, 10), new PageRequest(0, 10));
|
||||
assertEqualsAndHashcode(PageRequest.of(0, 10), PageRequest.of(0, 10));
|
||||
|
||||
// Is not equal to instance without sort
|
||||
assertNotEqualsAndHashcode(request, new PageRequest(0, 10));
|
||||
assertNotEqualsAndHashcode(request, PageRequest.of(0, 10));
|
||||
|
||||
// Is not equal to instance with another sort
|
||||
assertNotEqualsAndHashcode(request, new PageRequest(0, 10, Direction.ASC, "foo"));
|
||||
assertNotEqualsAndHashcode(request, PageRequest.of(0, 10, Direction.ASC, "foo"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,13 +29,13 @@ public class RangeUnitTests {
|
||||
|
||||
@Test(expected = IllegalArgumentException.class) // DATACMNS-651
|
||||
public void rejectsNullReferenceValuesForContains() {
|
||||
new Range<Long>(10L, 20L).contains(null);
|
||||
new Range<>(10L, 20L).contains(null);
|
||||
}
|
||||
|
||||
@Test // DATACMNS-651
|
||||
public void usesBoundsInclusivelyByDefault() {
|
||||
|
||||
Range<Long> range = new Range<Long>(10L, 20L);
|
||||
Range<Long> range = new Range<>(10L, 20L);
|
||||
|
||||
assertThat(range.contains(10L)).isTrue();
|
||||
assertThat(range.contains(20L)).isTrue();
|
||||
@@ -47,7 +47,7 @@ public class RangeUnitTests {
|
||||
@Test // DATACMNS-651
|
||||
public void excludesLowerBoundIfConfigured() {
|
||||
|
||||
Range<Long> range = new Range<Long>(10L, 20L, false, true);
|
||||
Range<Long> range = new Range<>(10L, 20L, false, true);
|
||||
|
||||
assertThat(range.contains(10L)).isFalse();
|
||||
assertThat(range.contains(20L)).isTrue();
|
||||
@@ -59,7 +59,7 @@ public class RangeUnitTests {
|
||||
@Test // DATACMNS-651
|
||||
public void excludesUpperBoundIfConfigured() {
|
||||
|
||||
Range<Long> range = new Range<Long>(10L, 20L, true, false);
|
||||
Range<Long> range = new Range<>(10L, 20L, true, false);
|
||||
|
||||
assertThat(range.contains(10L)).isTrue();
|
||||
assertThat(range.contains(20L)).isFalse();
|
||||
@@ -71,7 +71,7 @@ public class RangeUnitTests {
|
||||
@Test // DATACMNS-651
|
||||
public void handlesOpenUpperBoundCorrectly() {
|
||||
|
||||
Range<Long> range = new Range<Long>(10L, null);
|
||||
Range<Long> range = new Range<>(10L, null);
|
||||
|
||||
assertThat(range.contains(10L)).isTrue();
|
||||
assertThat(range.contains(20L)).isTrue();
|
||||
@@ -83,7 +83,7 @@ public class RangeUnitTests {
|
||||
@Test // DATACMNS-651
|
||||
public void handlesOpenLowerBoundCorrectly() {
|
||||
|
||||
Range<Long> range = new Range<Long>(null, 20L);
|
||||
Range<Long> range = new Range<>(null, 20L);
|
||||
|
||||
assertThat(range.contains(10L)).isTrue();
|
||||
assertThat(range.contains(20L)).isTrue();
|
||||
|
||||
@@ -39,7 +39,7 @@ public class SortUnitTests {
|
||||
@Test
|
||||
public void appliesDefaultForOrder() throws Exception {
|
||||
|
||||
assertThat(new Sort("foo").iterator().next().getDirection()).isEqualTo(Sort.DEFAULT_DIRECTION);
|
||||
assertThat(Sort.by("foo").iterator().next().getDirection()).isEqualTo(Sort.DEFAULT_DIRECTION);
|
||||
assertThat(new Sort((Direction) null, "foo").iterator().next().getDirection()).isEqualTo(Sort.DEFAULT_DIRECTION);
|
||||
}
|
||||
|
||||
@@ -90,14 +90,14 @@ public class SortUnitTests {
|
||||
@Test
|
||||
public void allowsCombiningSorts() {
|
||||
|
||||
Sort sort = new Sort("foo").and(new Sort("bar"));
|
||||
Sort sort = Sort.by("foo").and(Sort.by("bar"));
|
||||
assertThat(sort).containsExactly(new Sort.Order("foo"), new Sort.Order("bar"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void handlesAdditionalNullSort() {
|
||||
|
||||
Sort sort = new Sort("foo").and(null);
|
||||
Sort sort = Sort.by("foo").and(null);
|
||||
assertThat(sort).containsExactly(new Sort.Order("foo"));
|
||||
}
|
||||
|
||||
@@ -147,9 +147,9 @@ public class SortUnitTests {
|
||||
Order source = new Order(Direction.DESC, "foo").nullsFirst().ignoreCase();
|
||||
Order result = source.withProperty("bar");
|
||||
|
||||
assertThat(result.getProperty(), is("bar"));
|
||||
assertThat(result.getDirection(), is(source.getDirection()));
|
||||
assertThat(result.getNullHandling(), is(source.getNullHandling()));
|
||||
assertThat(result.isIgnoreCase(), is(source.isIgnoreCase()));
|
||||
assertThat(result.getProperty()).isEqualTo("bar");
|
||||
assertThat(result.getDirection()).isEqualTo(source.getDirection());
|
||||
assertThat(result.getNullHandling()).isEqualTo(source.getNullHandling());
|
||||
assertThat(result.isIgnoreCase()).isEqualTo(source.isIgnoreCase());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,7 +57,7 @@ public class SpringDataJaxbUnitTests {
|
||||
Unmarshaller unmarshaller;
|
||||
|
||||
Sort sort = new Sort(Direction.ASC, "firstname", "lastname");
|
||||
Pageable pageable = new PageRequest(2, 15, sort);
|
||||
Pageable pageable = PageRequest.of(2, 15, sort);
|
||||
Resource resource = new ClassPathResource("pageable.xml", this.getClass());
|
||||
Resource schemaFile = new ClassPathResource("spring-data-jaxb.xsd", this.getClass());
|
||||
|
||||
@@ -81,7 +81,7 @@ public class SpringDataJaxbUnitTests {
|
||||
Wrapper wrapper = new Wrapper();
|
||||
wrapper.pageable = pageable;
|
||||
wrapper.sort = sort;
|
||||
wrapper.pageableWithoutSort = new PageRequest(10, 20);
|
||||
wrapper.pageableWithoutSort = PageRequest.of(10, 20);
|
||||
marshaller.marshal(wrapper, writer);
|
||||
|
||||
assertThat(new Diff(reference, writer.toString()).similar()).isTrue();
|
||||
@@ -103,8 +103,8 @@ public class SpringDataJaxbUnitTests {
|
||||
PageWrapper wrapper = new PageWrapper();
|
||||
Content content = new Content();
|
||||
content.name = "Foo";
|
||||
wrapper.page = new PageImpl<Content>(Arrays.asList(content));
|
||||
wrapper.pageWithLinks = new PageImpl<Content>(Arrays.asList(content));
|
||||
wrapper.page = new PageImpl<>(Arrays.asList(content));
|
||||
wrapper.pageWithLinks = new PageImpl<>(Arrays.asList(content));
|
||||
|
||||
marshaller.marshal(wrapper, new StringWriter());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user