NodeItem.drawTree(): fix typo
This commit is contained in:
parent
6f81a62162
commit
3053eab9b0
2 changed files with 25 additions and 2 deletions
|
@ -354,8 +354,9 @@ public class NodeItem<T> implements Node<T> {
|
||||||
sb.append(String.format("[%1$" + (depth + name.length()) + "s]\n",
|
sb.append(String.format("[%1$" + (depth + name.length()) + "s]\n",
|
||||||
name));
|
name));
|
||||||
} else if (!children.isEmpty()) {
|
} else if (!children.isEmpty()) {
|
||||||
sb.append(String.format("[%1$" + (depth + unnamed) + "s]\n",
|
sb.append(
|
||||||
unnamed));
|
String.format("[%1$" + (depth + unnamed.length()) + "s]\n",
|
||||||
|
unnamed));
|
||||||
}
|
}
|
||||||
getChildren().stream().forEach(c -> sb.append(c.drawTree(depth + 1)));
|
getChildren().stream().forEach(c -> sb.append(c.drawTree(depth + 1)));
|
||||||
return sb.toString();
|
return sb.toString();
|
||||||
|
|
|
@ -856,4 +856,26 @@ public class NodeItemTest {
|
||||||
//then
|
//then
|
||||||
assertThat(node.getChildren()).isEmpty();
|
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]");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue