private String asText(Object o) { if (o instanceof ComparatorBasedComparisonStrategy) { return " according to " + o + " comparator"; } if (o instanceof StandardComparisonStrategy) { return ""; } return toStringOf(o); } }
private boolean actualAndExpectedHaveSameStringRepresentation() { return areEqual(toStringOf(actual), toStringOf(expected)); }
private static String detailedToStringOf(Object obj) { return toStringOf(obj) + " (" + obj.getClass().getSimpleName() + "@" + toHexString(obj.hashCode()) + ")"; }
private Object[] msgArgs(String description) { return array(description, toStringOf(expected), toStringOf(actual)); }
if (type == null) { String format = "The given array of types:<%s> should not have null elements"; throw new NullPointerException(String.format(format, toStringOf(types)));
if (type == null) { String format = "The given array of types:<%s> should not have null elements"; throw new NullPointerException(String.format(format, toStringOf(types)));
private static Object format(Map<?, ?> map, Object o) { return o == map ? "(this Map)" : toStringOf(o); }
return toStringOf((Calendar) o); return toStringOf((Class<?>) o); return toStringOf((Collection<?>) o); return toStringOf((Date) o); return toStringOf((Float) o); return toStringOf((Long) o); return toStringOf((File) o); return toStringOf((Map<?, ?>) o); return toStringOf((Comparator<?>) o);
/** * Returns the {@code String} representation of the given {@code Collection}, or {@code null} if the given * {@code Collection} is {@code null}. * * @param c the {@code Collection} to format. * @return the {@code String} representation of the given {@code Collection}. */ public static String format(Collection<?> c) { if (c == null) { return null; } Iterator<?> i = c.iterator(); if (!i.hasNext()) { return "[]"; } StringBuilder b = new StringBuilder(); b.append('['); for (;;) { Object e = i.next(); b.append(e == c ? "(this Collection)" : toStringOf(e)); if (!i.hasNext()) { return b.append(']').toString(); } b.append(", "); } }
private void deepToString(Object[] array, StringBuilder buffer, Set<Object[]> alreadyFormatted) { if (array == null) { buffer.append(NULL); return; } alreadyFormatted.add(array); buffer.append('['); int size = array.length; for (int i = 0; i < size; i++) { if (i != 0) { buffer.append(", "); } Object element = array[i]; if (!isArray(element)) { buffer.append(element == null ? NULL : toStringOf(element)); continue; } if (!isObjectArray(element)) { buffer.append(formatPrimitiveArray(element)); continue; } if (alreadyFormatted.contains(element)) { buffer.append("[...]"); continue; } deepToString((Object[]) element, buffer, alreadyFormatted); } buffer.append(']'); alreadyFormatted.remove(array); }