public interface Representation
There are two ways to replace the default Representation
(StandardRepresentation
):
Assertions.useRepresentation(Representation)
, from this point all the assertions will use the given representation
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:
org.assertj.core.presentation.Representation
file in META-INF/services directoryRepresentation
in itMETA-INF/services/org.assertj.core.presentation.Representation
is in the runtime classpath, usually putting it in src/test/resources
is enoughStandardRepresentation
and override the
StandardRepresentation.fallbackToStringOf(Object)
. By doing this all the defaults of AssertJ would be applied and you can apply your own customizationThe 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.
Modifier and Type | Method and Description |
---|---|
String |
toStringOf(Object object)
Returns the
String representation of the given object. |
String |
unambiguousToStringOf(Object object)
Returns the
String representation of the given object with its type and hexadecimal identity hash code so that
it can be differentiated from other objects with the same toStringOf(Object) representation. |
String toStringOf(Object object)
String
representation of the given object. It may or may not be the object's own implementation of
toString
.object
- the object to represent.toString
representation of the given object.String unambiguousToStringOf(Object object)
String
representation of the given object with its type and hexadecimal identity hash code so that
it can be differentiated from other objects with the same toStringOf(Object)
representation.object
- the object to represent.toString
representation of the given object.Copyright © 2014–2019 AssertJ. All rights reserved.