NodeItem.insertInPath(): exception message includes name of conflicting node

This commit is contained in:
Paul Campbell 2016-05-25 13:47:41 +01:00
parent 3e687b9766
commit 5d0de83aef
2 changed files with 5 additions and 5 deletions

View file

@ -321,8 +321,8 @@ public class NodeItem<T> implements Node<T> {
addChild(nodeItem); addChild(nodeItem);
return; return;
} }
final Optional<Node<T>> childNamed = findChildByName( String name = nodeItem.getName();
nodeItem.getName()); final Optional<Node<T>> childNamed = findChildByName(name);
if (!childNamed.isPresent()) { // nothing with the same name exists if (!childNamed.isPresent()) { // nothing with the same name exists
addChild(nodeItem); addChild(nodeItem);
return; return;
@ -330,8 +330,8 @@ public class NodeItem<T> implements Node<T> {
// we have an existing node with the same name // we have an existing node with the same name
final Node<T> existing = childNamed.get(); final Node<T> existing = childNamed.get();
if (!existing.isEmpty()) { if (!existing.isEmpty()) {
throw new NodeException( throw new NodeException("A non-empty node named '" + name
"A non-empty node with that name already exists here"); + "' already exists here");
} else { } else {
existing.setData(nodeItem.getData()); existing.setData(nodeItem.getData());
} }

View file

@ -767,7 +767,7 @@ public class NodeItemTest {
//given //given
exception.expect(NodeException.class); exception.expect(NodeException.class);
exception.expectMessage( exception.expectMessage(
"A non-empty node with that name already exists here"); "A non-empty node named 'grandchild' already exists here");
node = new NodeItem<>(null); node = new NodeItem<>(null);
val child = new NodeItem<String>(null, "child", node); val child = new NodeItem<String>(null, "child", node);
new NodeItem<>("data", "grandchild", child); new NodeItem<>("data", "grandchild", child);