Author: simonetripodi
Date: Wed Sep 14 21:23:34 2011
New Revision: 1170851
URL: http://svn.apache.org/viewvc?rev=1170851&view=rev
Log:
simplified parametrized tests executions via JUnit's Parameterized feature
Modified:
commons/proper/chain/trunk/src/test/java/org/apache/commons/chain/web/ChainResourcesTestCase.java
Modified:
commons/proper/chain/trunk/src/test/java/org/apache/commons/chain/web/ChainResourcesTestCase.java
URL:
http://svn.apache.org/viewvc/commons/proper/chain/trunk/src/test/java/org/apache/commons/chain/web/ChainResourcesTestCase.java?rev=1170851&r1=1170850&r2=1170851&view=diff
==============================================================================
---
commons/proper/chain/trunk/src/test/java/org/apache/commons/chain/web/ChainResourcesTestCase.java
(original)
+++
commons/proper/chain/trunk/src/test/java/org/apache/commons/chain/web/ChainResourcesTestCase.java
Wed Sep 14 21:23:34 2011
@@ -16,70 +16,62 @@
*/
package org.apache.commons.chain.web;
-import static junit.framework.Assert.assertEquals;
-import static junit.framework.Assert.assertNotNull;
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertNotNull;
+
+import java.util.Arrays;
+import java.util.Collection;
import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameters;
// Test case for org.apache.commons.chain.web.ChainResources
+@RunWith(Parameterized.class)
public class ChainResourcesTestCase {
- // ----------------------------------------------------- Instance Variables
+ // ----------------------------------------------------- Test data source
+ @Parameters
+ public static Collection<Object[]> data() {
+ return Arrays.asList(new Object[][] {
+ { "a,b,c", new String[] {"a", "b", "c"} },
+ { "a , b , c ", new String[] {"a", "b", "c"} },
+ { "a,\tb,\tc ", new String[] {"a", "b", "c"} },
+ { "\na,\nb,\nc\n", new String[] {"a", "b", "c"} },
+ { "a,,b,c ", new String[] {"a", "b", "c"} },
+ { ",a,b,,c,,", new String[] {"a", "b", "c"} },
+ { null, new String[] {} },
+ { "", new String[] {} },
+ { ",", new String[] {} },
+ { ",,", new String[] {} }
+ });
+ }
- protected TestData[] data = new TestData[]
- {
- new TestData("a,b,c", new String[] {"a", "b", "c"}),
- new TestData("a , b , c ", new String[] {"a", "b", "c"}),
- new TestData("a,\tb,\tc ", new String[] {"a", "b", "c"}),
- new TestData("\na,\nb,\nc\n", new String[] {"a", "b", "c"}),
- new TestData("a,,b,c ", new String[] {"a", "b", "c"}),
- new TestData(",a,b,,c,,", new String[] {"a", "b", "c"}),
- new TestData(null, new String[] {}),
- new TestData("", new String[] {}),
- new TestData(",", new String[] {}),
- new TestData(",,", new String[] {})
- };
+ // ----------------------------------------------------- Public constructor
+ private final String input;
- // ------------------------------------------------ Individual Test Methods
+ private final String[] expected;
-
- @Test
- public void testGetPaths() throws Exception {
- for (int i = 0; i < data.length; i++) {
- TestData datum = data[i];
- String[] expected = datum.getExpected();
- String[] actual =
ChainResources.getResourcePaths(datum.getInput());
-
- assertNotNull(actual);
- assertEquals(expected.length, actual.length);
- for (int j = 0; j < actual.length; j++) {
- assertEquals(expected[j], actual[j]);
- }
- }
+ public ChainResourcesTestCase(String input, String[] expected)
+ {
+ this.input = input;
+ this.expected = expected;
}
+ // ------------------------------------------------ Individual Test Methods
- // ---------------------------------------------------------- Inner classes
+ @Test
+ public void testGetPaths() throws Exception {
+ String[] actual = ChainResources.getResourcePaths(input);
- // Container for test data for one test
- public static final class TestData {
- private String input;
- private String[] expected;
- public TestData(String input, String[] expected) {
- this.input = input;
- this.expected = expected;
- }
- public String getInput() {
- return input;
- }
- public String[] getExpected() {
- return expected;
- }
+ assertNotNull(actual);
+ assertArrayEquals(expected, actual);
}
}