Skip to content

Commit 83c6e07

Browse files
Add a default implementation for unambiguousToStringOf in Representation.
1 parent 35bed61 commit 83c6e07

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

src/main/java/org/assertj/core/presentation/Representation.java

+8-3
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,18 @@ public interface Representation {
6565
String toStringOf(Object object);
6666

6767
/**
68-
* Returns the {@code String} representation of the given object with its type and hexadecimal identity hash code so that
69-
* it can be differentiated from other objects with the same {@link #toStringOf(Object)} representation.
68+
* Override this method to return a {@code String} representation of the given object that is unambigous so that it can
69+
* be differentiated from other objects with the same {@link #toStringOf(Object)} representation.
70+
* <p>
71+
* The default implementation calls {@link #toStringOf(Object)} but the {@link StandardRepresentation} adds
72+
* the object hexadecimal identity hash code.
7073
*
7174
* @param object the object to represent.
7275
* @return the unambiguous {@code toString} representation of the given object.
7376
*/
74-
String unambiguousToStringOf(Object object);
77+
default String unambiguousToStringOf(Object object) {
78+
return toStringOf(object);
79+
}
7580

7681
/**
7782
* In case multiple representations are loaded through {@link ServiceLoader} and they can represent the same types the one with the highest priority is selected.

src/main/java/org/assertj/core/presentation/StandardRepresentation.java

+7
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,13 @@ private static boolean hasOverriddenToStringInSubclassOf(Class<?> objectClass, C
286286
return false;
287287
}
288288

289+
/**
290+
* Returns the {@code String} representation of the given object with its type and hexadecimal identity hash code so that
291+
* it can be differentiated from other objects with the same {@link #toStringOf(Object)} representation.
292+
*
293+
* @param object the object to represent.
294+
* @return the unambiguous {@code toString} representation of the given object.
295+
*/
289296
@Override
290297
public String unambiguousToStringOf(Object obj) {
291298
// some types have already an unambiguous toString, no need to double down

0 commit comments

Comments
 (0)