Package org.assertj.core.presentation
Interface Representation
-
- All Known Implementing Classes:
BinaryRepresentation,HexadecimalRepresentation,StandardRepresentation,UnicodeRepresentation
public interface RepresentationControls the formatting (String representation) of types in assertion error message.There are two ways to replace the default
Representation(StandardRepresentation):- call
Assertions.useRepresentation(Representation), from this point all the assertions will use the given representation - register a representation as a service discovered at program startup
The advantage of registering a representation is that you don't need to do anything in your tests, the java runtime will discover it and AssertJ will use it but it requires a bit more work than a simple call to
Assertions.useRepresentation(Representation).To register a
Representation, you need to do several things:- create a file named
org.assertj.core.presentation.Representationfile in META-INF/services directory - put the fully qualified class name of your
Representationin it - make sure
META-INF/services/org.assertj.core.presentation.Representationis in the runtime classpath, usually putting it insrc/test/resourcesis enough - we recommend that you extend from the
StandardRepresentationand override theStandardRepresentation.fallbackToStringOf(Object). By doing this all the defaults of AssertJ would be applied and you can apply your own customization
The assertj-examples project provides a working example of registering a custom representation.
Registering a representation has been introduced in AssertJ 2.9.0/3.9.0.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description java.lang.StringtoStringOf(java.lang.Object object)Returns theStringrepresentation of the given object.java.lang.StringunambiguousToStringOf(java.lang.Object object)Returns theStringrepresentation of the given object with its type and hexadecimal identity hash code so that it can be differentiated from other objects with the sametoStringOf(Object)representation.
-
-
-
Method Detail
-
toStringOf
java.lang.String toStringOf(java.lang.Object object)
Returns theStringrepresentation of the given object. It may or may not be the object's own implementation oftoString.- Parameters:
object- the object to represent.- Returns:
- the
toStringrepresentation of the given object.
-
unambiguousToStringOf
java.lang.String unambiguousToStringOf(java.lang.Object object)
Returns theStringrepresentation of the given object with its type and hexadecimal identity hash code so that it can be differentiated from other objects with the sametoStringOf(Object)representation.- Parameters:
object- the object to represent.- Returns:
- the unambiguous
toStringrepresentation of the given object.
-
-