Top Description Inners Fields Constructors Methods
org.assertj.core.presentation

public Class StandardRepresentation

extends Object
implements Representation
Class Inheritance
All Implemented Interfaces
org.assertj.core.presentation.Representation
Known Direct Subclasses
org.assertj.core.presentation.UnicodeRepresentation, org.assertj.core.presentation.BinaryRepresentation, org.assertj.core.presentation.HexadecimalRepresentation
Static Imports
java.lang.Integer.toHexString, java.util.stream.Collectors.toList, org.assertj.core.util.Arrays.isArray, .Arrays.isArrayTypePrimitive, .Arrays.isObjectArray, .Arrays.notAnArrayOfPrimitives, .DateUtil.formatAsDatetime, .DateUtil.formatAsDatetimeWithMs, .Preconditions.checkArgument, .Strings.concat, .Strings.quote, .Throwables.getStackTrace

Standard java object representation.
Authors
Mariusz Smykula, Jack Gough

Nested and Inner Type Summary

Modifier and TypeClass and Description
protected static enum

Field Summary

Modifier and TypeField and Description
private static final Class<?>[]
private static final Map<Class<?>, Function<?, ? extends CharSequence>>
private static final String
private static final String
private static final String
public static final String
public static final String
pack-priv static final String
pack-priv static final String
private static int
private static int
private static int
private static final String
public static final StandardRepresentation
private static final String
private static final String
private static final Class<?>[]

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
protected String
private static Object
protected <T> String
customFormat(T object)

private String
private static boolean
doesDescriptionFitOnSingleLine(String singleLineDescription)

protected String

Returns:

to toString representation for the given object
fallbackToStringOf
(Object
the object to represent (never null
object
)

Returns the String representation of the given object.

protected String
format(Object[] array, String start, String end, String elementSeparator, String indentation, Object root)

protected String
format(List<?> elements, String start, String end, String elementSeparator, String indentation, Object root)

protected String
format(Iterable<?> iterable, String start, String end, String elementSeparator, String indentation, Object root)

private String
format(Map<?, ?> map, Object o)

protected String

Returns:

the String representation of the given array.
formatArray
(Object
the object that is expected to be an array.
o
)

Returns the String representation of the given array, or null if the given object is either null or not an array.

private String
formatLines(List<?> lines)

protected String
public static int
public static int
public static int
protected boolean

Returns:

true if the given object's type has a representation that is not ambiguous, false otherwise.
hasAlreadyAnUnambiguousToStringOf
(Object
the object to check
obj
)

Determine whether the given object's type has a representation that is not ambiguous.

protected boolean
private static boolean
private static boolean
hasOverriddenToStringInSubclassOf(Class<?> objectClass, Class<?> clazz)

private static String
private static boolean
protected String
protected String
multiLineFormat(Object[] array, Object root)

public static <
the type to register a formatter for
T
>
void
registerFormatterForType(Class<T>
the class of the type to register a formatter for
type
,
Function<T, String>
the formatter
formatter
)

Registers new formatter for the given type.

public static void
removeAllRegisteredFormatters()

Clear all formatters registered per type with registerFormatterForType(Class, Function).

private List<String>
representElements(Iterable<?> elements, String start, String end, String elementSeparator, String indentation, Object root)

private static String
representGroup(List<String> representedElements, String start, String end, String elementSeparator, String indentation)

public static void
resetDefaults()

It resets the static defaults for the standard representation.

protected String
safeStringOf(Object element, String start, String end, String elementSeparator, String indentation, Object root)

public static void
public static void
public static void
protected String
singleLineFormat(Iterable<?> iterable, String start, String end)

protected String
protected String

Returns:

the String representation of the given Iterable.
smartFormat
(Iterable<?>
the Iterable to format.
iterable
)

Returns the String representation of the given Iterable, or null if the given Iterable is null.

protected String
private static Map<?, ?>
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
public String

Returns:

the toString representation of the given object.
toStringOf
(Object
the given object.
object
)

Implements org.assertj.core.presentation.Representation.toStringOf.

Returns standard the toString representation of the given object.
protected String
protected String
toStringOf(AtomicBoolean atomicBoolean)

protected String
toStringOf(AtomicInteger atomicInteger)

protected String
toStringOf(AtomicLong atomicLong)

protected String
toStringOf(LongAdder longAdder)

protected String
toStringOf(Comparator<?> comparator)

protected String
toStringOf(ComparatorBasedComparisonStrategy comparatorBasedComparisonStrategy)

protected String
toStringOf(Calendar calendar)

protected String
protected String
protected String
protected String
protected String
protected String
toStringOf(LocalDateTime localDateTime)

protected String
toStringOf(OffsetDateTime offsetDateTime)

protected String
toStringOf(ZonedDateTime zonedDateTime)

protected String
toStringOf(LocalDate localDate)

protected String
toStringOf(YearMonth yearMonth)

protected String
protected String
protected String
protected String
protected String
toStringOf(Future<?> future)

protected String
protected String
toStringOf(MapEntry<?, ?> mapEntry)

protected String
toStringOf(Map.Entry<?, ?> javaMapEntry)

protected String
toStringOf(Map<?, ?> map)

protected String
toStringOf(Throwable throwable)

protected String
toStringOf(AtomicReference<?> atomicReference)

protected String
toStringOf(AtomicMarkableReference<?> atomicMarkableReference)

protected String
toStringOf(AtomicStampedReference<?> atomicStampedReference)

private String
toStringOf(ChangeDelta<?> changeDelta)

private String
toStringOf(DeleteDelta<?> deleteDelta)

private String
toStringOf(InsertDelta<?> insertDelta)

private String
toStringOf(Duration duration)

public String

Returns:

the unambiguous toString representation of the given object.
unambiguousToStringOf
(Object
the object to represent.
obj
)

Overrides default org.assertj.core.presentation.Representation.unambiguousToStringOf.

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.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

BLACKLISTED_ITERABLE_CLASSESback to summary
private static final Class<?>[] BLACKLISTED_ITERABLE_CLASSES
customFormatterByTypeback to summary
private static final Map<Class<?>, Function<?, ? extends CharSequence>> customFormatterByType
DEFAULT_ENDback to summary
private static final String DEFAULT_END
DEFAULT_MAX_ELEMENTS_EXCEEDEDback to summary
private static final String DEFAULT_MAX_ELEMENTS_EXCEEDED
DEFAULT_STARTback to summary
private static final String DEFAULT_START
ELEMENT_SEPARATORback to summary
public static final String ELEMENT_SEPARATOR
ELEMENT_SEPARATOR_WITH_NEWLINEback to summary
public static final String ELEMENT_SEPARATOR_WITH_NEWLINE
INDENTATION_AFTER_NEWLINEback to summary
pack-priv static final String INDENTATION_AFTER_NEWLINE
INDENTATION_FOR_SINGLE_LINEback to summary
pack-priv static final String INDENTATION_FOR_SINGLE_LINE
maxElementsForPrintingback to summary
private static int maxElementsForPrinting
maxLengthForSingleLineDescriptionback to summary
private static int maxLengthForSingleLineDescription
maxStackTraceElementsDisplayedback to summary
private static int maxStackTraceElementsDisplayed
NULLback to summary
private static final String NULL
STANDARD_REPRESENTATIONback to summary
public static final StandardRepresentation STANDARD_REPRESENTATION
TUPLE_ENDback to summary
private static final String TUPLE_END
TUPLE_STARTback to summary
private static final String TUPLE_START
TYPE_WITH_UNAMBIGUOUS_REPRESENTATIONback to summary
private static final Class<?>[] TYPE_WITH_UNAMBIGUOUS_REPRESENTATION

Constructor Detail

StandardRepresentationback to summary
public StandardRepresentation()

Method Detail

classNameDisambiguationback to summary
protected String classNameDisambiguation(Object o)
classNameOfback to summary
private static Object classNameOf(Object obj)
customFormatback to summary
protected <T> String customFormat(T object)
Annotations
@SuppressWarnings:unchecked
defaultToStringWithClassNameDisambiguationback to summary
private String defaultToStringWithClassNameDisambiguation(Object o)
doesDescriptionFitOnSingleLineback to summary
private static boolean doesDescriptionFitOnSingleLine(String singleLineDescription)
fallbackToStringOfback to summary
protected String fallbackToStringOf(Object object)

Returns the String representation of the given object. This method is used as a last resort if none of the StandardRepresentation predefined string representations were not called.

Parameters
object:Object

the object to represent (never null

Returns:String

to toString representation for the given object

formatback to summary
protected String format(Object[] array, String start, String end, String elementSeparator, String indentation, Object root)
formatback to summary
protected String format(List<?> elements, String start, String end, String elementSeparator, String indentation, Object root)
formatback to summary
protected String format(Iterable<?> iterable, String start, String end, String elementSeparator, String indentation, Object root)
formatback to summary
private String format(Map<?, ?> map, Object o)
formatArrayback to summary
protected String formatArray(Object o)

Returns the String representation of the given array, or null if the given object is either null or not an array. This method supports arrays having other arrays as elements.

Parameters
o:Object

the object that is expected to be an array.

Returns:String

the String representation of the given array.

formatLinesback to summary
private String formatLines(List<?> lines)
formatPrimitiveArrayback to summary
protected String formatPrimitiveArray(Object o)
getMaxElementsForPrintingback to summary
public static int getMaxElementsForPrinting()
Annotations
@VisibleForTesting
getMaxLengthForSingleLineDescriptionback to summary
public static int getMaxLengthForSingleLineDescription()
Annotations
@VisibleForTesting
getMaxStackTraceElementsDisplayedback to summary
public static int getMaxStackTraceElementsDisplayed()
Annotations
@VisibleForTesting
hasAlreadyAnUnambiguousToStringOfback to summary
protected boolean hasAlreadyAnUnambiguousToStringOf(Object obj)

Determine whether the given object's type has a representation that is not ambiguous.

Parameters
obj:Object

the object to check

Returns:boolean

true if the given object's type has a representation that is not ambiguous, false otherwise.

hasCustomFormatterForback to summary
protected boolean hasCustomFormatterFor(Object object)
hasOverriddenToStringback to summary
private static boolean hasOverriddenToString(Class<?> clazz)
hasOverriddenToStringInSubclassOfback to summary
private static boolean hasOverriddenToStringInSubclassOf(Class<?> objectClass, Class<?> clazz)
identityHexCodeOfback to summary
private static String identityHexCodeOf(Object obj)
isInstanceOfNotOverridingToStringback to summary
private static boolean isInstanceOfNotOverridingToString(Object object, Class<?> type)
multiLineFormatback to summary
protected String multiLineFormat(Iterable<?> iterable)
multiLineFormatback to summary
protected String multiLineFormat(Object[] array, Object root)
registerFormatterForTypeback to summary
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.

Parameters
<T>
the type to register a formatter for
type:Class<T>

the class of the type to register a formatter for

formatter:Function<T, String>

the formatter

removeAllRegisteredFormattersback to summary
public static void removeAllRegisteredFormatters()

Clear all formatters registered per type with registerFormatterForType(Class, Function).

representElementsback to summary
private List<String> representElements(Iterable<?> elements, String start, String end, String elementSeparator, String indentation, Object root)
representGroupback to summary
private static String representGroup(List<String> representedElements, String start, String end, String elementSeparator, String indentation)
resetDefaultsback to summary
public static void resetDefaults()

It resets the static defaults for the standard representation.

The following defaults will be reapplied:

  • maxLengthForSingleLineDescription = 80
  • maxElementsForPrinting = 1000
safeStringOfback to summary
protected String safeStringOf(Object element, String start, String end, String elementSeparator, String indentation, Object root)
setMaxElementsForPrintingback to summary
public static void setMaxElementsForPrinting(int value)
setMaxLengthForSingleLineDescriptionback to summary
public static void setMaxLengthForSingleLineDescription(int value)
setMaxStackTraceElementsDisplayedback to summary
public static void setMaxStackTraceElementsDisplayed(int value)
singleLineFormatback to summary
protected String singleLineFormat(Iterable<?> iterable, String start, String end)
singleLineFormatback to summary
protected String singleLineFormat(Object[] array, Object root)
smartFormatback to summary
protected String smartFormat(Iterable<?> iterable)

Returns the String representation of the given Iterable, or null if the given Iterable is null.

The Iterable will be formatted to a single line if it does not exceed 100 char, otherwise each element will be formatted on a new line with 4 space indentation.

Parameters
iterable:Iterable<?>

the Iterable to format.

Returns:String

the String representation of the given Iterable.

smartFormatback to summary
protected String smartFormat(Object[] array)
toSortedMapIfPossibleback to summary
private static Map<?, ?> toSortedMapIfPossible(Map<?, ?> map)
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object

Annotations
@Override
toStringOfback to summary
public String toStringOf(Object object)

Implements org.assertj.core.presentation.Representation.toStringOf.

Returns standard the toString representation of the given object. It may or not the object's own implementation of toString.

Parameters
object:Object

the given object.

Returns:String

the toString representation of the given object.

Annotations
@Override
toStringOfback to summary
protected String toStringOf(Number number)
toStringOfback to summary
protected String toStringOf(AtomicBoolean atomicBoolean)
toStringOfback to summary
protected String toStringOf(AtomicInteger atomicInteger)
toStringOfback to summary
protected String toStringOf(AtomicLong atomicLong)
toStringOfback to summary
protected String toStringOf(LongAdder longAdder)
toStringOfback to summary
protected String toStringOf(Comparator<?> comparator)
toStringOfback to summary
protected String toStringOf(ComparatorBasedComparisonStrategy comparatorBasedComparisonStrategy)
toStringOfback to summary
protected String toStringOf(Calendar calendar)
toStringOfback to summary
protected String toStringOf(Class<?> c)
toStringOfback to summary
protected String toStringOf(String s)
toStringOfback to summary
protected String toStringOf(Character c)
toStringOfback to summary
protected String toStringOf(PredicateDescription p)
toStringOfback to summary
protected String toStringOf(Date date)
toStringOfback to summary
protected String toStringOf(LocalDateTime localDateTime)
toStringOfback to summary
protected String toStringOf(OffsetDateTime offsetDateTime)
toStringOfback to summary
protected String toStringOf(ZonedDateTime zonedDateTime)
toStringOfback to summary
protected String toStringOf(LocalDate localDate)
toStringOfback to summary
protected String toStringOf(YearMonth yearMonth)
toStringOfback to summary
protected String toStringOf(Float f)
toStringOfback to summary
protected String toStringOf(Long l)
toStringOfback to summary
protected String toStringOf(File file)
toStringOfback to summary
protected String toStringOf(SimpleDateFormat dateFormat)
toStringOfback to summary
protected String toStringOf(Future<?> future)
toStringOfback to summary
protected String toStringOf(Tuple tuple)
toStringOfback to summary
protected String toStringOf(MapEntry<?, ?> mapEntry)
toStringOfback to summary
protected String toStringOf(Map.Entry<?, ?> javaMapEntry)
toStringOfback to summary
protected String toStringOf(Map<?, ?> map)
toStringOfback to summary
protected String toStringOf(Throwable throwable)
toStringOfback to summary
protected String toStringOf(AtomicReference<?> atomicReference)
toStringOfback to summary
protected String toStringOf(AtomicMarkableReference<?> atomicMarkableReference)
toStringOfback to summary
protected String toStringOf(AtomicStampedReference<?> atomicStampedReference)
toStringOfback to summary
private String toStringOf(ChangeDelta<?> changeDelta)
toStringOfback to summary
private String toStringOf(DeleteDelta<?> deleteDelta)
toStringOfback to summary
private String toStringOf(InsertDelta<?> insertDelta)
toStringOfback to summary
private String toStringOf(Duration duration)
unambiguousToStringOfback to summary
public String unambiguousToStringOf(Object obj)

Overrides default org.assertj.core.presentation.Representation.unambiguousToStringOf.

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.

Parameters
obj:Object

the object to represent.

Returns:String

the unambiguous toString representation of the given object.

Annotations
@Override
org.assertj.core.presentation back to summary

protected final Enum StandardRepresentation.GroupType

extends Enum<StandardRepresentation.GroupType>
Class Inheritance

Field Summary

Modifier and TypeField and Description
public static final StandardRepresentation.GroupType
private String
public static final StandardRepresentation.GroupType

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public String
public static StandardRepresentation.GroupType
public static StandardRepresentation.GroupType[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

ARRAYback to summary
public static final StandardRepresentation.GroupType ARRAY
descriptionback to summary
private String description
ITERABLEback to summary
public static final StandardRepresentation.GroupType ITERABLE

Constructor Detail

GroupTypeback to summary
private GroupType(String value)

Method Detail

descriptionback to summary
public String description()
valueOfback to summary
public static StandardRepresentation.GroupType valueOf(String name)
valuesback to summary
public static StandardRepresentation.GroupType[] values()