groovy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sh...@apache.org
Subject groovy git commit: GROOVY-7044: Fixed deep cloning of nodes generated by NodeBuilder
Date Sat, 02 Jul 2016 17:45:26 GMT
Repository: groovy
Updated Branches:
  refs/heads/GROOVY_2_4_X fda7a056e -> f6deab440


GROOVY-7044: Fixed deep cloning of nodes generated by NodeBuilder

Use default behavior when creating Nodes without value.
(closes #270)


Project: http://git-wip-us.apache.org/repos/asf/groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/f6deab44
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/f6deab44
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/f6deab44

Branch: refs/heads/GROOVY_2_4_X
Commit: f6deab44097f87ef99547b2ad08595ac8c2e22a8
Parents: fda7a05
Author: Daniel Spilker <daniel.spilker@coremedia.com>
Authored: Mon Mar 7 11:04:56 2016 +0100
Committer: Shil Sinha <shils@apache.org>
Committed: Sat Jul 2 13:37:09 2016 -0400

----------------------------------------------------------------------
 src/main/groovy/util/NodeBuilder.java        |  5 ++---
 src/spec/test/builder/NodeBuilderTest.groovy | 24 +++++++++++++++++++++++
 2 files changed, 26 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/f6deab44/src/main/groovy/util/NodeBuilder.java
----------------------------------------------------------------------
diff --git a/src/main/groovy/util/NodeBuilder.java b/src/main/groovy/util/NodeBuilder.java
index 4b46429..babe5c3 100644
--- a/src/main/groovy/util/NodeBuilder.java
+++ b/src/main/groovy/util/NodeBuilder.java
@@ -18,7 +18,6 @@
  */
 package groovy.util;
 
-import java.util.ArrayList;
 import java.util.Map;
 
 /**
@@ -37,7 +36,7 @@ public class NodeBuilder extends BuilderSupport {
     }
 
     protected Object createNode(Object name) {
-        return new Node(getCurrentNode(), name, new ArrayList());
+        return new Node(getCurrentNode(), name);
     }
 
     protected Object createNode(Object name, Object value) {
@@ -45,7 +44,7 @@ public class NodeBuilder extends BuilderSupport {
     }
 
     protected Object createNode(Object name, Map attributes) {
-        return new Node(getCurrentNode(), name, attributes, new ArrayList());
+        return new Node(getCurrentNode(), name, attributes);
     }
 
     protected Object createNode(Object name, Map attributes, Object value) {

http://git-wip-us.apache.org/repos/asf/groovy/blob/f6deab44/src/spec/test/builder/NodeBuilderTest.groovy
----------------------------------------------------------------------
diff --git a/src/spec/test/builder/NodeBuilderTest.groovy b/src/spec/test/builder/NodeBuilderTest.groovy
index c59830f..be2d385 100644
--- a/src/spec/test/builder/NodeBuilderTest.groovy
+++ b/src/spec/test/builder/NodeBuilderTest.groovy
@@ -37,4 +37,28 @@ class NodeBuilderTest extends GroovyTestCase {
         assert userlist.user.find { it.@lastname == 'Smith' }.address.size() == 2
         // end::node_builder_gpath_assert[]
     }
+
+    // GROOVY-7044
+    void testNodeCloning() {
+        def node = new NodeBuilder().a {
+            b()
+        }
+        def clonedNode = node.clone()
+        node.appendNode('c')
+
+        // clonedNode should not contain node c
+        assert !clonedNode.children().any { it.name() == 'c' }
+    }
+
+    // GROOVY-7044
+    void testNodeCloningWithAttributes() {
+        def node = new NodeBuilder().a(foo: 'bar') {
+            b()
+        }
+        def clonedNode = node.clone()
+        node.appendNode('c')
+
+        // clonedNode should not contain node c
+        assert !clonedNode.children().any { it.name() == 'c' }
+    }
 }


Mime
View raw message