From 3053eab9b038f889a4071e66616e3cce869fc5f6 Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Tue, 24 May 2016 13:50:38 +0100 Subject: [PATCH] NodeItem.drawTree(): fix typo --- src/main/java/net/kemitix/node/NodeItem.java | 5 +++-- .../java/net/kemitix/node/NodeItemTest.java | 22 +++++++++++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/src/main/java/net/kemitix/node/NodeItem.java b/src/main/java/net/kemitix/node/NodeItem.java index 8ef24a6..1ef3bf6 100644 --- a/src/main/java/net/kemitix/node/NodeItem.java +++ b/src/main/java/net/kemitix/node/NodeItem.java @@ -354,8 +354,9 @@ public class NodeItem implements Node { 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(); diff --git a/src/test/java/net/kemitix/node/NodeItemTest.java b/src/test/java/net/kemitix/node/NodeItemTest.java index ec9953f..200321f 100644 --- a/src/test/java/net/kemitix/node/NodeItemTest.java +++ b/src/test/java/net/kemitix/node/NodeItemTest.java @@ -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(null, "bob", node); + val alice = new NodeItem(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(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]"); + } }