From d82b0290a1e91e5735e4af3c585e6cb7e392eabb Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Tue, 24 May 2016 22:35:24 +0100 Subject: [PATCH] NodeItemTest: demonstrate using dynamic name supplier to generate node paths --- .../java/net/kemitix/node/NodeItemTest.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/test/java/net/kemitix/node/NodeItemTest.java b/src/test/java/net/kemitix/node/NodeItemTest.java index dde300a..a8c95af 100644 --- a/src/test/java/net/kemitix/node/NodeItemTest.java +++ b/src/test/java/net/kemitix/node/NodeItemTest.java @@ -14,6 +14,7 @@ import java.util.Arrays; import java.util.Collections; import java.util.Optional; import java.util.concurrent.atomic.AtomicInteger; +import java.util.function.Function; /** * Test for {@link NodeItem}. @@ -1011,4 +1012,21 @@ public class NodeItemTest { assertThat(node.isNamed()).isFalse(); assertThat(node.isNamed()).isTrue(); } + + @Test + public void canUseNameSupplierToBuildFullPath() { + //given + final Function, String> pathNameSupplier = node -> { + Node parent = node.getParent(); + if (parent == null) { + return ""; + } + return parent.getName() + "/" + node.getData(); + }; + node = new NodeItem<>(null, pathNameSupplier); + val child = new NodeItem("child", node); + val grandchild = new NodeItem("grandchild", child); + //then + assertThat(grandchild.getName()).isEqualTo("/child/grandchild"); + } }