DATACMNS-713 - PageImpl now adapts total if necessary.

On a last page the total handed into a PageImpl constructor might not necessarily fit the content as there's the change of an insertion or deletion between the calculated count and the retrieval of the content. We now leniently mitigate those differences if the page created is the last page of the result.

Related tickets: DATAJPA-728, DATACMNS-615.
This commit is contained in:
Oliver Gierke
2015-06-15 14:18:09 +02:00
parent 7107a599bb
commit de4f1ffb7b
2 changed files with 38 additions and 13 deletions

View File

@@ -128,14 +128,6 @@ public class PageImplUnitTests {
assertThat(page.hasPrevious(), is(false));
}
/**
* @see DATACMNS-615
*/
@Test(expected = IllegalArgumentException.class)
public void rejectsTotalLessThanContentLength() {
new PageImpl<String>(Arrays.asList("foo", "bar"), new PageRequest(0, 10), 1);
}
/**
* @see DATACMNS-635
*/
@@ -153,4 +145,38 @@ public class PageImplUnitTests {
assertThat(transformed.getContent(), hasSize(2));
assertThat(transformed.getContent(), contains(3, 3));
}
/**
* @see DATACMNS-713
*/
@Test
public void adaptsTotalForLastPageOnIntermediateDeletion() {
assertThat(new PageImpl<String>(Arrays.asList("foo", "bar"), new PageRequest(0, 5), 3).getTotalElements(), is(2L));
}
/**
* @see DATACMNS-713
*/
@Test
public void adaptsTotalForLastPageOnIntermediateInsertion() {
assertThat(new PageImpl<String>(Arrays.asList("foo", "bar"), new PageRequest(0, 5), 1).getTotalElements(), is(2L));
}
/**
* @see DATACMNS-713
*/
@Test
public void adaptsTotalForLastPageOnIntermediateDeletionOnLastPate() {
assertThat(new PageImpl<String>(Arrays.asList("foo", "bar"), new PageRequest(1, 10), 13).getTotalElements(),
is(12L));
}
/**
* @see DATACMNS-713
*/
@Test
public void adaptsTotalForLastPageOnIntermediateInsertionOnLastPate() {
assertThat(new PageImpl<String>(Arrays.asList("foo", "bar"), new PageRequest(1, 10), 11).getTotalElements(),
is(12L));
}
}