Package org.assertj.core.presentation
Class StandardRepresentation
- java.lang.Object
-
- org.assertj.core.presentation.StandardRepresentation
-
- All Implemented Interfaces:
Representation
- Direct Known Subclasses:
BinaryRepresentation
,HexadecimalRepresentation
,UnicodeRepresentation
public class StandardRepresentation extends Object implements Representation
Standard java object representation.- Author:
- Mariusz Smykula
-
-
Field Summary
Fields Modifier and Type Field Description private static Map<Class<?>,Function<?,String>>
customFormatterByType
private static String
DEFAULT_END
private static String
DEFAULT_MAX_ELEMENTS_EXCEEDED
private static String
DEFAULT_START
static String
ELEMENT_SEPARATOR
static String
ELEMENT_SEPARATOR_WITH_NEWLINE
(package private) static String
INDENTATION_AFTER_NEWLINE
(package private) static String
INDENTATION_FOR_SINGLE_LINE
private static int
maxElementsForPrinting
private static int
maxLengthForSingleLineDescription
private static String
NULL
static StandardRepresentation
STANDARD_REPRESENTATION
private static String
TUPLE_END
private static String
TUPLE_START
-
Constructor Summary
Constructors Constructor Description StandardRepresentation()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected <T> String
customFormat(T object)
private static boolean
doesDescriptionFitOnSingleLine(String singleLineDescription)
protected String
fallbackToStringOf(Object object)
Returns theString
representation of the given object.String
format(Iterable<?> iterable, String start, String end, String elementSeparator, String indentation)
protected String
format(Object[] array, String elementSeparator, String indentation, Set<Object[]> alreadyFormatted)
private String
format(Map<?,?> map, Object o)
protected String
formatArray(Object o)
Returns theString
representation of the given array, ornull
if the given object is eithernull
or not an array.private String
formatLines(List<?> lines)
protected String
formatPrimitiveArray(Object o)
static int
getMaxElementsForPrinting()
static int
getMaxLengthForSingleLineDescription()
protected boolean
hasCustomFormatterFor(Object object)
protected String
multiLineFormat(Iterable<?> iterable)
protected String
multiLineFormat(Object[] iterable, Set<Object[]> alreadyFormatted)
static <T> void
registerFormatterForType(Class<T> type, Function<T,String> formatter)
Registers new formatter for the given type.static void
removeAllRegisteredFormatters()
Clear all formatters registered per type withregisterFormatterForType(Class, Function)
.static void
resetDefaults()
It resets the static defaults for the standard representation.static void
setMaxElementsForPrinting(int value)
static void
setMaxLengthForSingleLineDescription(int value)
protected String
singleLineFormat(Iterable<?> iterable, String start, String end)
protected String
singleLineFormat(Object[] iterable, Set<Object[]> alreadyFormatted)
protected String
smartFormat(Iterable<?> iterable)
Returns theString
representation of the givenIterable
, ornull
if the givenIterable
isnull
.protected String
smartFormat(Object[] iterable)
private static Map<?,?>
toSortedMapIfPossible(Map<?,?> map)
String
toString()
protected String
toStringOf(File file)
protected String
toStringOf(Character c)
protected String
toStringOf(Class<?> c)
protected String
toStringOf(Float f)
protected String
toStringOf(Long l)
protected String
toStringOf(Number number)
String
toStringOf(Object object)
Returns standard thetoString
representation of the given object.protected String
toStringOf(String s)
protected String
toStringOf(SimpleDateFormat dateFormat)
protected String
toStringOf(Calendar c)
protected String
toStringOf(Comparator<?> comparator)
protected String
toStringOf(AtomicBoolean atomicBoolean)
protected String
toStringOf(AtomicInteger atomicInteger)
protected String
toStringOf(AtomicLong atomicLong)
protected String
toStringOf(AtomicMarkableReference<?> atomicMarkableReference)
protected String
toStringOf(AtomicReference<?> atomicReference)
protected String
toStringOf(AtomicStampedReference<?> atomicStampedReference)
protected String
toStringOf(CompletableFuture<?> future)
protected String
toStringOf(Date d)
protected String
toStringOf(Map<?,?> map)
protected String
toStringOf(MapEntry<?,?> mapEntry)
protected String
toStringOf(Tuple tuple)
protected String
toStringOf(ComparatorBasedComparisonStrategy comparatorBasedComparisonStrategy)
protected String
toStringOf(PredicateDescription p)
private String
toStringOf(ChangeDelta<?> changeDelta)
private String
toStringOf(DeleteDelta<?> deleteDelta)
private String
toStringOf(InsertDelta<?> insertDelta)
String
unambiguousToStringOf(Object obj)
Returns theString
representation of the given object with its type and hexadecimal identity hash code so that it can be differentiated from other objects with the sameRepresentation.toStringOf(Object)
representation.
-
-
-
Field Detail
-
STANDARD_REPRESENTATION
public static final StandardRepresentation STANDARD_REPRESENTATION
-
NULL
private static final String NULL
- See Also:
- Constant Field Values
-
TUPLE_START
private static final String TUPLE_START
- See Also:
- Constant Field Values
-
TUPLE_END
private static final String TUPLE_END
- See Also:
- Constant Field Values
-
DEFAULT_START
private static final String DEFAULT_START
- See Also:
- Constant Field Values
-
DEFAULT_END
private static final String DEFAULT_END
- See Also:
- Constant Field Values
-
DEFAULT_MAX_ELEMENTS_EXCEEDED
private static final String DEFAULT_MAX_ELEMENTS_EXCEEDED
- See Also:
- Constant Field Values
-
INDENTATION_AFTER_NEWLINE
static final String INDENTATION_AFTER_NEWLINE
- See Also:
- Constant Field Values
-
INDENTATION_FOR_SINGLE_LINE
static final String INDENTATION_FOR_SINGLE_LINE
- See Also:
- Constant Field Values
-
ELEMENT_SEPARATOR
public static final String ELEMENT_SEPARATOR
- See Also:
- Constant Field Values
-
ELEMENT_SEPARATOR_WITH_NEWLINE
public static final String ELEMENT_SEPARATOR_WITH_NEWLINE
-
maxLengthForSingleLineDescription
private static int maxLengthForSingleLineDescription
-
maxElementsForPrinting
private static int maxElementsForPrinting
-
-
Method Detail
-
resetDefaults
public static void resetDefaults()
-
setMaxLengthForSingleLineDescription
public static void setMaxLengthForSingleLineDescription(int value)
-
getMaxLengthForSingleLineDescription
public static int getMaxLengthForSingleLineDescription()
-
setMaxElementsForPrinting
public static void setMaxElementsForPrinting(int value)
-
getMaxElementsForPrinting
public static int getMaxElementsForPrinting()
-
registerFormatterForType
public static <T> void registerFormatterForType(Class<T> type, Function<T,String> formatter)
Registers new formatter for the given type. All instances of the given type will be formatted with the provided formatter.- Type Parameters:
T
- the type to register a formatter for- Parameters:
type
- the class of the type to register a formatter forformatter
- the formatter
-
removeAllRegisteredFormatters
public static void removeAllRegisteredFormatters()
Clear all formatters registered per type withregisterFormatterForType(Class, Function)
.
-
toStringOf
public String toStringOf(Object object)
Returns standard thetoString
representation of the given object. It may or not the object's own implementation oftoString
.- Specified by:
toStringOf
in interfaceRepresentation
- Parameters:
object
- the given object.- Returns:
- the
toString
representation of the given object.
-
customFormat
protected <T> String customFormat(T object)
-
hasCustomFormatterFor
protected boolean hasCustomFormatterFor(Object object)
-
unambiguousToStringOf
public String unambiguousToStringOf(Object obj)
Description copied from interface:Representation
Returns theString
representation of the given object with its type and hexadecimal identity hash code so that it can be differentiated from other objects with the sameRepresentation.toStringOf(Object)
representation.- Specified by:
unambiguousToStringOf
in interfaceRepresentation
- Parameters:
obj
- the object to represent.- Returns:
- the unambiguous
toString
representation of the given object.
-
fallbackToStringOf
protected String fallbackToStringOf(Object object)
Returns theString
representation of the given object. This method is used as a last resort if none of theStandardRepresentation
predefined string representations were not called.- Parameters:
object
- the object to represent (nevernull
- Returns:
- to
toString
representation for the given object
-
toStringOf
protected String toStringOf(AtomicBoolean atomicBoolean)
-
toStringOf
protected String toStringOf(AtomicInteger atomicInteger)
-
toStringOf
protected String toStringOf(AtomicLong atomicLong)
-
toStringOf
protected String toStringOf(Comparator<?> comparator)
-
toStringOf
protected String toStringOf(ComparatorBasedComparisonStrategy comparatorBasedComparisonStrategy)
-
toStringOf
protected String toStringOf(PredicateDescription p)
-
toStringOf
protected String toStringOf(SimpleDateFormat dateFormat)
-
toStringOf
protected String toStringOf(CompletableFuture<?> future)
-
toStringOf
protected String toStringOf(AtomicReference<?> atomicReference)
-
toStringOf
protected String toStringOf(AtomicMarkableReference<?> atomicMarkableReference)
-
toStringOf
protected String toStringOf(AtomicStampedReference<?> atomicStampedReference)
-
toStringOf
private String toStringOf(ChangeDelta<?> changeDelta)
-
toStringOf
private String toStringOf(DeleteDelta<?> deleteDelta)
-
toStringOf
private String toStringOf(InsertDelta<?> insertDelta)
-
formatArray
protected String formatArray(Object o)
Returns theString
representation of the given array, ornull
if the given object is eithernull
or not an array. This method supports arrays having other arrays as elements.- Parameters:
o
- the object that is expected to be an array.- Returns:
- the
String
representation of the given array.
-
multiLineFormat
protected String multiLineFormat(Object[] iterable, Set<Object[]> alreadyFormatted)
-
singleLineFormat
protected String singleLineFormat(Object[] iterable, Set<Object[]> alreadyFormatted)
-
format
protected String format(Object[] array, String elementSeparator, String indentation, Set<Object[]> alreadyFormatted)
-
format
public String format(Iterable<?> iterable, String start, String end, String elementSeparator, String indentation)
-
smartFormat
protected String smartFormat(Iterable<?> iterable)
Returns theString
representation of the givenIterable
, ornull
if the givenIterable
isnull
.The
Iterable
will be formatted to a single line if it does not exceed 100 char, otherwise each elements will be formatted on a new line with 4 space indentation.- Parameters:
iterable
- theIterable
to format.- Returns:
- the
String
representation of the givenIterable
.
-
doesDescriptionFitOnSingleLine
private static boolean doesDescriptionFitOnSingleLine(String singleLineDescription)
-
-