Browse Source

More uses for streams

master
Gintas Grigelionis 7 years ago
parent
commit
3f74fc257a
4 changed files with 14 additions and 32 deletions
  1. +6
    -8
      src/tests/junit/org/apache/tools/ant/IntrospectionHelperTest.java
  2. +2
    -6
      src/tests/junit/org/apache/tools/ant/taskdefs/ExecuteWatchdogTest.java
  3. +3
    -9
      src/tests/junit/org/apache/tools/ant/taskdefs/JarTest.java
  4. +3
    -9
      src/tests/junit/org/apache/tools/ant/taskdefs/XmlPropertyTest.java

+ 6
- 8
src/tests/junit/org/apache/tools/ant/IntrospectionHelperTest.java View File

@@ -267,13 +267,12 @@ public class IntrospectionHelperTest {
public void testGetNestedElementMap() { public void testGetNestedElementMap() {
Map<String, Class<?>> elemMap = getExpectedNestedElements(); Map<String, Class<?>> elemMap = getExpectedNestedElements();
Map<String, Class<?>> actualMap = ih.getNestedElementMap(); Map<String, Class<?>> actualMap = ih.getNestedElementMap();
for (Map.Entry<String, Class<?>> entry : actualMap.entrySet()) {
String elemName = entry.getKey();
actualMap.forEach((elemName, value) -> {
Class<?> elemClass = elemMap.get(elemName); Class<?> elemClass = elemMap.get(elemName);
assertNotNull("Support for " + elemName + " in IntrospectionHelperTest?", elemClass); assertNotNull("Support for " + elemName + " in IntrospectionHelperTest?", elemClass);
assertEquals("Type of " + elemName, elemClass, entry.getValue());
assertEquals("Type of " + elemName, elemClass, value);
elemMap.remove(elemName); elemMap.remove(elemName);
}
});
assertTrue("Found all", elemMap.isEmpty()); assertTrue("Found all", elemMap.isEmpty());


// Check it's a read-only map. // Check it's a read-only map.
@@ -607,13 +606,12 @@ public class IntrospectionHelperTest {
public void testGetAttributeMap() { public void testGetAttributeMap() {
Map<String, Class<?>> attrMap = getExpectedAttributes(); Map<String, Class<?>> attrMap = getExpectedAttributes();
Map<String, Class<?>> actualMap = ih.getAttributeMap(); Map<String, Class<?>> actualMap = ih.getAttributeMap();
for (Map.Entry<String, Class<?>> entry : actualMap.entrySet()) {
String attrName = entry.getKey();
actualMap.forEach((attrName, value) -> {
Class<?> attrClass = attrMap.get(attrName); Class<?> attrClass = attrMap.get(attrName);
assertNotNull("Support for " + attrName + " in IntrospectionHelperTest?", attrClass); assertNotNull("Support for " + attrName + " in IntrospectionHelperTest?", attrClass);
assertEquals("Type of " + attrName, attrClass, entry.getValue());
assertEquals("Type of " + attrName, attrClass, value);
attrMap.remove(attrName); attrMap.remove(attrName);
}
});
attrMap.remove("name"); attrMap.remove("name");
assertTrue("Found all", attrMap.isEmpty()); assertTrue("Found all", attrMap.isEmpty());




+ 2
- 6
src/tests/junit/org/apache/tools/ant/taskdefs/ExecuteWatchdogTest.java View File

@@ -20,6 +20,7 @@ package org.apache.tools.ant.taskdefs;


import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.util.stream.Collectors;


import org.apache.tools.ant.util.JavaEnvUtils; import org.apache.tools.ant.util.JavaEnvUtils;
import org.junit.Before; import org.junit.Before;
@@ -75,12 +76,7 @@ public class ExecuteWatchdogTest {


private String getErrorOutput(Process p) throws Exception { private String getErrorOutput(Process p) throws Exception {
BufferedReader err = new BufferedReader(new InputStreamReader(p.getErrorStream())); BufferedReader err = new BufferedReader(new InputStreamReader(p.getErrorStream()));
StringBuilder buf = new StringBuilder();
String line;
while ((line = err.readLine()) != null) {
buf.append(line);
}
return buf.toString();
return err.lines().collect(Collectors.joining());
} }


private int waitForEnd(Process p) throws Exception { private int waitForEnd(Process p) throws Exception {


+ 3
- 9
src/tests/junit/org/apache/tools/ant/taskdefs/JarTest.java View File

@@ -24,6 +24,7 @@ import java.io.FileReader;
import java.io.InputStream; import java.io.InputStream;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.io.IOException; import java.io.IOException;
import java.util.Collections;
import java.util.Enumeration; import java.util.Enumeration;
import java.util.zip.ZipEntry; import java.util.zip.ZipEntry;
import java.util.zip.ZipFile; import java.util.zip.ZipFile;
@@ -239,15 +240,8 @@ public class JarTest {
public void testNoDuplicateIndex() throws IOException { public void testNoDuplicateIndex() throws IOException {
buildRule.executeTarget("testIndexTests"); buildRule.executeTarget("testIndexTests");
try (ZipFile archive = new ZipFile(new File(getOutputDir(), tempJar))) { try (ZipFile archive = new ZipFile(new File(getOutputDir(), tempJar))) {
Enumeration<? extends ZipEntry> e = archive.entries();
int numberOfIndexLists = 0;
while (e.hasMoreElements()) {
ZipEntry ze = e.nextElement();
if (ze.getName().equals("META-INF/INDEX.LIST")) {
numberOfIndexLists++;
}
}
assertEquals(1, numberOfIndexLists);
assertEquals(1, (int) Collections.list(archive.entries()).stream()
.filter(ze -> ze.getName().equals("META-INF/INDEX.LIST")).count());
} }
} }




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

@@ -24,7 +24,6 @@ import java.io.FileInputStream;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Hashtable; import java.util.Hashtable;
import java.util.Map;
import java.util.List; import java.util.List;
import java.util.Properties; import java.util.Properties;


@@ -159,7 +158,6 @@ public class XmlPropertyTest {
workingDir = FILE_UTILS.resolveFile(new File("."), "."); workingDir = FILE_UTILS.resolveFile(new File("."), ".");
} }



File propertyFile = getGoldfile(inputFile, keepRoot, collapse, File propertyFile = getGoldfile(inputFile, keepRoot, collapse,
semantic, include, localRoot); semantic, include, localRoot);
if (!propertyFile.exists()) { if (!propertyFile.exists()) {
@@ -269,13 +267,9 @@ public class XmlPropertyTest {
*/ */
private static void ensureReferences(String msg, File inputFile, private static void ensureReferences(String msg, File inputFile,
Hashtable<String, Object> references) { Hashtable<String, Object> references) {
for (Map.Entry<String, Object> entry : references.entrySet()) {
String currentKey = entry.getKey();
Object currentValue = entry.getValue();
assertTrue(msg + "-" + inputFile.getName() + " Key=" + currentKey
+ " is not a recognized type.", currentValue instanceof Path
|| currentValue instanceof String || currentKey.startsWith("ant."));
}
references.forEach((key, value) -> assertTrue(msg + "-" + inputFile.getName()
+ " Key=" + key + " is not a recognized type.",
value instanceof Path || value instanceof String || key.startsWith("ant.")));
} }


/** /**


Loading…
Cancel
Save