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

View file

@ -767,7 +767,7 @@ public class NodeItemTest {
//given
exception.expect(NodeException.class);
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);
val child = new NodeItem<String>(null, "child", node);
new NodeItem<>("data", "grandchild", child);