Author: julien(a)jboss.com
Date: 2007-10-17 09:16:16 -0400 (Wed, 17 Oct 2007)
New Revision: 8677
Added:
modules/test/trunk/unit/src/main/org/jboss/test/unit/pojo/MethodAndMethodArgumentAnnotatedWithParameter1.java
modules/test/trunk/unit/src/main/org/jboss/test/unit/pojo/MethodAndMethodArgumentAnnotatedWithParameter2.java
Removed:
modules/test/trunk/unit/src/main/org/jboss/test/unit/pojo/ClassHavingSamePropertyParameterAndMethodArgumentParameter.java
Modified:
modules/test/trunk/unit/src/main/org/jboss/test/unit/pojo/AbstractPOJOTests.java
modules/test/trunk/unit/src/main/org/jboss/unit/info/TestInfo.java
modules/test/trunk/unit/src/main/org/jboss/unit/spi/pojo/TestCaseDef.java
modules/test/trunk/unit/src/main/org/jboss/unit/spi/pojo/TestProviderSupport.java
Log:
specify the contract for getParameters() on TestInfo and implemented test case for it
Modified:
modules/test/trunk/unit/src/main/org/jboss/test/unit/pojo/AbstractPOJOTests.java
===================================================================
---
modules/test/trunk/unit/src/main/org/jboss/test/unit/pojo/AbstractPOJOTests.java 2007-10-17
13:07:31 UTC (rev 8676)
+++
modules/test/trunk/unit/src/main/org/jboss/test/unit/pojo/AbstractPOJOTests.java 2007-10-17
13:16:16 UTC (rev 8677)
@@ -25,6 +25,7 @@
import org.jboss.unit.api.Assert;
import static org.jboss.unit.util.CollectionTools.*;
+import static org.jboss.unit.api.Assert.*;
import java.util.Map;
import java.util.Collections;
@@ -63,7 +64,7 @@
testMethodAnnotatedWithTag();
//
- testClassHavingSamePropertyParameterAndMethodArgumentParameter();
+ testMethodAndMethodArgumentAnnotatedWithParameter();
//
testClassWithoutDefaultConstructor();
@@ -144,12 +145,15 @@
invoke(driver, clazz, "testFoo", AbstractPOJOTest.InvokeResult.PASS,
true);
}
- private void testClassHavingSamePropertyParameterAndMethodArgumentParameter()
+ private void testMethodAndMethodArgumentAnnotatedWithParameter()
{
- AbstractPOJOTest driver =
assertCanBuildSuite(ClassHavingSamePropertyParameterAndMethodArgumentParameter.class);
+ AbstractPOJOTest driver1 =
assertCanBuildSuite(MethodAndMethodArgumentAnnotatedWithParameter1.class);
+ invoke(driver1, MethodAndMethodArgumentAnnotatedWithParameter1.class,
"testFoo", AbstractPOJOTest.InvokeResult.PASS, true);
+
assertTrue(driver1.getParameterNames().containsAll(driver1.getTestCaseParameterNames("testFoo")));
- //
- invoke(driver, ClassHavingSamePropertyParameterAndMethodArgumentParameter.class,
"testFoo", AbstractPOJOTest.InvokeResult.PASS, true);
+ AbstractPOJOTest driver2 =
assertCanBuildSuite(MethodAndMethodArgumentAnnotatedWithParameter2.class);
+ invoke(driver2, MethodAndMethodArgumentAnnotatedWithParameter2.class,
"testFoo", AbstractPOJOTest.InvokeResult.PASS, true);
+
assertTrue(driver2.getParameterNames().containsAll(driver2.getTestCaseParameterNames("testFoo")));
}
private void testClassWithFailingConstructor()
Deleted:
modules/test/trunk/unit/src/main/org/jboss/test/unit/pojo/ClassHavingSamePropertyParameterAndMethodArgumentParameter.java
===================================================================
---
modules/test/trunk/unit/src/main/org/jboss/test/unit/pojo/ClassHavingSamePropertyParameterAndMethodArgumentParameter.java 2007-10-17
13:07:31 UTC (rev 8676)
+++
modules/test/trunk/unit/src/main/org/jboss/test/unit/pojo/ClassHavingSamePropertyParameterAndMethodArgumentParameter.java 2007-10-17
13:16:16 UTC (rev 8677)
@@ -1,51 +0,0 @@
-/******************************************************************************
- * JBoss, a division of Red Hat *
- * Copyright 2006, Red Hat Middleware, LLC, and individual *
- * contributors as indicated by the @authors tag. See the *
- * copyright.txt in the distribution for a full listing of *
- * individual contributors. *
- * *
- * This is free software; you can redistribute it and/or modify it *
- * under the terms of the GNU Lesser General Public License as *
- * published by the Free Software Foundation; either version 2.1 of *
- * the License, or (at your option) any later version. *
- * *
- * This software is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
- * Lesser General Public License for more details. *
- * *
- * You should have received a copy of the GNU Lesser General Public *
- * License along with this software; if not, write to the Free *
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
- ******************************************************************************/
-package org.jboss.test.unit.pojo;
-
-import org.jboss.unit.api.pojo.annotations.Parameter;
-import org.jboss.unit.api.pojo.annotations.Test;
-
-import java.util.Collections;
-
-/**
- * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
- * @version $Revision: 1.1 $
- */
-public class ClassHavingSamePropertyParameterAndMethodArgumentParameter
-{
-
- @Parameter
- public void setFoo(String foo)
- {
- POJOAssert.buffer1 = foo;
- }
-
- @Test
- public void testFoo(@Parameter(name="foo") String foo)
- {
- if (POJOAssert.buffer1 != null && POJOAssert.buffer1.equals(foo))
- {
-
POJOAssert.call(ClassHavingSamePropertyParameterAndMethodArgumentParameter.class,
Collections.singletonMap("foo", POJOAssert.buffer1));
- }
- }
-}
Copied:
modules/test/trunk/unit/src/main/org/jboss/test/unit/pojo/MethodAndMethodArgumentAnnotatedWithParameter1.java
(from rev 8670,
modules/test/trunk/unit/src/main/org/jboss/test/unit/pojo/ClassHavingSamePropertyParameterAndMethodArgumentParameter.java)
===================================================================
---
modules/test/trunk/unit/src/main/org/jboss/test/unit/pojo/MethodAndMethodArgumentAnnotatedWithParameter1.java
(rev 0)
+++
modules/test/trunk/unit/src/main/org/jboss/test/unit/pojo/MethodAndMethodArgumentAnnotatedWithParameter1.java 2007-10-17
13:16:16 UTC (rev 8677)
@@ -0,0 +1,48 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.test.unit.pojo;
+
+import org.jboss.unit.api.pojo.annotations.Parameter;
+import org.jboss.unit.api.pojo.annotations.Test;
+
+import java.util.Collections;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public class MethodAndMethodArgumentAnnotatedWithParameter1
+{
+
+ @Parameter
+ public void setFoo(String foo)
+ {
+ POJOAssert.buffer1 = foo;
+ }
+
+ @Test
+ public void testFoo(@Parameter(name="foo") String foo)
+ {
+ POJOAssert.call(MethodAndMethodArgumentAnnotatedWithParameter1.class,
Collections.singletonMap("foo", POJOAssert.buffer1));
+ }
+}
Added:
modules/test/trunk/unit/src/main/org/jboss/test/unit/pojo/MethodAndMethodArgumentAnnotatedWithParameter2.java
===================================================================
---
modules/test/trunk/unit/src/main/org/jboss/test/unit/pojo/MethodAndMethodArgumentAnnotatedWithParameter2.java
(rev 0)
+++
modules/test/trunk/unit/src/main/org/jboss/test/unit/pojo/MethodAndMethodArgumentAnnotatedWithParameter2.java 2007-10-17
13:16:16 UTC (rev 8677)
@@ -0,0 +1,52 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.test.unit.pojo;
+
+import org.jboss.unit.api.pojo.annotations.Parameter;
+import org.jboss.unit.api.pojo.annotations.Test;
+
+import java.util.Map;
+import java.util.HashMap;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public class MethodAndMethodArgumentAnnotatedWithParameter2
+{
+
+ @Parameter
+ public void setBar(String bar)
+ {
+ POJOAssert.buffer1 = bar;
+ }
+
+ @Test
+ public void testFoo(@Parameter(name="foo") String foo)
+ {
+ Map<String, String> map = new HashMap<String, String>();
+ map.put("bar", POJOAssert.buffer1);
+ map.put("foo", foo);
+ POJOAssert.call(MethodAndMethodArgumentAnnotatedWithParameter2.class, map);
+ }
+}
\ No newline at end of file
Modified: modules/test/trunk/unit/src/main/org/jboss/unit/info/TestInfo.java
===================================================================
--- modules/test/trunk/unit/src/main/org/jboss/unit/info/TestInfo.java 2007-10-17 13:07:31
UTC (rev 8676)
+++ modules/test/trunk/unit/src/main/org/jboss/unit/info/TestInfo.java 2007-10-17 13:16:16
UTC (rev 8677)
@@ -50,7 +50,9 @@
String getDescription();
/**
- * Return a map of parameters.
+ * Returns a map of parameters required to execute the test related to this
description. For a test case
+ * it returns a map of parameters to execute this test case. For a test suite it
returns a map
+ * formed by the union of the maps returned by the children of the test suite.
*
* @return the parameters
*/
Modified: modules/test/trunk/unit/src/main/org/jboss/unit/spi/pojo/TestCaseDef.java
===================================================================
--- modules/test/trunk/unit/src/main/org/jboss/unit/spi/pojo/TestCaseDef.java 2007-10-17
13:07:31 UTC (rev 8676)
+++ modules/test/trunk/unit/src/main/org/jboss/unit/spi/pojo/TestCaseDef.java 2007-10-17
13:16:16 UTC (rev 8677)
@@ -48,10 +48,10 @@
final String description;
/** . */
- final LinkedHashMap<String,ArgumentTestParameter> arguments;
+ final LinkedHashMap<String, ArgumentTestParameter> arguments;
/** . */
- final Map<String,TestParameter> parameters;
+ final Map<String, TestParameter> parameters;
/** . */
final Set<String> keywords;
Modified:
modules/test/trunk/unit/src/main/org/jboss/unit/spi/pojo/TestProviderSupport.java
===================================================================
---
modules/test/trunk/unit/src/main/org/jboss/unit/spi/pojo/TestProviderSupport.java 2007-10-17
13:07:31 UTC (rev 8676)
+++
modules/test/trunk/unit/src/main/org/jboss/unit/spi/pojo/TestProviderSupport.java 2007-10-17
13:16:16 UTC (rev 8677)
@@ -73,7 +73,7 @@
private final Method destroy;
/** . */
- final Map<String, PropertyTestParameter> suiteParameters;
+ final Map<String, PropertyTestParameter> propertyParameters;
/** . */
private final Constructor ctor;
@@ -81,6 +81,9 @@
/** . */
private final Set<String> suiteKeywords;
+ /** . */
+ final Map<String, TestParameter> suiteParameters;
+
public TestProviderSupport(Class testClass)
{
if (testClass == null)
@@ -137,7 +140,7 @@
}
//
- Map<String, PropertyTestParameter> suiteParameters = new HashMap<String,
PropertyTestParameter>();
+ Map<String, PropertyTestParameter> propertyParameters = new
HashMap<String, PropertyTestParameter>();
Map<String, TestCaseDef> testCases = new HashMap<String,
TestCaseDef>();
Method create = null;
Method destroy = null;
@@ -230,11 +233,11 @@
}
//
- PropertyTestParameter parameter = suiteParameters.get(name);
+ PropertyTestParameter parameter = propertyParameters.get(name);
if (parameter == null)
{
parameter = new PropertyTestParameter(name, description);
- suiteParameters.put(name, parameter);
+ propertyParameters.put(name, parameter);
}
//
@@ -396,7 +399,8 @@
keywords.addAll(CollectionTools.set(tagMethodAnnotation.value()));
}
- Map<String,TestParameter> parameters = new HashMap<String,
TestParameter>(suiteParameters);
+ //
+ Map<String,TestParameter> parameters = new HashMap<String,
TestParameter>(propertyParameters);
parameters.putAll(methodParameters);
//
@@ -410,15 +414,26 @@
}
}
- //
+ // Set the state computed from the annotations
this.suiteName = suiteName;
this.suiteDescription = suiteDescription;
this.suiteKeywords = suiteKeywords;
- this.suiteParameters = suiteParameters;
+ this.propertyParameters = propertyParameters;
this.testCases = testCases;
this.ctor = ctor;
this.create = create;
this.destroy = destroy;
+
+ // Compute the suite parameters
+ Map<String, TestParameter> suiteParameters = new HashMap<String,
TestParameter>();
+ for (TestCaseDef testCase : testCases.values())
+ {
+ suiteParameters.putAll(testCase.arguments);
+ }
+ suiteParameters.putAll(propertyParameters);
+
+ // Set the state computed from the existing state
+ this.suiteParameters = suiteParameters;
}
public TestSuiteDescriptor getDescriptor()
@@ -493,7 +508,7 @@
testCase.parametrization = parametrization;
//
- for (PropertyTestParameter parameter : suiteParameters.values())
+ for (PropertyTestParameter parameter : propertyParameters.values())
{
if (!parametrization.containsKey(parameter.getName()))
{