/** * Converts the entire tree into a string-based representation. * * @see #toString(TreeDef, Object, Function, String) */ public static <T> String toString(TreeDef<T> treeDef, T root, Function<? super T, String> toString) { return toString(treeDef, root, toString, " "); }
/** * Converts the entire tree into a string-based representation. * * @see #toString(TreeDef, Object, Function, String) */ public static <T> String toString(TreeDef<T> treeDef, T root) { return toString(treeDef, root, Object::toString); }
/** * Returns an {@link AssertionError} containing the contents of the * two trees. Attempts to throw a JUnit ComparisonFailure if JUnit * is on the class path, but it fails to a plain old {@code java.lang.AssertionError} * if the reflection calls fail. */ private AssertionError createAssertionError() { // convert both sides to strings String expected = TreeQuery.toString(expectedDef, expectedRoot, expectedToString); String actual = TreeQuery.toString(actualDef, actualRoot, actualToString); // try to create a junit ComparisonFailure for (String exceptionType : Arrays.asList( "org.junit.ComparisonFailure", "junit.framework.ComparisonFailure")) { try { return createComparisonFailure(exceptionType, expected, actual); } catch (Exception e) {} } // we'll have to settle for a plain-jane AssertionError return new AssertionError("Expected:\n" + expected + "\n\nActual:\n" + actual); }
/** * Returns a "deep" toString, including the entire tree below this level. * * @see TreeQuery#toString(TreeDef, Object, Function, String) */ public String toStringDeep() { return TreeQuery.toString(treeDef(), this, node -> node.getContent().toString()); }