Author: oheger
Date: Tue Oct 27 20:13:08 2009
New Revision: 830325
URL: http://svn.apache.org/viewvc?rev=830325&view=rev
Log:
Switched some tests to JUnit 4 style.
Modified:
commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/base/TestFlatNodeHandler.java
commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/base/TestFlatNodeSourceAdapter.java
Modified: commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/base/TestFlatNodeHandler.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/base/TestFlatNodeHandler.java?rev=830325&r1=830324&r2=830325&view=diff
==============================================================================
--- commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/base/TestFlatNodeHandler.java
(original)
+++ commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/base/TestFlatNodeHandler.java
Tue Oct 27 20:13:08 2009
@@ -16,11 +16,17 @@
*/
package org.apache.commons.configuration2.base;
-import java.util.List;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
-import junit.framework.TestCase;
+import java.util.List;
import org.apache.commons.configuration2.ConfigurationRuntimeException;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
/**
* Test class for FlatNodeHandler.
@@ -30,7 +36,7 @@
* Configuration team</a>
* @version $Id$
*/
-public class TestFlatNodeHandler extends TestCase
+public class TestFlatNodeHandler
{
/** An array with the names of the test child nodes. */
private static final String[] CHILD_NAMES = {
@@ -49,10 +55,9 @@
/** Stores the internal update flag of the node handler. */
private Boolean internalUpdate;
- @Override
- protected void setUp() throws Exception
+ @Before
+ public void setUp() throws Exception
{
- super.setUp();
source = new ConfigurationSourceEventWrapper(
new MapConfigurationSource());
source.addConfigurationSourceListener(new ConfigurationSourceListener()
@@ -73,11 +78,10 @@
* Clears the test environment. This implementation also checks whether an
* unexpected change event was received.
*/
- @Override
- protected void tearDown() throws Exception
+ @After
+ public void tearDown() throws Exception
{
assertNull("Unexpected change event", internalUpdate);
- super.tearDown();
}
/**
@@ -110,6 +114,7 @@
/**
* Tests querying the child nodes of a node.
*/
+ @Test
public void testGetChildren()
{
List<FlatNode> children = handler.getChildren(setUpTestNode());
@@ -125,6 +130,7 @@
/**
* Tests querying children by name.
*/
+ @Test
public void testGetChildrenName()
{
List<FlatNode> children = handler.getChildren(setUpTestNode(),
@@ -139,6 +145,7 @@
/**
* Tests querying the number of children.
*/
+ @Test
public void testGetChildrenCount()
{
FlatNode root = setUpTestNode();
@@ -161,6 +168,7 @@
/**
* Tests querying the total number of children.
*/
+ @Test
public void testGetChildrenCountTotal()
{
assertEquals("Wrong total number of children", CHILD_NAMES.length,
@@ -170,6 +178,7 @@
/**
* Tests querying children by their index.
*/
+ @Test
public void testGetChild()
{
FlatNode node = setUpTestNode();
@@ -183,6 +192,7 @@
/**
* Tests adding a new child node.
*/
+ @Test
public void testAddChild()
{
FlatNode node = setUpTestNode();
@@ -198,6 +208,7 @@
/**
* Tests removing a child node.
*/
+ @Test
public void testRemoveChild()
{
FlatNode node = setUpTestNode();
@@ -214,6 +225,7 @@
/**
* Tests setting the value of a node.
*/
+ @Test
public void testSetValue()
{
FlatNode node = setUpTestNode();
@@ -227,6 +239,7 @@
/**
* Tests querying the value of a node.
*/
+ @Test
public void testGetValue()
{
FlatNode node = setUpTestNode();
@@ -240,6 +253,7 @@
/**
* Tests querying the name of nodes.
*/
+ @Test
public void testNodeName()
{
FlatNode node = setUpTestNode();
@@ -254,6 +268,7 @@
/**
* Tests querying the parent of a node.
*/
+ @Test
public void testGetParent()
{
FlatNode node = setUpTestNode();
@@ -265,23 +280,17 @@
* Tests adding a value to an attribute. Because attributes are not
* supported, this should cause an exception.
*/
+ @Test(expected = ConfigurationRuntimeException.class)
public void testAddAttributeValue()
{
- try
- {
- handler.addAttributeValue(setUpTestNode(), "attr", "test");
- fail("Could add an attribute!");
- }
- catch (ConfigurationRuntimeException crex)
- {
- // ok
- }
+ handler.addAttributeValue(setUpTestNode(), "attr", "test");
}
/**
* Tests querying the value of an attribute. Because flat nodes do not
* support attributes, result should always be null.
*/
+ @Test
public void testGetAttributeValue()
{
assertNull("Wrong attribute value", handler.getAttributeValue(
@@ -292,6 +301,7 @@
* Tests querying the existing attributes. Here always an empty list should
* be returned.
*/
+ @Test
public void testGetAttributes()
{
assertTrue("Found attributes", handler.getAttributes(setUpTestNode())
@@ -302,6 +312,7 @@
* Tests removing an attribute. This should be a no-op. We only test whether
* no exception is thrown.
*/
+ @Test
public void testRemoveAttribute()
{
handler.removeAttribute(setUpTestNode(), "test");
@@ -311,16 +322,9 @@
* Tests setting the value of an attribute. Because attributes are not
* supported, this should cause an exception.
*/
+ @Test(expected = ConfigurationRuntimeException.class)
public void testSetAttributeValue()
{
- try
- {
- handler.setAttributeValue(setUpTestNode(), "attr", "test");
- fail("Could add an attribute!");
- }
- catch (ConfigurationRuntimeException crex)
- {
- // ok
- }
+ handler.setAttributeValue(setUpTestNode(), "attr", "test");
}
}
Modified: commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/base/TestFlatNodeSourceAdapter.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/base/TestFlatNodeSourceAdapter.java?rev=830325&r1=830324&r2=830325&view=diff
==============================================================================
--- commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/base/TestFlatNodeSourceAdapter.java
(original)
+++ commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/base/TestFlatNodeSourceAdapter.java
Tue Oct 27 20:13:08 2009
@@ -16,15 +16,20 @@
*/
package org.apache.commons.configuration2.base;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotSame;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
-import junit.framework.TestCase;
-
import org.apache.commons.configuration2.expr.def.DefaultExpressionEngine;
import org.easymock.EasyMock;
+import org.junit.Test;
/**
* Test class for {@code FlatNodeSourceAdapter}.
@@ -32,7 +37,7 @@
* @author Commons Configuration team
* @version $Id$
*/
-public class TestFlatNodeSourceAdapter extends TestCase
+public class TestFlatNodeSourceAdapter
{
/** An array with the names of the test properties. */
private static final String[] KEYS = {
@@ -107,22 +112,16 @@
* Tries to create an adapter for a null source. This should cause an
* exception.
*/
+ @Test(expected = IllegalArgumentException.class)
public void testInitNull()
{
- try
- {
- new FlatNodeSourceAdapter(null);
- fail("Could create instance without source!");
- }
- catch (IllegalArgumentException iex)
- {
- // ok
- }
+ new FlatNodeSourceAdapter(null);
}
/**
* Tests whether the correct original source is returned.
*/
+ @Test
public void testGetOriginalSource()
{
FlatConfigurationSource src = createMockSource();
@@ -136,6 +135,7 @@
* Tests whether a listener can be added. It should be added at the wrapped
* source.
*/
+ @Test
public void testAddConfigurationSourceListener()
{
FlatConfigurationSource src = createMockSource();
@@ -152,6 +152,7 @@
* Tests whether event listeners can be removed. The calls should be
* delegated to the wrapped source.
*/
+ @Test
public void testRemoveConfigurationSourceListener()
{
FlatConfigurationSource src = createMockSource();
@@ -173,6 +174,7 @@
/**
* Tests the clear() implementation.
*/
+ @Test
public void testClear()
{
FlatConfigurationSource src = createMockSource();
@@ -187,6 +189,7 @@
* Tries to set a root node. This operation is not supported, so an
* exception should be thrown.
*/
+ @Test
public void testSetRootNode()
{
FlatConfigurationSource src = createMockSource();
@@ -209,6 +212,7 @@
* transformed into a hierarchical structure. We test whether it can be
* accessed from a configuration.
*/
+ @Test
public void testTransformation()
{
FlatNodeSourceAdapter adapter = createTestAdapter();
@@ -230,6 +234,7 @@
* Tests the transformation performed by the adapter if a property with
* multiple values is involved.
*/
+ @Test
public void testTransformationList()
{
FlatNodeSourceAdapter adapter = createTestAdapter();
@@ -251,6 +256,7 @@
/**
* Tests whether changes at the wrapped source are visible.
*/
+ @Test
public void testConfigurationSourceChanged()
{
FlatNodeSourceAdapter adapter = createTestAdapter();
@@ -267,6 +273,7 @@
* Tests whether updates of the configuration are visible in the wrapped
* source.
*/
+ @Test
public void testUpdateOriginalSource()
{
FlatNodeSourceAdapter adapter = createTestAdapter();
@@ -281,6 +288,7 @@
/**
* Tests whether capabilities can be requested.
*/
+ @Test
public void testGetCapability()
{
FlatConfigurationSource src = createMockSource();
|