Browse Source

Make loops less verbose

master
Gintas Grigelionis 7 years ago
parent
commit
97ac63abcb
3 changed files with 15 additions and 25 deletions
  1. +3
    -7
      src/tests/junit/org/apache/tools/ant/IntrospectionHelperTest.java
  2. +10
    -13
      src/tests/junit/org/apache/tools/ant/taskdefs/XmlPropertyTest.java
  3. +2
    -5
      src/tests/junit/org/apache/tools/zip/UTF8ZipFilesTest.java

+ 3
- 7
src/tests/junit/org/apache/tools/ant/IntrospectionHelperTest.java View File

@@ -23,7 +23,7 @@ import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.nio.file.Path; import java.nio.file.Path;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.util.Enumeration;
import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.Hashtable; import java.util.Hashtable;
import java.util.List; import java.util.List;
@@ -253,9 +253,7 @@ public class IntrospectionHelperTest {
@Test @Test
public void testGetNestedElements() { public void testGetNestedElements() {
Map<String, Class<?>> elemMap = getExpectedNestedElements(); Map<String, Class<?>> elemMap = getExpectedNestedElements();
Enumeration<String> e = ih.getNestedElements();
while (e.hasMoreElements()) {
String name = e.nextElement();
for (String name : Collections.list(ih.getNestedElements())) {
Class<?> expect = elemMap.get(name); Class<?> expect = elemMap.get(name);
assertNotNull("Support for " + name + " in IntrospectioNHelperTest?", assertNotNull("Support for " + name + " in IntrospectioNHelperTest?",
expect); expect);
@@ -594,9 +592,7 @@ public class IntrospectionHelperTest {
@Test @Test
public void testGetAttributes() { public void testGetAttributes() {
Map<String, Class<?>> attrMap = getExpectedAttributes(); Map<String, Class<?>> attrMap = getExpectedAttributes();
Enumeration<String> e = ih.getAttributes();
while (e.hasMoreElements()) {
String name = e.nextElement();
for (String name : Collections.list(ih.getAttributes())) {
Class<?> expect = attrMap.get(name); Class<?> expect = attrMap.get(name);
assertNotNull("Support for " + name + " in IntrospectionHelperTest?", assertNotNull("Support for " + name + " in IntrospectionHelperTest?",
expect); expect);


+ 10
- 13
src/tests/junit/org/apache/tools/ant/taskdefs/XmlPropertyTest.java View File

@@ -22,11 +22,11 @@ import java.io.File;
import java.io.FileFilter; import java.io.FileFilter;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.IOException; import java.io.IOException;
import java.util.Enumeration;
import java.util.ArrayList;
import java.util.Hashtable; import java.util.Hashtable;
import java.util.Map; import java.util.Map;
import java.util.List;
import java.util.Properties; import java.util.Properties;
import java.util.Vector;


import org.apache.tools.ant.BuildFileRule; import org.apache.tools.ant.BuildFileRule;
import org.apache.tools.ant.Project; import org.apache.tools.ant.Project;
@@ -149,10 +149,7 @@ public class XmlPropertyTest {
*/ */
private void doTest(String msg, boolean keepRoot, boolean collapse, private void doTest(String msg, boolean keepRoot, boolean collapse,
boolean semantic, boolean include, boolean localRoot) throws IOException { boolean semantic, boolean include, boolean localRoot) throws IOException {
Enumeration<File> iter =
getFiles(buildRule.getProject().resolveFile("xmlproperty/inputs"));
while (iter.hasMoreElements()) {
File inputFile = iter.nextElement();
for (File inputFile : getFiles(buildRule.getProject().resolveFile("xmlproperty/inputs"))) {
// What's the working directory? If local, then its the // What's the working directory? If local, then its the
// folder of the input file. Otherwise, its the "current" dir.. // folder of the input file. Otherwise, its the "current" dir..
File workingDir; File workingDir;
@@ -325,30 +322,30 @@ public class XmlPropertyTest {
* Retrieve a list of xml files in the specified folder * Retrieve a list of xml files in the specified folder
* and below. * and below.
*/ */
private static Enumeration<File> getFiles(final File startingDir) {
Vector<File> result = new Vector<>();
private static List<File> getFiles(final File startingDir) {
List<File> result = new ArrayList<>();
getFiles(startingDir, result); getFiles(startingDir, result);
return result.elements();
return result;
} }


/** /**
* Collect a list of xml files in the specified folder * Collect a list of xml files in the specified folder
* and below. * and below.
*/ */
private static void getFiles(final File startingDir, Vector<File> collect) {
private static void getFiles(final File startingDir, List<File> collect) {
FileFilter filter = file -> { FileFilter filter = file -> {
if (file.isDirectory()) { if (file.isDirectory()) {
return true; return true;
} else { } else {
return (file.getPath().indexOf("taskdefs") > 0 &&
file.getPath().toLowerCase().endsWith(".xml"));
return file.getPath().contains("taskdefs")
&& file.getPath().toLowerCase().endsWith(".xml");
} }
}; };


File[] files = startingDir.listFiles(filter); File[] files = startingDir.listFiles(filter);
for (File f : files) { for (File f : files) {
if (!f.isDirectory()) { if (!f.isDirectory()) {
collect.addElement(f);
collect.add(f);
} else { } else {
getFiles(f, collect); getFiles(f, collect);
} }


+ 2
- 5
src/tests/junit/org/apache/tools/zip/UTF8ZipFilesTest.java View File

@@ -22,6 +22,7 @@ import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.util.Collections;
import java.util.Enumeration; import java.util.Enumeration;
import java.util.zip.CRC32; import java.util.zip.CRC32;
import org.junit.Test; import org.junit.Test;
@@ -189,11 +190,7 @@ public class UTF8ZipFilesTest {
ZipFile zf = null; ZipFile zf = null;
try { try {
zf = new ZipFile(file, encoding, false); zf = new ZipFile(file, encoding, false);

Enumeration<ZipEntry> e = zf.getEntries();
while (e.hasMoreElements()) {
ZipEntry ze = e.nextElement();

for (ZipEntry ze : Collections.list(zf.getEntries())) {
if (ze.getName().endsWith("sser.txt")) { if (ze.getName().endsWith("sser.txt")) {
assertUnicodeName(ze, OIL_BARREL_TXT, encoding); assertUnicodeName(ze, OIL_BARREL_TXT, encoding);




Loading…
Cancel
Save