Node.setName(): ensure that setting name to null enables the name supplier
This commit is contained in:
parent
7de6c5ad49
commit
96ac0f720f
2 changed files with 14 additions and 1 deletions
|
@ -22,7 +22,8 @@ public interface Node<T> {
|
||||||
String getName();
|
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
|
* @param name the new name
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -975,6 +975,18 @@ public class NodeItemTest {
|
||||||
assertThat(child.getName()).isEqualTo("local supplier");
|
assertThat(child.getName()).isEqualTo("local supplier");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void setNameToNullRevertsToParentNameSupplier() {
|
||||||
|
//given
|
||||||
|
node = new NodeItem<>(null, n -> "root supplier");
|
||||||
|
val child = new NodeItem<String>(null, "child name", node);
|
||||||
|
assertThat(child.getName()).isEqualTo("child name");
|
||||||
|
//when
|
||||||
|
child.setName(null);
|
||||||
|
//then
|
||||||
|
assertThat(child.getName()).isEqualTo("root supplier");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getNameWithNameSupplierIsRecalculatedEachCall() {
|
public void getNameWithNameSupplierIsRecalculatedEachCall() {
|
||||||
val counter = new AtomicInteger(0);
|
val counter = new AtomicInteger(0);
|
||||||
|
|
Loading…
Reference in a new issue