/** * Creates a string representation of an assertion and its recorded values. * * @param text the assertion's source text * @param recorder a recorder holding the values recorded during evaluation * of the assertion * @return a string representation of the assertion and its recorded values */ public static String render(String text, ValueRecorder recorder) { return new AssertionRenderer(text, recorder).render(); }
/** * Returns a string representation of the given value, or <tt>null</tt> if * the value should not be included (because it does not add any valuable * information). * * @param value a value * @return a string representation of the given value */ private static String valueToString(Object value) { String toString; try { toString = InvokerHelper.format(value, true, -1, false); } catch (Exception e) { return String.format("%s (toString() threw %s)", javaLangObjectToString(value), e.getClass().getName()); } if (toString == null) { return String.format("%s (toString() == null)", javaLangObjectToString(value)); } if (toString.equals("")) { if (hasStringLikeType(value)) return "\"\""; return String.format("%s (toString() == \"\")", javaLangObjectToString(value)); } return toString; }
private String render() { renderText(); sortValues(); renderValues(); return linesToString(); }
if (next != null && next.getColumn() == startColumn) continue; String str = valueToString(value.getValue()); if (str == null) continue; // null signals the value shouldn't be rendered placeString(lines.get(j), str, startColumn); startColumns.set(j, startColumn); continue nextValue; } else { placeString(lines.get(j), "|", startColumn); if (j > 1) // make sure that no values are ever placed on empty line startColumns.set(j, startColumn + 1); // + 1: no whitespace required between end of value and "|" StringBuilder newLine = new StringBuilder(); lines.add(newLine); placeString(newLine, s, startColumn); startColumns.add(startColumn);
if (next != null && next.getColumn() == value.getColumn()) continue; String str = valueToString(value.getValue()); if (str == null) continue; // null signals the value shouldn't be rendered placeString(lines.get(j), str, startColumn); startColumns.set(j, startColumn); continue nextValue; } else { placeString(lines.get(j), "|", startColumn); if (j > 1) // make sure that no values are ever placed on empty line startColumns.set(j, startColumn + 1); // + 1: no whitespace required between end of value and "|" StringBuilder newLine = new StringBuilder(); lines.add(newLine); placeString(newLine, s, startColumn); startColumns.add(startColumn);
/** * Creates a string representation of an assertion and its recorded values. * * @param text the assertion's source text * @param recorder a recorder holding the values recorded during evaluation * of the assertion * @return a string representation of the assertion and its recorded values */ public static String render(String text, ValueRecorder recorder) { return new AssertionRenderer(text, recorder).render(); }
private String render() { renderText(); sortValues(); renderValues(); return linesToString(); }
/** * Returns a string representation of the given value, or <tt>null</tt> if * the value should not be included (because it does not add any valuable * information). * * @param value a value * @return a string representation of the given value */ private static String valueToString(Object value) { String toString; try { toString = DefaultGroovyMethods.toString(value); } catch (Exception e) { return String.format("%s (toString() threw %s)", javaLangObjectToString(value), e.getClass().getName()); } if (toString == null) { return String.format("%s (toString() == null)", javaLangObjectToString(value)); } if (toString.equals("")) { if (hasStringLikeType(value)) return "\"\""; return String.format("%s (toString() == \"\")", javaLangObjectToString(value)); } return toString; }