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.
  • Field Details

    • NULL

      private static final String NULL
      See Also:
    • STANDARD_REPRESENTATION

      public static final StandardRepresentation STANDARD_REPRESENTATION
    • TUPLE_START

      private static final String TUPLE_START
      See Also:
    • TUPLE_END

      private static final String TUPLE_END
      See Also:
    • DEFAULT_START

      private static final String DEFAULT_START
      See Also:
    • DEFAULT_END

      private static final String DEFAULT_END
      See Also:
    • DEFAULT_MAX_ELEMENTS_EXCEEDED

      private static final String DEFAULT_MAX_ELEMENTS_EXCEEDED
      See Also:
    • INDENTATION_AFTER_NEWLINE

      static final String INDENTATION_AFTER_NEWLINE
      See Also:
    • INDENTATION_FOR_SINGLE_LINE

      static final String INDENTATION_FOR_SINGLE_LINE
      See Also:
    • ELEMENT_SEPARATOR

      public static final String ELEMENT_SEPARATOR
      See Also:
    • 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
    • customFormatterByType

      private static final Map<Class<?>,Function<?,? extends CharSequence>> customFormatterByType
    • TYPE_WITH_UNAMBIGUOUS_REPRESENTATION

      private static final Class<?>[] TYPE_WITH_UNAMBIGUOUS_REPRESENTATION
    • BLACKLISTED_ITERABLE_CLASSES

      private static final Class<?>[] BLACKLISTED_ITERABLE_CLASSES
  • Constructor Details

    • StandardRepresentation

      public StandardRepresentation()
  • Method Details

    • resetDefaults

      public static void resetDefaults()
      It resets the static defaults for the standard representation.

      The following defaults will be reapplied:

      • maxLengthForSingleLineDescription = 80
      • maxElementsForPrinting = 1000
    • 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 for
      formatter - the formatter
    • removeAllRegisteredFormatters

      public static void removeAllRegisteredFormatters()
      Clear all formatters registered per type with registerFormatterForType(Class, Function).
    • toStringOf

      public String toStringOf(Object object)
      Returns standard the toString representation of the given object. It may or not the object's own implementation of toString.
      Specified by:
      toStringOf in interface Representation
      Parameters:
      object - the given object.
      Returns:
      the toString representation 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 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.
      Specified by:
      unambiguousToStringOf in interface Representation
      Parameters:
      obj - the object to represent.
      Returns:
      the unambiguous toString representation of the given object.
    • toString

      public String toString()
      Overrides:
      toString in class 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 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 - the object to represent (never null
      Returns:
      to toString representation for the given object
    • toStringOf

      protected String toStringOf(Number number)
    • toStringOf

      protected String toStringOf(AtomicBoolean atomicBoolean)
    • toStringOf

      protected String toStringOf(AtomicInteger atomicInteger)
    • toStringOf

      protected String toStringOf(AtomicLong atomicLong)
    • toStringOf

      protected String toStringOf(LongAdder longAdder)
    • toStringOf

      protected String toStringOf(Comparator<?> comparator)
    • toStringOf

      protected String toStringOf(ComparatorBasedComparisonStrategy comparatorBasedComparisonStrategy)
    • toStringOf

      protected String toStringOf(Calendar calendar)
    • toStringOf

      protected String toStringOf(Class<?> c)
    • toStringOf

      protected String toStringOf(String s)
    • toStringOf

      protected String toStringOf(Character c)
    • toStringOf

      protected String toStringOf(PredicateDescription p)
    • toStringOf

      protected String toStringOf(Date date)
    • toStringOf

      protected String toStringOf(LocalDateTime localDateTime)
    • toStringOf

      protected String toStringOf(OffsetDateTime offsetDateTime)
    • toStringOf

      protected String toStringOf(ZonedDateTime zonedDateTime)
    • toStringOf

      protected String toStringOf(LocalDate localDate)
    • classNameDisambiguation

      protected String classNameDisambiguation(Object o)
    • toStringOf

      protected String toStringOf(Float f)
    • toStringOf

      protected String toStringOf(Long l)
    • toStringOf

      protected String toStringOf(File file)
    • toStringOf

      protected String toStringOf(SimpleDateFormat dateFormat)
    • toStringOf

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

      protected String toStringOf(Tuple tuple)
    • toStringOf

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

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

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

      protected String toStringOf(Throwable throwable)
    • toStringOf

      protected String toStringOf(AtomicReference<?> atomicReference)
    • toStringOf

      protected String toStringOf(AtomicMarkableReference<?> atomicMarkableReference)
    • toStringOf

      protected String toStringOf(AtomicStampedReference<?> atomicStampedReference)
    • multiLineFormat

      protected String multiLineFormat(Iterable<?> iterable)
    • singleLineFormat

      protected String singleLineFormat(Iterable<?> iterable, String start, String end)
    • smartFormat

      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 - the Iterable to format.
      Returns:
      the String representation of the given Iterable.
    • formatArray

      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 - the object that is expected to be an array.
      Returns:
      the String representation of the given array.
    • smartFormat

      protected String smartFormat(Object[] array)
    • formatPrimitiveArray

      protected String formatPrimitiveArray(Object o)
    • multiLineFormat

      protected String multiLineFormat(Object[] array, Object root)
    • singleLineFormat

      protected String singleLineFormat(Object[] array, Object root)
    • format

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

      protected String format(List<?> elements, 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(Iterable<?> 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)
    • toStringOf

      private String toStringOf(Duration duration)
    • formatLines

      private String formatLines(List<?> lines)
    • doesDescriptionFitOnSingleLine

      private static boolean doesDescriptionFitOnSingleLine(String singleLineDescription)
    • identityHexCodeOf

      private static String identityHexCodeOf(Object obj)
    • classNameOf

      private static Object classNameOf(Object obj)
    • defaultToStringWithClassNameDisambiguation

      private String defaultToStringWithClassNameDisambiguation(Object o)
    • toSortedMapIfPossible

      private static Map<?,?> toSortedMapIfPossible(Map<?,?> map)
    • format

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