NodeItem.drawTree(): fix typo

This commit is contained in:
Paul Campbell 2016-05-24 13:50:38 +01:00
parent 6f81a62162
commit 3053eab9b0
2 changed files with 25 additions and 2 deletions

View file

@ -354,8 +354,9 @@ public class NodeItem<T> implements Node<T> {
sb.append(String.format("[%1$" + (depth + name.length()) + "s]\n",
name));
} else if (!children.isEmpty()) {
sb.append(String.format("[%1$" + (depth + unnamed) + "s]\n",
unnamed));
sb.append(
String.format("[%1$" + (depth + unnamed.length()) + "s]\n",
unnamed));
}
getChildren().stream().forEach(c -> sb.append(c.drawTree(depth + 1)));
return sb.toString();

View file

@ -856,4 +856,26 @@ public class NodeItemTest {
//then
assertThat(node.getChildren()).isEmpty();
}
@Test
public void drawTreeIsCorrect() {
//given
node = new NodeItem<>(null, "root");
val bob = new NodeItem<String>(null, "bob", node);
val alice = new NodeItem<String>(null, "alice", node);
new NodeItem<>(null, "dave", alice);
new NodeItem<>(null, bob); // has no name and no children so no included
val kim = new NodeItem<String>(null, node); // nameless mother
new NodeItem<>(null, "lucy", kim);
//when
val tree = node.drawTree(0);
//then
String[] lines = tree.split("\n");
assertThat(lines).contains("[root]", "[ alice]", "[ dave]",
"[ (unnamed)]", "[ lucy]", "[ bob]");
assertThat(lines).containsSubsequence("[root]", "[ alice]", "[ dave]");
assertThat(lines).containsSubsequence("[root]", "[ (unnamed)]",
"[ lucy]");
assertThat(lines).containsSubsequence("[root]", "[ bob]");
}
}