From 080d995ba0995788b5560b4df234711e928df136 Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Tue, 24 May 2016 16:36:10 +0100 Subject: [PATCH] NodeItemTest: more tests --- .../java/net/kemitix/node/NodeItemTest.java | 55 ++++++++++++++++++- 1 file changed, 53 insertions(+), 2 deletions(-) diff --git a/src/test/java/net/kemitix/node/NodeItemTest.java b/src/test/java/net/kemitix/node/NodeItemTest.java index 251d690..da5df99 100644 --- a/src/test/java/net/kemitix/node/NodeItemTest.java +++ b/src/test/java/net/kemitix/node/NodeItemTest.java @@ -717,7 +717,8 @@ public class NodeItemTest { node.insertInPath(grandchild, "child"); // as root/child/grandchild //then assertThat(node.getChildByName("child")).as("child").isSameAs(child); - assertThat(node.getChildByName("child").getChildByName("grandchild")).as( + assertThat( + node.getChildByName("child").getChildByName("grandchild")).as( "grandchild").isSameAs(grandchild); } @@ -733,7 +734,8 @@ public class NodeItemTest { node.insertInPath(child); //then assertThat(node.getChildByName("child")).as("child").isSameAs(child); - assertThat(node.getChildByName("child").getChildByName("grandchild")).as( + assertThat( + node.getChildByName("child").getChildByName("grandchild")).as( "grandchild").isSameAs(grandchild); } @@ -745,6 +747,17 @@ public class NodeItemTest { node.removeParent(); } + @Test + public void removingParentFromNodeWithParentRemovesParent() { + //given + node = new NodeItem<>(null); + NodeItem child = new NodeItem<>(null, node); + //when + child.removeParent(); + //then + assertThat(child.getParent()).isNull(); + } + @Test public void placeNodeInTreeWhereNonEmptyNodeWithSameNameExists() { //given @@ -922,4 +935,42 @@ public class NodeItemTest { //when node.getChild("child data"); } + + @Test + @SuppressWarnings("unchecked") + public void constructorWithNameSupplierAndParentBeChildOfParent() { + //given + node = new NodeItem<>(null); + //when + NodeItem child = new NodeItem<>(null, Node::getData, node); + //then + assertThat(child.getParent()).isSameAs(node); + assertThat(node.getChildren()).containsExactly(child); + } + + @Test + @SuppressWarnings("unchecked") + public void removeParentCopiesRootNameSupplier() { + //given + node = new NodeItem<>("root data", n -> "root supplier"); + val child = new NodeItem<>("child data", node); + assertThat(child.getName()).isEqualTo("root supplier"); + //when + child.removeParent(); + //then + assertThat(child.getName()).isEqualTo("root supplier"); + } + + @Test + @SuppressWarnings("unchecked") + public void removeParentDoesNotReplaceLocalNameSupplier() { + //given + node = new NodeItem<>("root data", n -> "root supplier"); + val child = new NodeItem<>("child data", n -> "local supplier", node); + assertThat(child.getName()).isEqualTo("local supplier"); + //when + child.removeParent(); + //then + assertThat(child.getName()).isEqualTo("local supplier"); + } }