Skip to content

Commit 3af13c4

Browse files
manousosManousos Mathioudakis
authored and
Manousos Mathioudakis
committed
Fix same toString representation for different page instances. Closes spring-projects#2066
1 parent 6b0292c commit 3af13c4

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

src/main/java/org/springframework/data/domain/PageImpl.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
* @param <T> the type of which the page consists.
2727
* @author Oliver Gierke
2828
* @author Mark Paluch
29+
* @author Manousos Mathioudakis
2930
*/
3031
public class PageImpl<T> extends Chunk<T> implements Page<T> {
3132

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

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

126128
/*

src/test/java/org/springframework/data/domain/PageImplUnitTests.java

+11-1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
*
3030
* @author Oliver Gierke
3131
* @author Mark Paluch
32+
* @author Manousos Mathioudakis
3233
*/
3334
class PageImplUnitTests {
3435

@@ -191,7 +192,16 @@ void toStringShouldNotInspectNullInstances() {
191192

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

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

198+
@Test //issue 2066
199+
void toStringShouldNotBeEqualsForDifferentPages() {
200+
Page<String> page1 = new PageImpl<>(Arrays.asList("item1", "item2"), PageRequest.of(0, 5), 10);
201+
Page<String> page2 = new PageImpl<>(Arrays.asList("item1", "item3"), PageRequest.of(0, 5), 10);
202+
203+
assertThat(page1.toString()).isNotEqualTo(page2.toString());
204+
}
205+
206+
197207
}

0 commit comments

Comments
 (0)