You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by oh...@apache.org on 2014/04/13 17:57:58 UTC
svn commit: r1587010 -
/commons/proper/configuration/branches/immutableNodes/src/test/java/org/apache/commons/configuration/tree/TestNodeAddData.java
Author: oheger
Date: Sun Apr 13 15:57:58 2014
New Revision: 1587010
URL: http://svn.apache.org/r1587010
Log:
Fixed test for NodeAddData.
It was broken by the latest merge operation.
Modified:
commons/proper/configuration/branches/immutableNodes/src/test/java/org/apache/commons/configuration/tree/TestNodeAddData.java
Modified: commons/proper/configuration/branches/immutableNodes/src/test/java/org/apache/commons/configuration/tree/TestNodeAddData.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/branches/immutableNodes/src/test/java/org/apache/commons/configuration/tree/TestNodeAddData.java?rev=1587010&r1=1587009&r2=1587010&view=diff
==============================================================================
--- commons/proper/configuration/branches/immutableNodes/src/test/java/org/apache/commons/configuration/tree/TestNodeAddData.java (original)
+++ commons/proper/configuration/branches/immutableNodes/src/test/java/org/apache/commons/configuration/tree/TestNodeAddData.java Sun Apr 13 15:57:58 2014
@@ -17,91 +17,91 @@
package org.apache.commons.configuration.tree;
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
+import java.util.ArrayList;
+import java.util.Collections;
import java.util.List;
-import org.junit.Before;
+import org.junit.BeforeClass;
import org.junit.Test;
/**
* Test class for NodeAddData.
*
- * @author <a
- * href="http://commons.apache.org/configuration/team-list.html">Commons
- * Configuration team</a>
* @version $Id$
*/
public class TestNodeAddData
{
- /** Constant for the default parent node used for testing. */
- private static final ConfigurationNode TEST_PARENT = new DefaultConfigurationNode(
- "parent");
-
/** Constant for the name of the new node. */
private static final String TEST_NODENAME = "testNewNode";
/** Constant for the name of a path node. */
private static final String PATH_NODE_NAME = "PATHNODE";
- /** Constant for the number of path nodes to be added. */
- private static final int PATH_NODE_COUNT = 10;
-
- /** The object to be tested. */
- NodeAddData addData;
+ /** A default parent node. */
+ private static ImmutableNode parentNode;
- @Before
- public void setUp() throws Exception
+ @BeforeClass
+ public static void setUpBeforeClass() throws Exception
{
- addData = new NodeAddData(TEST_PARENT, TEST_NODENAME);
+ parentNode = new ImmutableNode.Builder().name("testParent").create();
}
/**
- * Tests the default values of an uninitialized instance.
+ * Tests whether the constructor can handle a null collection of path nodes.
*/
@Test
- public void testUninitialized()
+ public void testPathNodesNull()
{
- addData = new NodeAddData();
- assertNull("A parent is set", addData.getParent());
- assertNull("Node has a name", addData.getNewNodeName());
- assertFalse("Attribute flag is set", addData.isAttribute());
- assertTrue("Path nodes are not empty", addData.getPathNodes().isEmpty());
+ NodeAddData<ImmutableNode> data =
+ new NodeAddData<ImmutableNode>(parentNode, TEST_NODENAME,
+ false, null);
+ assertTrue("Got path nodes", data.getPathNodes().isEmpty());
}
/**
- * Tests the constructor that initializes the most important fields.
+ * Tests whether the collection with path nodes cannot be modified if no
+ * data is available.
*/
- @Test
- public void testInitialized()
+ @Test(expected = UnsupportedOperationException.class)
+ public void testPathNodesNullModify()
{
- assertSame("Wrong parent", TEST_PARENT, addData.getParent());
- assertEquals("Wrong node name", TEST_NODENAME, addData.getNewNodeName());
- assertFalse("Attribute flag is set", addData.isAttribute());
- assertTrue("Path nodes are not empty", addData.getPathNodes().isEmpty());
+ NodeAddData<ImmutableNode> data =
+ new NodeAddData<ImmutableNode>(parentNode, TEST_NODENAME,
+ false, null);
+ data.getPathNodes().add("test");
}
/**
- * Tests adding path nodes.
+ * Tests whether a defensive copy of the collection with path nodes is
+ * created.
*/
@Test
- public void testAddPathNode()
+ public void testInitPathNodesDefensiveCopy()
{
- for (int i = 0; i < PATH_NODE_COUNT; i++)
- {
- addData.addPathNode(PATH_NODE_NAME + i);
- }
-
- List<String> nodes = addData.getPathNodes();
- assertEquals("Incorrect number of path nodes", PATH_NODE_COUNT, nodes
+ List<String> pathNodes = new ArrayList<String>();
+ pathNodes.add(PATH_NODE_NAME);
+ NodeAddData<ImmutableNode> data =
+ new NodeAddData<ImmutableNode>(parentNode, TEST_NODENAME,
+ false, pathNodes);
+ pathNodes.add("anotherNode");
+ assertEquals("Wrong number of path nodes", 1, data.getPathNodes()
.size());
- for (int i = 0; i < PATH_NODE_COUNT; i++)
- {
- assertEquals("Wrong path node at position" + i, PATH_NODE_NAME + i,
- nodes.get(i));
- }
+ assertEquals("Wrong path node", PATH_NODE_NAME, data.getPathNodes()
+ .get(0));
+ }
+
+ /**
+ * Tests that the collection with path nodes cannot be modified if data is
+ * available.
+ */
+ @Test(expected = UnsupportedOperationException.class)
+ public void testPathNodesDefinedModify()
+ {
+ NodeAddData<ImmutableNode> data =
+ new NodeAddData<ImmutableNode>(parentNode, TEST_NODENAME,
+ false, Collections.singleton(PATH_NODE_NAME));
+ data.getPathNodes().add("anotherNode");
}
}