From 5d0de83aef3ad665cdbddfd4784cc1ae0bafa482 Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Wed, 25 May 2016 13:47:41 +0100 Subject: [PATCH] NodeItem.insertInPath(): exception message includes name of conflicting node --- src/main/java/net/kemitix/node/NodeItem.java | 8 ++++---- src/test/java/net/kemitix/node/NodeItemTest.java | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/java/net/kemitix/node/NodeItem.java b/src/main/java/net/kemitix/node/NodeItem.java index b724048..4dacfd1 100644 --- a/src/main/java/net/kemitix/node/NodeItem.java +++ b/src/main/java/net/kemitix/node/NodeItem.java @@ -321,8 +321,8 @@ public class NodeItem implements Node { addChild(nodeItem); return; } - final Optional> childNamed = findChildByName( - nodeItem.getName()); + String name = nodeItem.getName(); + final Optional> childNamed = findChildByName(name); if (!childNamed.isPresent()) { // nothing with the same name exists addChild(nodeItem); return; @@ -330,8 +330,8 @@ public class NodeItem implements Node { // we have an existing node with the same name final Node 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()); } diff --git a/src/test/java/net/kemitix/node/NodeItemTest.java b/src/test/java/net/kemitix/node/NodeItemTest.java index b292c9d..bd3c4ce 100644 --- a/src/test/java/net/kemitix/node/NodeItemTest.java +++ b/src/test/java/net/kemitix/node/NodeItemTest.java @@ -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(null, "child", node); new NodeItem<>("data", "grandchild", child);