Skip to content

Commit

Permalink
Fix same toString representation for different page instances. Closes s…
Browse files Browse the repository at this point in the history
  • Loading branch information
manousos authored and Manousos Mathioudakis committed Mar 4, 2021
1 parent 6b0292c commit 3af13c4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/main/java/org/springframework/data/domain/PageImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
* @param <T> the type of which the page consists.
* @author Oliver Gierke
* @author Mark Paluch
* @author Manousos Mathioudakis
*/
public class PageImpl<T> extends Chunk<T> implements Page<T> {

Expand Down Expand Up @@ -120,7 +121,8 @@ public String toString() {
contentType = content.get(0).getClass().getName();
}

return String.format("Page %s of %d containing %s instances", getNumber() + 1, getTotalPages(), contentType);
return String.format("Page %s of %d containing %s instances @%s",
getNumber() + 1, getTotalPages(), contentType, Integer.toHexString(hashCode()));
}

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
*
* @author Oliver Gierke
* @author Mark Paluch
* @author Manousos Mathioudakis
*/
class PageImplUnitTests {

Expand Down Expand Up @@ -191,7 +192,16 @@ void toStringShouldNotInspectNullInstances() {

Page<Integer> page = new PageImpl<>(Collections.singletonList(null));

assertThat(page).hasToString("Page 1 of 1 containing UNKNOWN instances");
assertThat(page).hasToString(String.format("Page 1 of 1 containing UNKNOWN instances @%s", Integer.toHexString(page.hashCode())));
}

@Test //issue 2066
void toStringShouldNotBeEqualsForDifferentPages() {
Page<String> page1 = new PageImpl<>(Arrays.asList("item1", "item2"), PageRequest.of(0, 5), 10);
Page<String> page2 = new PageImpl<>(Arrays.asList("item1", "item3"), PageRequest.of(0, 5), 10);

assertThat(page1.toString()).isNotEqualTo(page2.toString());
}


}

0 comments on commit 3af13c4

Please sign in to comment.