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, Jack Gough
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static classStandardRepresentation.GroupType
-
Field Summary
Fields Modifier and Type Field Description private static Map<Class<?>,Function<?,String>>customFormatterByTypeprivate static StringDEFAULT_ENDprivate static StringDEFAULT_MAX_ELEMENTS_EXCEEDEDprivate static StringDEFAULT_STARTstatic StringELEMENT_SEPARATORstatic StringELEMENT_SEPARATOR_WITH_NEWLINE(package private) static StringINDENTATION_AFTER_NEWLINE(package private) static StringINDENTATION_FOR_SINGLE_LINEprivate static intmaxElementsForPrintingprivate static intmaxLengthForSingleLineDescriptionprivate static intmaxStackTraceElementsDisplayedprivate static StringNULLstatic StandardRepresentationSTANDARD_REPRESENTATIONprivate static StringTUPLE_ENDprivate static StringTUPLE_STARTprivate static Class<?>[]TYPE_WITH_UNAMBIGUOUS_REPRESENTATION-
Fields inherited from interface org.assertj.core.presentation.Representation
DEFAULT_PRIORITY
-
-
Constructor Summary
Constructors Constructor Description StandardRepresentation()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected StringclassNameDisambiguation(Object o)private static ObjectclassNameOf(Object obj)protected <T> StringcustomFormat(T object)private StringdefaultToStringWithClassNameDisambiguation(Object o)private static booleandoesDescriptionFitOnSingleLine(String singleLineDescription)protected StringfallbackToStringOf(Object object)Returns theStringrepresentation of the given object.protected Stringformat(Iterable<?> iterable, String start, String end, String elementSeparator, String indentation, Object root)protected Stringformat(Object[] array, String start, String end, String elementSeparator, String indentation, Object root)private Stringformat(Map<?,?> map, Object o)protected StringformatArray(Object o)Returns theStringrepresentation of the given array, ornullif the given object is eithernullor not an array.private StringformatLines(List<?> lines)protected StringformatPrimitiveArray(Object o)static intgetMaxElementsForPrinting()static intgetMaxLengthForSingleLineDescription()static intgetMaxStackTraceElementsDisplayed()protected booleanhasAlreadyAnUnambiguousToStringOf(Object obj)Determine whether the given object's type has a representation that is not ambiguous.protected booleanhasCustomFormatterFor(Object object)private static booleanhasOverriddenToString(Class<?> clazz)private static booleanhasOverriddenToStringInSubclassOf(Class<?> objectClass, Class<?> clazz)private static StringidentityHexCodeOf(Object obj)private static booleanisInstanceOfNotOverridingToString(Object object, Class<?> type)protected StringmultiLineFormat(Iterable<?> iterable)protected StringmultiLineFormat(Object[] array, Object root)static <T> voidregisterFormatterForType(Class<T> type, Function<T,String> formatter)Registers new formatter for the given type.static voidremoveAllRegisteredFormatters()Clear all formatters registered per type withregisterFormatterForType(Class, Function).private List<String>representElements(Stream<?> elements, String start, String end, String elementSeparator, String indentation, Object root)private static StringrepresentGroup(List<String> representedElements, String start, String end, String elementSeparator, String indentation)static voidresetDefaults()It resets the static defaults for the standard representation.protected StringsafeStringOf(Object element, String start, String end, String elementSeparator, String indentation, Object root)static voidsetMaxElementsForPrinting(int value)static voidsetMaxLengthForSingleLineDescription(int value)static voidsetMaxStackTraceElementsDisplayed(int value)protected StringsingleLineFormat(Iterable<?> iterable, String start, String end)protected StringsingleLineFormat(Object[] array, Object root)protected StringsmartFormat(Iterable<?> iterable)Returns theStringrepresentation of the givenIterable, ornullif the givenIterableisnull.protected StringsmartFormat(Object[] array)private static Object[]toObjectArray(Object o)private static Map<?,?>toSortedMapIfPossible(Map<?,?> map)StringtoString()protected StringtoStringOf(File file)protected StringtoStringOf(Character c)protected StringtoStringOf(Class<?> c)protected StringtoStringOf(Float f)protected StringtoStringOf(Long l)protected StringtoStringOf(Number number)StringtoStringOf(Object object)Returns standard thetoStringrepresentation of the given object.protected StringtoStringOf(String s)protected StringtoStringOf(Throwable throwable)protected StringtoStringOf(SimpleDateFormat dateFormat)private StringtoStringOf(Duration duration)protected StringtoStringOf(LocalDate localDate)protected StringtoStringOf(LocalDateTime localDateTime)protected StringtoStringOf(OffsetDateTime offsetDateTime)protected StringtoStringOf(ZonedDateTime zonedDateTime)protected StringtoStringOf(Calendar calendar)protected StringtoStringOf(Comparator<?> comparator)protected StringtoStringOf(AtomicBoolean atomicBoolean)protected StringtoStringOf(AtomicInteger atomicInteger)protected StringtoStringOf(AtomicLong atomicLong)protected StringtoStringOf(AtomicMarkableReference<?> atomicMarkableReference)protected StringtoStringOf(AtomicReference<?> atomicReference)protected StringtoStringOf(AtomicStampedReference<?> atomicStampedReference)protected StringtoStringOf(LongAdder longAdder)protected StringtoStringOf(Future<?> future)protected StringtoStringOf(Date date)protected StringtoStringOf(Map.Entry<?,?> javaMapEntry)protected StringtoStringOf(Map<?,?> map)protected StringtoStringOf(MapEntry<?,?> mapEntry)protected StringtoStringOf(Tuple tuple)protected StringtoStringOf(org.assertj.core.internal.ComparatorBasedComparisonStrategy comparatorBasedComparisonStrategy)protected StringtoStringOf(PredicateDescription p)private StringtoStringOf(ChangeDelta<?> changeDelta)private StringtoStringOf(DeleteDelta<?> deleteDelta)private StringtoStringOf(InsertDelta<?> insertDelta)StringunambiguousToStringOf(Object obj)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.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.assertj.core.presentation.Representation
getPriority
-
-
-
-
Field Detail
-
NULL
private static final String NULL
- See Also:
- Constant Field Values
-
STANDARD_REPRESENTATION
public static final StandardRepresentation STANDARD_REPRESENTATION
-
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
-
maxStackTraceElementsDisplayed
private static int maxStackTraceElementsDisplayed
-
TYPE_WITH_UNAMBIGUOUS_REPRESENTATION
private static final Class<?>[] TYPE_WITH_UNAMBIGUOUS_REPRESENTATION
-
-
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)
-
getMaxStackTraceElementsDisplayed
public static int getMaxStackTraceElementsDisplayed()
-
setMaxStackTraceElementsDisplayed
public static void setMaxStackTraceElementsDisplayed(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 thetoStringrepresentation of the given object. It may or not the object's own implementation oftoString.- Specified by:
toStringOfin interfaceRepresentation- Parameters:
object- the given object.- Returns:
- the
toStringrepresentation of the given object.
-
isInstanceOfNotOverridingToString
private static boolean isInstanceOfNotOverridingToString(Object object, Class<?> type)
-
hasOverriddenToString
private static boolean hasOverriddenToString(Class<?> clazz)
-
hasOverriddenToStringInSubclassOf
private static boolean hasOverriddenToStringInSubclassOf(Class<?> objectClass, Class<?> clazz)
-
unambiguousToStringOf
public String unambiguousToStringOf(Object obj)
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.- Specified by:
unambiguousToStringOfin interfaceRepresentation- Parameters:
obj- the object to represent.- Returns:
- the unambiguous
toStringrepresentation of the given object.
-
customFormat
protected <T> String customFormat(T object)
-
hasCustomFormatterFor
protected boolean hasCustomFormatterFor(Object object)
-
hasAlreadyAnUnambiguousToStringOf
protected boolean hasAlreadyAnUnambiguousToStringOf(Object obj)
Determine whether the given object's type has a representation that is not ambiguous.- Parameters:
obj- the object to check- Returns:
- true if the given object's type has a representation that is not ambiguous, false otherwise.
-
fallbackToStringOf
protected String fallbackToStringOf(Object object)
Returns theStringrepresentation of the given object. This method is used as a last resort if none of theStandardRepresentationpredefined string representations were not called.- Parameters:
object- the object to represent (nevernull- Returns:
- to
toStringrepresentation 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(org.assertj.core.internal.ComparatorBasedComparisonStrategy comparatorBasedComparisonStrategy)
-
toStringOf
protected String toStringOf(PredicateDescription p)
-
toStringOf
protected String toStringOf(LocalDateTime localDateTime)
-
toStringOf
protected String toStringOf(OffsetDateTime offsetDateTime)
-
toStringOf
protected String toStringOf(ZonedDateTime zonedDateTime)
-
toStringOf
protected String toStringOf(SimpleDateFormat dateFormat)
-
toStringOf
protected String toStringOf(AtomicReference<?> atomicReference)
-
toStringOf
protected String toStringOf(AtomicMarkableReference<?> atomicMarkableReference)
-
toStringOf
protected String toStringOf(AtomicStampedReference<?> atomicStampedReference)
-
smartFormat
protected String smartFormat(Iterable<?> iterable)
Returns theStringrepresentation of the givenIterable, ornullif the givenIterableisnull.The
Iterablewill 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- theIterableto format.- Returns:
- the
Stringrepresentation of the givenIterable.
-
formatArray
protected String formatArray(Object o)
Returns theStringrepresentation of the given array, ornullif the given object is eithernullor 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
Stringrepresentation of the given array.
-
format
protected String format(Object[] array, String start, String end, String elementSeparator, String indentation, Object root)
-
format
protected String format(Iterable<?> iterable, String start, String end, String elementSeparator, String indentation, Object root)
-
safeStringOf
protected String safeStringOf(Object element, String start, String end, String elementSeparator, String indentation, Object root)
-
representElements
private List<String> representElements(Stream<?> elements, String start, String end, String elementSeparator, String indentation, Object root)
-
representGroup
private static String representGroup(List<String> representedElements, String start, String end, String elementSeparator, String indentation)
-
toStringOf
private String toStringOf(ChangeDelta<?> changeDelta)
-
toStringOf
private String toStringOf(DeleteDelta<?> deleteDelta)
-
toStringOf
private String toStringOf(InsertDelta<?> insertDelta)
-
doesDescriptionFitOnSingleLine
private static boolean doesDescriptionFitOnSingleLine(String singleLineDescription)
-
defaultToStringWithClassNameDisambiguation
private String defaultToStringWithClassNameDisambiguation(Object o)
-
-