HierarchyNode implements Serializable { @Override public String toString() { StringBuilder sb = new StringBuilder((dependencies.size() + 1) * 15); sb.append(file.getName()).append(" ["); for (File dep : dependencies) { sb.append(dep.getName()).append(","); } if (!dependencies.isEmpty()) { sb.deleteCharAt(sb.length() - 1); } sb.append("]"); return sb.toString(); } HierarchyNode(File file, HierarchyNode parent); void addDependency(HierarchyNode node); void addMissingDependency(String name); boolean hasDependencies(); File getFile(); Set<File> getDependencies(); Set<String> getMissingDependencies(); boolean containsDependency(File dependency); @Override int hashCode(); @Override boolean equals(Object obj); @Override String toString();  }
@Test public void testToString() { toStringPrint(root); assertEquals("file_name []", root.toString()); new HierarchyNode(new File("another_file", null, null), root); toStringPrint(root); assertEquals("file_name [another_file]", root.toString()); new HierarchyNode(new File("new_file", null, null), root); toStringPrint(root); assertEquals("file_name [another_file,new_file]", root.toString()); new HierarchyNode(new File(), root); toStringPrint(root); assertEquals("file_name [another_file,new_file,null]", root.toString()); }
@Test public void testToString2() { toStringPrint(root); new HierarchyNode(new File("left", null, null), root); toStringPrint(root); assertEquals("file_name [left]", root.toString()); new HierarchyNode(new File("right", null, null), root); toStringPrint(root); assertEquals("file_name [left,right]", root.toString()); }