svn commit: r682060 - in /ofbiz/trunk/framework/testtools/src/org/ofbiz/testtools: EntityXmlAssertTest.java JunitSuiteWrapper.java ModelTestSuite.java ServiceTest.java SimpleMethodTest.java TestRunContainer.java

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r682060 - in /ofbiz/trunk/framework/testtools/src/org/ofbiz/testtools: EntityXmlAssertTest.java JunitSuiteWrapper.java ModelTestSuite.java ServiceTest.java SimpleMethodTest.java TestRunContainer.java

doogie-3
Author: doogie
Date: Sat Aug  2 14:39:20 2008
New Revision: 682060

URL: http://svn.apache.org/viewvc?rev=682060&view=rev
Log:
More generics.

Modified:
    ofbiz/trunk/framework/testtools/src/org/ofbiz/testtools/EntityXmlAssertTest.java
    ofbiz/trunk/framework/testtools/src/org/ofbiz/testtools/JunitSuiteWrapper.java
    ofbiz/trunk/framework/testtools/src/org/ofbiz/testtools/ModelTestSuite.java
    ofbiz/trunk/framework/testtools/src/org/ofbiz/testtools/ServiceTest.java
    ofbiz/trunk/framework/testtools/src/org/ofbiz/testtools/SimpleMethodTest.java
    ofbiz/trunk/framework/testtools/src/org/ofbiz/testtools/TestRunContainer.java

Modified: ofbiz/trunk/framework/testtools/src/org/ofbiz/testtools/EntityXmlAssertTest.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/testtools/src/org/ofbiz/testtools/EntityXmlAssertTest.java?rev=682060&r1=682059&r2=682060&view=diff
==============================================================================
--- ofbiz/trunk/framework/testtools/src/org/ofbiz/testtools/EntityXmlAssertTest.java (original)
+++ ofbiz/trunk/framework/testtools/src/org/ofbiz/testtools/EntityXmlAssertTest.java Sat Aug  2 14:39:20 2008
@@ -23,12 +23,15 @@
 
 import org.w3c.dom.Element;
 import org.ofbiz.entity.GenericDelegator;
+import org.ofbiz.entity.GenericValue;
 import org.ofbiz.entity.util.EntityDataAssert;
 import org.ofbiz.entity.util.EntitySaxReader;
 import org.ofbiz.base.util.UtilValidate;
 import org.ofbiz.base.util.Debug;
 import org.ofbiz.base.location.FlexibleLocation;
 
+import javolution.util.FastList;
+
 import java.util.List;
 import java.util.ArrayList;
 import java.util.Iterator;
@@ -55,7 +58,7 @@
         int testCaseCount = 0;
         try {
             URL entityXmlURL = FlexibleLocation.resolveLocation(entityXmlUrlString);
-            List checkValueList = modelTestSuite.getDelegator().readXmlDocument(entityXmlURL);
+            List<GenericValue> checkValueList = modelTestSuite.getDelegator().readXmlDocument(entityXmlURL);
             testCaseCount = checkValueList.size();
         } catch (Exception e) {
             Debug.logError(e, "Error getting test case count", module);
@@ -69,7 +72,7 @@
         try {
             URL entityXmlURL = FlexibleLocation.resolveLocation(entityXmlUrlString);
             GenericDelegator delegator = modelTestSuite.getDelegator();
-            List errorMessages = new ArrayList();
+            List<Object> errorMessages = FastList.newInstance();
 
             if ("assert".equals(this.action)) {
                 EntityDataAssert.assertData(entityXmlURL, delegator, errorMessages);
@@ -82,10 +85,8 @@
             }
 
             if (UtilValidate.isNotEmpty(errorMessages)) {
-                Iterator failureIterator = errorMessages.iterator();
-                while (failureIterator.hasNext()) {
-                    String failureMessage = (String) failureIterator.next();
-                    result.addFailure(this, new AssertionFailedError(failureMessage));
+                for (Object failureMessage: errorMessages) {
+                    result.addFailure(this, new AssertionFailedError(failureMessage.toString()));
                 }
             }
         } catch (Exception e) {

Modified: ofbiz/trunk/framework/testtools/src/org/ofbiz/testtools/JunitSuiteWrapper.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/testtools/src/org/ofbiz/testtools/JunitSuiteWrapper.java?rev=682060&r1=682059&r2=682060&view=diff
==============================================================================
--- ofbiz/trunk/framework/testtools/src/org/ofbiz/testtools/JunitSuiteWrapper.java (original)
+++ ofbiz/trunk/framework/testtools/src/org/ofbiz/testtools/JunitSuiteWrapper.java Sat Aug  2 14:39:20 2008
@@ -39,13 +39,10 @@
 
     public static final String module = JunitSuiteWrapper.class.getName();
     
-    protected List modelTestSuiteList = FastList.newInstance();
+    protected List<ModelTestSuite> modelTestSuiteList = FastList.newInstance();
     
     public JunitSuiteWrapper(String componentName, String testCase) {
-        List testSuiteInfoList = ComponentConfig.getAllTestSuiteInfos(componentName);
-        Iterator testSuiteInfoIter = testSuiteInfoList.iterator();
-        while (testSuiteInfoIter.hasNext()) {
-            ComponentConfig.TestSuiteInfo testSuiteInfo = (ComponentConfig.TestSuiteInfo) testSuiteInfoIter.next();
+        for (ComponentConfig.TestSuiteInfo testSuiteInfo: ComponentConfig.getAllTestSuiteInfos(componentName)) {
             ResourceHandler testSuiteResource = testSuiteInfo.createResourceHandler();
 
             try {
@@ -69,30 +66,20 @@
 
     @Deprecated
     public void populateTestSuite(TestSuite suite) {
-        Iterator modelTestSuiteIter = this.modelTestSuiteList.iterator();
-        while (modelTestSuiteIter.hasNext()) {
-            ModelTestSuite modelTestSuite = (ModelTestSuite) modelTestSuiteIter.next();
-            List testList = modelTestSuite.getTestList();
-            Iterator testIter = testList.iterator();
-            while (testIter.hasNext()) {
-                Test tst = (Test) testIter.next();
+        for (ModelTestSuite modelTestSuite: this.modelTestSuiteList) {
+            for (Test tst: modelTestSuite.getTestList()) {
                 suite.addTest(tst);
             }
         }
     }
 
-    public List makeTestSuites() {
-        List testSuites = FastList.newInstance();
+    public List<TestSuite> makeTestSuites() {
+        List<TestSuite> testSuites = FastList.newInstance();
 
-        Iterator modelTestSuiteIter = this.modelTestSuiteList.iterator();
-        while (modelTestSuiteIter.hasNext()) {
-            ModelTestSuite modelTestSuite = (ModelTestSuite) modelTestSuiteIter.next();
+        for (ModelTestSuite modelTestSuite: this.modelTestSuiteList) {
             TestSuite suite = new TestSuite();
             suite.setName(modelTestSuite.getSuiteName());
-            List testList = modelTestSuite.getTestList();
-            Iterator testIter = testList.iterator();
-            while (testIter.hasNext()) {
-                Test tst = (Test) testIter.next();
+            for (Test tst: modelTestSuite.getTestList()) {
                 suite.addTest(tst);
             }
             testSuites.add(suite);
@@ -101,16 +88,11 @@
         return testSuites;
     }
     
-    public List getAllTestList() {
-        List allTestList = FastList.newInstance();
+    public List<Test> getAllTestList() {
+        List<Test> allTestList = FastList.newInstance();
 
-        Iterator modelTestSuiteIter = this.modelTestSuiteList.iterator();
-        while (modelTestSuiteIter.hasNext()) {
-            ModelTestSuite modelTestSuite = (ModelTestSuite) modelTestSuiteIter.next();
-            List testList = modelTestSuite.getTestList();
-            Iterator testIter = testList.iterator();
-            while (testIter.hasNext()) {
-                Test tst = (Test) testIter.next();
+        for (ModelTestSuite modelTestSuite: this.modelTestSuiteList) {
+            for (Test tst: modelTestSuite.getTestList()) {
                 allTestList.add(tst);
             }
         }

Modified: ofbiz/trunk/framework/testtools/src/org/ofbiz/testtools/ModelTestSuite.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/testtools/src/org/ofbiz/testtools/ModelTestSuite.java?rev=682060&r1=682059&r2=682060&view=diff
==============================================================================
--- ofbiz/trunk/framework/testtools/src/org/ofbiz/testtools/ModelTestSuite.java (original)
+++ ofbiz/trunk/framework/testtools/src/org/ofbiz/testtools/ModelTestSuite.java Sat Aug  2 14:39:20 2008
@@ -49,7 +49,7 @@
     protected GenericDelegator delegator;
     protected LocalDispatcher dispatcher;
 
-    protected List testList = FastList.newInstance();
+    protected List<Test> testList = FastList.newInstance();
     
     public ModelTestSuite(Element mainElement, String testCase) {
         this.suiteName = mainElement.getAttribute("suite-name");
@@ -63,10 +63,7 @@
         this.delegator = GenericDelegator.getGenericDelegator(this.delegatorName);
         this.dispatcher = GenericDispatcher.getLocalDispatcher(this.dispatcherName, delegator);
         
-        List testCaseElementList = UtilXml.childElementList(mainElement, "test-case");
-        Iterator testCaseElementIter = testCaseElementList.iterator();
-        while (testCaseElementIter.hasNext()) {
-            Element testCaseElement = (Element) testCaseElementIter.next();
+        for (Element testCaseElement : UtilXml.childElementList(mainElement, "test-case")) {
             String caseName = testCaseElement.getAttribute("case-name");
             if (testCase == null || caseName.equals(testCase)) {
                 Element childElement = UtilXml.firstChildElement(testCaseElement);
@@ -120,7 +117,7 @@
         return this.dispatcher;
     }
     
-    List getTestList() {
+    List<Test> getTestList() {
         return testList;
     }
 }

Modified: ofbiz/trunk/framework/testtools/src/org/ofbiz/testtools/ServiceTest.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/testtools/src/org/ofbiz/testtools/ServiceTest.java?rev=682060&r1=682059&r2=682060&view=diff
==============================================================================
--- ofbiz/trunk/framework/testtools/src/org/ofbiz/testtools/ServiceTest.java (original)
+++ ofbiz/trunk/framework/testtools/src/org/ofbiz/testtools/ServiceTest.java Sat Aug  2 14:39:20 2008
@@ -26,6 +26,7 @@
 import org.ofbiz.service.GenericServiceException;
 import org.ofbiz.service.ServiceUtil;
 import org.ofbiz.service.ModelService;
+import org.ofbiz.base.util.UtilGenerics;
 import org.ofbiz.base.util.UtilMisc;
 import org.ofbiz.base.util.UtilValidate;
 
@@ -58,7 +59,7 @@
 
         try {
 
-            Map serviceResult = dispatcher.runSync(serviceName, UtilMisc.toMap("test", this, "testResult", result));
+            Map<String, Object> serviceResult = dispatcher.runSync(serviceName, UtilMisc.toMap("test", this, "testResult", result));
 
             // do something with the errorMessage
             String errorMessage = (String) serviceResult.get(ModelService.ERROR_MESSAGE);
@@ -67,20 +68,17 @@
             }
 
             // do something with the errorMessageList
-            List errorMessageList = (List) serviceResult.get(ModelService.ERROR_MESSAGE_LIST);
+            List<Object> errorMessageList = UtilGenerics.checkList(serviceResult.get(ModelService.ERROR_MESSAGE_LIST));
             if (UtilValidate.isNotEmpty(errorMessageList)) {
-                Iterator i = errorMessageList.iterator();
-                while (i.hasNext()) {
-                    result.addFailure(this, new AssertionFailedError((String) i.next()));
+                for (Object message: errorMessageList) {
+                    result.addFailure(this, new AssertionFailedError(message.toString()));
                 }
             }
 
             // do something with the errorMessageMap
-            Map errorMessageMap = (Map) serviceResult.get(ModelService.ERROR_MESSAGE_MAP);
+            Map<String, Object> errorMessageMap = UtilGenerics.cast(serviceResult.get(ModelService.ERROR_MESSAGE_MAP));
             if (!UtilValidate.isEmpty(errorMessageMap)) {
-                Iterator i = errorMessageMap.entrySet().iterator();
-                while (i.hasNext()) {
-                    Map.Entry entry = (Map.Entry) i.next();
+                for (Map.Entry<String, Object> entry: errorMessageMap.entrySet()) {
                     result.addFailure(this, new AssertionFailedError(entry.getKey() + ": " + entry.getValue()));
                 }
             }

Modified: ofbiz/trunk/framework/testtools/src/org/ofbiz/testtools/SimpleMethodTest.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/testtools/src/org/ofbiz/testtools/SimpleMethodTest.java?rev=682060&r1=682059&r2=682060&view=diff
==============================================================================
--- ofbiz/trunk/framework/testtools/src/org/ofbiz/testtools/SimpleMethodTest.java (original)
+++ ofbiz/trunk/framework/testtools/src/org/ofbiz/testtools/SimpleMethodTest.java Sat Aug  2 14:39:20 2008
@@ -26,6 +26,7 @@
 import junit.framework.AssertionFailedError;
 import junit.framework.TestResult;
 
+import org.ofbiz.base.util.UtilGenerics;
 import org.ofbiz.base.util.UtilMisc;
 import org.ofbiz.base.util.UtilValidate;
 import org.ofbiz.minilang.MiniLangException;
@@ -71,20 +72,17 @@
             }
 
             // do something with the errorMessageList
-            List errorMessageList = (List) serviceResult.get(ModelService.ERROR_MESSAGE_LIST);
+            List<Object> errorMessageList = UtilGenerics.cast(serviceResult.get(ModelService.ERROR_MESSAGE_LIST));
             if (UtilValidate.isNotEmpty(errorMessageList)) {
-                Iterator i = errorMessageList.iterator();
-                while (i.hasNext()) {
-                    result.addFailure(this, new AssertionFailedError((String) i.next()));
+                for (Object message: errorMessageList) {
+                    result.addFailure(this, new AssertionFailedError(message.toString()));
                 }
             }
 
             // do something with the errorMessageMap
-            Map errorMessageMap = (Map) serviceResult.get(ModelService.ERROR_MESSAGE_MAP);
+            Map<String, Object> errorMessageMap = UtilGenerics.cast(serviceResult.get(ModelService.ERROR_MESSAGE_MAP));
             if (!UtilValidate.isEmpty(errorMessageMap)) {
-                Iterator i = errorMessageMap.entrySet().iterator();
-                while (i.hasNext()) {
-                    Map.Entry entry = (Map.Entry) i.next();
+                for (Map.Entry<String, Object> entry: errorMessageMap.entrySet()) {
                     result.addFailure(this, new AssertionFailedError(entry.getKey() + ": " + entry.getValue()));
                 }
             }

Modified: ofbiz/trunk/framework/testtools/src/org/ofbiz/testtools/TestRunContainer.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/testtools/src/org/ofbiz/testtools/TestRunContainer.java?rev=682060&r1=682059&r2=682060&view=diff
==============================================================================
--- ofbiz/trunk/framework/testtools/src/org/ofbiz/testtools/TestRunContainer.java (original)
+++ ofbiz/trunk/framework/testtools/src/org/ofbiz/testtools/TestRunContainer.java Sat Aug  2 14:39:20 2008
@@ -107,10 +107,7 @@
             throw new ContainerException("No tests found (" + component + " / " + testCase + ")");
         }
 
-        List testSuites = jsWrapper.makeTestSuites();
-        Iterator i = testSuites.iterator();
-        while (i.hasNext()) {
-            TestSuite suite = (TestSuite) i.next();
+        for (TestSuite suite: jsWrapper.makeTestSuites()) {
             JUnitTest test = new JUnitTest();
             test.setName(suite.getName());