[testng] 42/160: JDK7 migration: Replace for loop with foreach

Eugene Zhukov eugene-guest at moszumanska.debian.org
Tue Aug 18 10:22:20 UTC 2015


This is an automated email from the git hooks/post-receive script.

eugene-guest pushed a commit to annotated tag testng-6.9.5
in repository testng.

commit d46142454fa19e07df3851321c2d35df0f52a7da
Author: Ryan Schmitt <rschmitt at pobox.com>
Date:   Sat May 30 21:24:37 2015 -0700

    JDK7 migration: Replace for loop with foreach
---
 src/main/java/org/testng/Assert.java               |  6 +--
 .../org/testng/internal/ConfigurationMethod.java   | 30 +++++++-------
 src/main/java/org/testng/remote/RemoteTestNG.java  |  4 +-
 .../remote/strprotocol/TestResultMessage.java      | 48 +++++++++++-----------
 .../java/org/testng/reporters/FailedReporter.java  |  4 +-
 .../org/testng/reporters/SuiteHTMLReporter.java    |  3 +-
 .../java/org/testng/reporters/XMLReporter.java     |  4 +-
 src/test/java/test/BaseDistributedTest.java        | 10 ++---
 src/test/java/test/BaseTest.java                   |  4 +-
 9 files changed, 56 insertions(+), 57 deletions(-)

diff --git a/src/main/java/org/testng/Assert.java b/src/main/java/org/testng/Assert.java
index d15c032..5f035bf 100644
--- a/src/main/java/org/testng/Assert.java
+++ b/src/main/java/org/testng/Assert.java
@@ -829,13 +829,13 @@ public class Assert {
     }
 
     Set<?> entrySet = actual.entrySet();
-    for (Iterator<?> iterator = entrySet.iterator(); iterator.hasNext();) {
-      Map.Entry<?, ?> entry = (Map.Entry<?, ?>) iterator.next();
+    for (Object anEntrySet : entrySet) {
+      Map.Entry<?, ?> entry = (Map.Entry<?, ?>) anEntrySet;
       Object key = entry.getKey();
       Object value = entry.getValue();
       Object expectedValue = expected.get(key);
       assertEquals(value, expectedValue, "Maps do not match for key:" + key + " actual:" + value
-          + " expected:" + expectedValue);
+              + " expected:" + expectedValue);
     }
 
   }
diff --git a/src/main/java/org/testng/internal/ConfigurationMethod.java b/src/main/java/org/testng/internal/ConfigurationMethod.java
index 2c84bcd..1bd5c7e 100755
--- a/src/main/java/org/testng/internal/ConfigurationMethod.java
+++ b/src/main/java/org/testng/internal/ConfigurationMethod.java
@@ -135,21 +135,21 @@ public class ConfigurationMethod extends BaseTestMethod {
       Object instance)
   {
     List<ITestNGMethod> result = Lists.newArrayList();
-    for(int i = 0; i < methods.length; i++) {
-      result.add(new ConfigurationMethod(methods[i].getConstructorOrMethod(),
-                                          finder,
-                                          isBeforeSuite,
-                                          isAfterSuite,
-                                          isBeforeTest,
-                                          isAfterTest,
-                                          isBeforeClass,
-                                          isAfterClass,
-                                          isBeforeMethod,
-                                          isAfterMethod,
-                                          new String[0],
-                                          new String[0],
-                                          instance));
-    }
+      for (ITestNGMethod method : methods) {
+          result.add(new ConfigurationMethod(method.getConstructorOrMethod(),
+                  finder,
+                  isBeforeSuite,
+                  isAfterSuite,
+                  isBeforeTest,
+                  isAfterTest,
+                  isBeforeClass,
+                  isAfterClass,
+                  isBeforeMethod,
+                  isAfterMethod,
+                  new String[0],
+                  new String[0],
+                  instance));
+      }
 
     return result.toArray(new ITestNGMethod[result.size()]);
   }
diff --git a/src/main/java/org/testng/remote/RemoteTestNG.java b/src/main/java/org/testng/remote/RemoteTestNG.java
index 8b3668e..b9bfbcb 100644
--- a/src/main/java/org/testng/remote/RemoteTestNG.java
+++ b/src/main/java/org/testng/remote/RemoteTestNG.java
@@ -95,8 +95,8 @@ public class RemoteTestNG extends TestNG {
 
         int testCount= 0;
 
-        for(int i= 0; i < suites.size(); i++) {
-          testCount+= (suites.get(i)).getTests().size();
+        for (XmlSuite suite : suites) {
+          testCount += suite.getTests().size();
         }
 
         GenericMessage gm= new GenericMessage(MessageHelper.GENERIC_SUITE_COUNT);
diff --git a/src/main/java/org/testng/remote/strprotocol/TestResultMessage.java b/src/main/java/org/testng/remote/strprotocol/TestResultMessage.java
index 3fbef04..6c9bf95 100755
--- a/src/main/java/org/testng/remote/strprotocol/TestResultMessage.java
+++ b/src/main/java/org/testng/remote/strprotocol/TestResultMessage.java
@@ -344,44 +344,44 @@ public class TestResultMessage implements IStringMessage {
     List<String> results = Lists.newArrayList();
     if (o instanceof byte[]) {
       byte[] array = (byte[]) o;
-      for (int i = 0; i < array.length; i++) {
-        results.add(String.valueOf(array[i]));
-      }
+        for (byte anArray : array) {
+            results.add(String.valueOf(anArray));
+        }
     } else if (o instanceof boolean[]) {
       boolean[] array = (boolean[]) o;
-      for (int i = 0; i < array.length; i++) {
-        results.add(String.valueOf(array[i]));
-      }
+        for (boolean anArray : array) {
+            results.add(String.valueOf(anArray));
+        }
     } else if (o instanceof char[]) {
       char[] array = (char[]) o;
-      for (int i = 0; i < array.length; i++) {
-        results.add(String.valueOf(array[i]));
-      }
+        for (char anArray : array) {
+            results.add(String.valueOf(anArray));
+        }
     } else if (o instanceof double[]) {
       double[] array = (double[]) o;
-      for (int i = 0; i < array.length; i++) {
-        results.add(String.valueOf(array[i]));
-      }
+        for (double anArray : array) {
+            results.add(String.valueOf(anArray));
+        }
     } else if (o instanceof float[]) {
       float[] array = (float[]) o;
-      for (int i = 0; i < array.length; i++) {
-        results.add(String.valueOf(array[i]));
-      }
+        for (float anArray : array) {
+            results.add(String.valueOf(anArray));
+        }
     } else if (o instanceof short[]) {
       short[] array = (short[]) o;
-      for (int i = 0; i < array.length; i++) {
-        results.add(String.valueOf(array[i]));
-      }
+        for (short anArray : array) {
+            results.add(String.valueOf(anArray));
+        }
     } else if (o instanceof int[]) {
       int[] array = (int[]) o;
-      for (int i = 0; i < array.length; i++) {
-        results.add(String.valueOf(array[i]));
-      }
+        for (int anArray : array) {
+            results.add(String.valueOf(anArray));
+        }
     } else if (o instanceof long[]) {
       long[] array = (long[]) o;
-      for (int i = 0; i < array.length; i++) {
-        results.add(String.valueOf(array[i]));
-      }
+        for (long anArray : array) {
+            results.add(String.valueOf(anArray));
+        }
     }
     return results.toArray(new String[results.size()]);
   }
diff --git a/src/main/java/org/testng/reporters/FailedReporter.java b/src/main/java/org/testng/reporters/FailedReporter.java
index 621b63c..2165aa4 100755
--- a/src/main/java/org/testng/reporters/FailedReporter.java
+++ b/src/main/java/org/testng/reporters/FailedReporter.java
@@ -43,8 +43,8 @@ public class FailedReporter extends TestListenerAdapter implements IReporter {
 
   @Override
   public void generateReport(List<XmlSuite> xmlSuites, List<ISuite> suites, String outputDirectory) {
-    for(int i= 0; i < suites.size(); i++) {
-      generateFailureSuite(suites.get(i).getXmlSuite(), suites.get(i), outputDirectory);
+    for (ISuite suite : suites) {
+      generateFailureSuite(suite.getXmlSuite(), suite, outputDirectory);
     }
   }
 
diff --git a/src/main/java/org/testng/reporters/SuiteHTMLReporter.java b/src/main/java/org/testng/reporters/SuiteHTMLReporter.java
index f54a519..3c75de0 100755
--- a/src/main/java/org/testng/reporters/SuiteHTMLReporter.java
+++ b/src/main/java/org/testng/reporters/SuiteHTMLReporter.java
@@ -54,12 +54,11 @@ public class SuiteHTMLReporter implements IReporter {
       e.printStackTrace();
     }
 
-    for (int i = 0; i < suites.size(); i++) {
+    for (ISuite suite : suites) {
 
       //
       // Generate the various reports
       //
-      ISuite suite = suites.get(i);
       XmlSuite xmlSuite = suite.getXmlSuite();
       if (xmlSuite.getTests().size() == 0) {
         continue;
diff --git a/src/main/java/org/testng/reporters/XMLReporter.java b/src/main/java/org/testng/reporters/XMLReporter.java
index b52c689..b532514 100755
--- a/src/main/java/org/testng/reporters/XMLReporter.java
+++ b/src/main/java/org/testng/reporters/XMLReporter.java
@@ -59,8 +59,8 @@ public class XMLReporter implements IReporter {
     p.put("total", passed + failed + skipped);
     rootBuffer.push(XMLReporterConfig.TAG_TESTNG_RESULTS, p);
     writeReporterOutput(rootBuffer);
-    for (int i = 0; i < suites.size(); i++) {
-      writeSuite(suites.get(i).getXmlSuite(), suites.get(i));
+    for (ISuite suite : suites) {
+      writeSuite(suite.getXmlSuite(), suite);
     }
     rootBuffer.pop();
     Utils.writeUtf8File(config.getOutputDirectory(), FILE_NAME, rootBuffer, null /* no prefix */);
diff --git a/src/test/java/test/BaseDistributedTest.java b/src/test/java/test/BaseDistributedTest.java
index 253eba9..2dcfa66 100644
--- a/src/test/java/test/BaseDistributedTest.java
+++ b/src/test/java/test/BaseDistributedTest.java
@@ -18,16 +18,16 @@ public class BaseDistributedTest {
     Assert.assertEquals(found.size(), expected.size(),
         "Verification for " + title + " tests failed:");
 
-    for(Iterator it = expected.values().iterator(); it.hasNext();) {
-      String name = (String) it.next();
-      if(null == found.get(name)) {
+    for (Object o : expected.values()) {
+      String name = (String) o;
+      if (null == found.get(name)) {
         dumpMap("Expected", expected);
         dumpMap("Found", found);
       }
 
       Assert.assertNotNull(found.get(name),
-          "Expected to find method " + name + " in " + title
-          + " but didn't find it.");
+              "Expected to find method " + name + " in " + title
+                      + " but didn't find it.");
     }
   }
 
diff --git a/src/test/java/test/BaseTest.java b/src/test/java/test/BaseTest.java
index c4c0733..632bb0f 100644
--- a/src/test/java/test/BaseTest.java
+++ b/src/test/java/test/BaseTest.java
@@ -280,8 +280,8 @@ public class BaseTest extends BaseDistributedTest {
   private Collection computeDifferences(Map m1, Map m2) {
     List result= new ArrayList();
 
-    for(Iterator it= m1.keySet().iterator(); it.hasNext();) {
-      it.next();
+    for (Object o : m1.keySet()) {
+      o;
     }
 
     return result;

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-java/testng.git



More information about the pkg-java-commits mailing list