diff --git a/src/main/java/net/kemitix/node/Node.java b/src/main/java/net/kemitix/node/Node.java index cba5129..9d82efd 100644 --- a/src/main/java/net/kemitix/node/Node.java +++ b/src/main/java/net/kemitix/node/Node.java @@ -22,7 +22,8 @@ public interface Node { String getName(); /** - * Sets the explicit name for a node. + * Sets the explicit name for a node. Setting the name to null will clear + * the name and revert to the parent's name supplier. * * @param name the new name */ diff --git a/src/test/java/net/kemitix/node/NodeItemTest.java b/src/test/java/net/kemitix/node/NodeItemTest.java index 866ac24..dde300a 100644 --- a/src/test/java/net/kemitix/node/NodeItemTest.java +++ b/src/test/java/net/kemitix/node/NodeItemTest.java @@ -975,6 +975,18 @@ public class NodeItemTest { assertThat(child.getName()).isEqualTo("local supplier"); } + @Test + public void setNameToNullRevertsToParentNameSupplier() { + //given + node = new NodeItem<>(null, n -> "root supplier"); + val child = new NodeItem(null, "child name", node); + assertThat(child.getName()).isEqualTo("child name"); + //when + child.setName(null); + //then + assertThat(child.getName()).isEqualTo("root supplier"); + } + @Test public void getNameWithNameSupplierIsRecalculatedEachCall() { val counter = new AtomicInteger(0);