From 0c13243ae695a37802fe3f68efe77dee9733f315 Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Sat, 18 Feb 2017 19:07:50 +0000 Subject: [PATCH] NodeItemTest: add more tests for update {get,find}{Data,Parent} methods --- .../java/net/kemitix/node/NodeItemTest.java | 75 ++++++++++++++++++- 1 file changed, 73 insertions(+), 2 deletions(-) diff --git a/src/test/java/net/kemitix/node/NodeItemTest.java b/src/test/java/net/kemitix/node/NodeItemTest.java index f91deef..73b7951 100644 --- a/src/test/java/net/kemitix/node/NodeItemTest.java +++ b/src/test/java/net/kemitix/node/NodeItemTest.java @@ -35,8 +35,79 @@ public class NodeItemTest { node = Nodes.unnamedRoot(data); //then assertThat(node.getData()).as("can get the data from a node") - . - contains(data); + .contains(data); + } + + @Test + public void getDataWhenEmptyThrowsException() throws Exception { + //given + node = Nodes.unnamedRoot(null); + assertThat(node.isEmpty()).isTrue(); + exception.expect(EmptyNodeException.class); + //when + node.getData(); + } + + @Test + public void findDataWhenFullReturnsData() { + //given + val data = "data"; + node = Nodes.unnamedRoot(data); + //when + val result = node.findData(); + //then + assertThat(result).contains(data); + } + + @Test + public void findDataWhenEmptyReturnsEmptyOptional() { + //given + node = Nodes.unnamedRoot(null); + //when + val result = node.findData(); + //then + assertThat(result).isEmpty(); + } + + @Test + public void getParentWhenRootThrowsException() { + //given + node = Nodes.unnamedRoot(null); + exception.expect(OrphanedNodeException.class); + //when + node.getParent(); + } + + @Test + public void getParentWhenChildReturnsRoot() { + //given + val root = Nodes.unnamedRoot("root"); + node = Nodes.unnamedChild("child", root); + //when + val result = node.getParent(); + //then + assertThat(result).isSameAs(root); + } + + @Test + public void findParentWhenRootReturnsEmptyOptional() { + //given + node = Nodes.unnamedRoot(null); + //when + val result = node.findParent(); + //then + assertThat(result).isEmpty(); + } + + @Test + public void findParentWhenChildReturnsRoot() { + //given + val root = Nodes.unnamedRoot("root"); + node = Nodes.unnamedChild("child", root); + //when + val result = node.findParent(); + //then + assertThat(result).contains(root); } @Test