summaryrefslogtreecommitdiff
path: root/src/tests
diff options
context:
space:
mode:
authorMatt Benson <mbenson@apache.org>2017-04-13 10:15:22 -0500
committerMatt Benson <mbenson@apache.org>2017-04-13 10:15:22 -0500
commitb7d1e9bde44cb8e5233d6e70bb96e14cbb2f3e2d (patch)
treeee39db3a46b9da337a5f6424a74e578177a8d266 /src/tests
parentaf74d1f6b882cef5f4167d972638ad886d12d58c (diff)
downloadant-java8.tar.gz
java 5-8java8
Diffstat (limited to 'src/tests')
-rw-r--r--src/tests/junit/org/apache/tools/ant/taskdefs/ProtectedJarMethodsTest.java38
-rw-r--r--src/tests/junit/org/apache/tools/ant/types/resources/LazyResourceCollectionTest.java368
2 files changed, 201 insertions, 205 deletions
diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/ProtectedJarMethodsTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/ProtectedJarMethodsTest.java
index 27b3c8c8d..1d1a6706a 100644
--- a/src/tests/junit/org/apache/tools/ant/taskdefs/ProtectedJarMethodsTest.java
+++ b/src/tests/junit/org/apache/tools/ant/taskdefs/ProtectedJarMethodsTest.java
@@ -21,6 +21,7 @@ package org.apache.tools.ant.taskdefs;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
+import java.util.List;
import org.apache.tools.ant.BuildFileRule;
import org.junit.Before;
@@ -50,8 +51,8 @@ public class ProtectedJarMethodsTest {
public void testGrabFilesAndDirs() throws IOException {
buildRule.executeTarget("testIndexTests");
String archive = buildRule.getProject().getProperty(tempJar);
- ArrayList dirs = new ArrayList();
- ArrayList files = new ArrayList();
+ List<String> dirs = new ArrayList<>();
+ List<String> files = new ArrayList<>();
String[] expectedDirs = new String[] {
"META-INF/",
"sub/",
@@ -61,14 +62,14 @@ public class ProtectedJarMethodsTest {
};
Jar.grabFilesAndDirs(archive, dirs, files);
assertEquals(expectedDirs.length, dirs.size());
- for (int i = 0; i < expectedDirs.length; i++) {
- assertTrue("Found " + expectedDirs[i],
- dirs.contains(expectedDirs[i]));
+ for (String expectedDir : expectedDirs) {
+ assertTrue("Found " + expectedDir,
+ dirs.contains(expectedDir));
}
assertEquals(expectedFiles.length, files.size());
- for (int i = 0; i < expectedFiles.length; i++) {
- assertTrue("Found " + expectedFiles[i],
- files.contains(expectedFiles[i]));
+ for (String expectedFile : expectedFiles) {
+ assertTrue("Found " + expectedFile,
+ files.contains(expectedFile));
}
}
@@ -81,26 +82,23 @@ public class ProtectedJarMethodsTest {
@Test
public void testFindJarNameNoMatch() {
- assertNull(Jar.findJarName("foo", new String[] {"bar"}));
+ assertNull(Jar.findJarName("foo", new String[] { "bar" }));
}
@Test
public void testFindJarNameSimpleMatches() {
- assertEquals("foo", Jar.findJarName("foo", new String[] {"foo"}));
- assertEquals("lib/foo", Jar.findJarName("foo",
- new String[] {"lib/foo"}));
- assertEquals("foo", Jar.findJarName("bar" + File.separatorChar + "foo",
- new String[] {"foo"}));
+ assertEquals("foo", Jar.findJarName("foo", new String[] { "foo" }));
assertEquals("lib/foo",
- Jar.findJarName("bar" + File.separatorChar + "foo",
- new String[] {"lib/foo"}));
+ Jar.findJarName("foo", new String[] { "lib/foo" }));
+ assertEquals("foo", Jar.findJarName("bar" + File.separatorChar + "foo",
+ new String[] { "foo" }));
+ assertEquals("lib/foo", Jar.findJarName(
+ "bar" + File.separatorChar + "foo", new String[] { "lib/foo" }));
}
@Test
public void testFindJarNameLongestMatchWins() {
- assertEquals("lib/foo",
- Jar.findJarName("lib/foo",
- new String[] {"foo", "lib/foo",
- "lib/bar/foo"}));
+ assertEquals("lib/foo", Jar.findJarName("lib/foo",
+ new String[] { "foo", "lib/foo", "lib/bar/foo" }));
}
}
diff --git a/src/tests/junit/org/apache/tools/ant/types/resources/LazyResourceCollectionTest.java b/src/tests/junit/org/apache/tools/ant/types/resources/LazyResourceCollectionTest.java
index bb85d81a1..34bcecdb3 100644
--- a/src/tests/junit/org/apache/tools/ant/types/resources/LazyResourceCollectionTest.java
+++ b/src/tests/junit/org/apache/tools/ant/types/resources/LazyResourceCollectionTest.java
@@ -1,186 +1,184 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-package org.apache.tools.ant.types.resources;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Iterator;
-import java.util.List;
-import java.util.NoSuchElementException;
-
-
-import org.apache.tools.ant.types.Resource;
-import org.apache.tools.ant.types.ResourceCollection;
-import org.junit.Test;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-
-public class LazyResourceCollectionTest {
-
- private class StringResourceCollection implements ResourceCollection {
- List resources = Arrays.<Resource>asList();
-
- List createdIterators = new ArrayList();
-
- public int size() {
- return resources.size();
- }
-
- public Iterator<Resource> iterator() {
- StringResourceIterator it = new StringResourceIterator();
- createdIterators.add(it);
- return it;
- }
-
- public boolean isFilesystemOnly() {
- return false;
- }
- }
-
- private class StringResourceIterator implements Iterator {
- int cursor = 0;
-
- public void remove() {
- throw new UnsupportedOperationException();
- }
-
- public Object next() {
- if (cursor < 3) {
- cursor++;
- return new StringResource("r" + cursor);
- }
- return null;
- }
-
- public boolean hasNext() {
- return cursor < 3;
- }
- }
-
- @Test
- public void testLazyLoading() throws Exception {
- StringResourceCollection collectionTest = new StringResourceCollection();
- LazyResourceCollectionWrapper lazyCollection = new LazyResourceCollectionWrapper();
- lazyCollection.add(collectionTest);
-
- Iterator<Resource> it = lazyCollection.iterator();
- assertOneCreatedIterator(collectionTest);
- StringResourceIterator stringResourceIterator = (StringResourceIterator) collectionTest.createdIterators
- .get(0);
- assertEquals("A resource was loaded without iterating", 1,
- stringResourceIterator.cursor);
-
- StringResource r = (StringResource) it.next();
- assertOneCreatedIterator(collectionTest);
- assertEquals("r1", r.getValue());
- assertEquals("Iterating once load more than 1 resource", 2,
- stringResourceIterator.cursor);
-
- r = (StringResource) it.next();
- assertOneCreatedIterator(collectionTest);
- assertEquals("r2", r.getValue());
- assertEquals("Iterating twice load more than 2 resources", 3,
- stringResourceIterator.cursor);
-
- r = (StringResource) it.next();
- assertOneCreatedIterator(collectionTest);
- assertEquals("r3", r.getValue());
- assertEquals("Iterating 3 times load more than 3 resources", 3,
- stringResourceIterator.cursor);
-
- try {
- it.next();
- fail("NoSuchElementException should have been raised");
- } catch (NoSuchElementException e) {
- // ok
- }
- }
-
- private void assertOneCreatedIterator(
- StringResourceCollection testCollection) {
- assertEquals("More than one iterator has been created", 1,
- testCollection.createdIterators.size());
- }
-
- @Test
- public void testCaching() throws Exception {
- StringResourceCollection collectionTest = new StringResourceCollection();
- LazyResourceCollectionWrapper lazyCollection = new LazyResourceCollectionWrapper();
- lazyCollection.add(collectionTest);
-
- assertTrue(lazyCollection.isCache());
- Iterator<Resource> it1 = lazyCollection.iterator();
- assertOneCreatedIterator(collectionTest);
- Iterator<Resource> it2 = lazyCollection.iterator();
- assertOneCreatedIterator(collectionTest);
-
- StringResourceIterator stringResourceIterator = (StringResourceIterator) collectionTest.createdIterators
- .get(0);
- assertEquals("A resource was loaded without iterating", 1,
- stringResourceIterator.cursor);
-
- StringResource r = (StringResource) it1.next();
- assertEquals("r1", r.getValue());
- assertEquals("Iterating once load more than 1 resource", 2,
- stringResourceIterator.cursor);
-
- r = (StringResource) it2.next();
- assertEquals("r1", r.getValue());
- assertEquals(
- "The second iterator did not lookup in the cache for a resource",
- 2, stringResourceIterator.cursor);
-
- r = (StringResource) it2.next();
- assertEquals("r2", r.getValue());
- assertEquals("Iterating twice load more than 2 resources", 3,
- stringResourceIterator.cursor);
-
- r = (StringResource) it1.next();
- assertEquals("r2", r.getValue());
- assertEquals(
- "The first iterator did not lookup in the cache for a resource",
- 3, stringResourceIterator.cursor);
-
- r = (StringResource) it2.next();
- assertEquals("r3", r.getValue());
- assertEquals("Iterating 3 times load more than 3 resources", 3,
- stringResourceIterator.cursor);
-
- r = (StringResource) it1.next();
- assertEquals("r3", r.getValue());
- assertEquals(
- "The first iterator did not lookup in the cache for a resource",
- 3, stringResourceIterator.cursor);
-
- try {
- it1.next();
- fail("NoSuchElementException should have been raised");
- } catch (NoSuchElementException e) {
- // ok
- }
-
- try {
- it2.next();
- fail("NoSuchElementException should have been raised");
- } catch (NoSuchElementException e) {
- // ok
- }
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.apache.tools.ant.types.resources;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.NoSuchElementException;
+
+
+import org.apache.tools.ant.types.Resource;
+import org.apache.tools.ant.types.ResourceCollection;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+public class LazyResourceCollectionTest {
+
+ private class StringResourceCollection implements ResourceCollection {
+ List<StringResourceIterator> createdIterators = new ArrayList<>();
+
+ @Override
+ public int size() {
+ return 3;
+ }
+
+ @Override
+ public Iterator<Resource> iterator() {
+ StringResourceIterator it = new StringResourceIterator();
+ createdIterators.add(it);
+ return it;
+ }
+
+ @Override
+ public boolean isFilesystemOnly() {
+ return false;
+ }
+ }
+
+ private class StringResourceIterator implements Iterator<Resource> {
+ int cursor = 0;
+
+ @Override
+ public void remove() {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public StringResource next() {
+ if (cursor < 3) {
+ cursor++;
+ return new StringResource("r" + cursor);
+ }
+ return null;
+ }
+
+ @Override
+ public boolean hasNext() {
+ return cursor < 3;
+ }
+ }
+
+ @Test
+ public void testLazyLoading() throws Exception {
+ StringResourceCollection collectionTest = new StringResourceCollection();
+ LazyResourceCollectionWrapper lazyCollection = new LazyResourceCollectionWrapper();
+ lazyCollection.add(collectionTest);
+
+ Iterator<Resource> it = lazyCollection.iterator();
+ assertOneCreatedIterator(collectionTest);
+ StringResourceIterator stringResourceIterator =
+ collectionTest.createdIterators.get(0);
+ assertEquals("A resource was loaded without iterating", 1,
+ stringResourceIterator.cursor);
+
+ assertStringValue("r1", it.next());
+ assertOneCreatedIterator(collectionTest);
+ assertEquals("Iterating once load more than 1 resource", 2,
+ stringResourceIterator.cursor);
+
+ assertStringValue("r2", it.next());
+ assertOneCreatedIterator(collectionTest);
+ assertEquals("Iterating twice load more than 2 resources", 3,
+ stringResourceIterator.cursor);
+
+ assertStringValue("r3", it.next());
+ assertOneCreatedIterator(collectionTest);
+ assertEquals("Iterating 3 times load more than 3 resources", 3,
+ stringResourceIterator.cursor);
+
+ try {
+ it.next();
+ fail("NoSuchElementException should have been raised");
+ } catch (NoSuchElementException e) {
+ // ok
+ }
+ }
+
+ private void assertOneCreatedIterator(
+ StringResourceCollection testCollection) {
+ assertEquals("More than one iterator has been created", 1,
+ testCollection.createdIterators.size());
+ }
+
+ @Test
+ public void testCaching() throws Exception {
+ StringResourceCollection collectionTest = new StringResourceCollection();
+ LazyResourceCollectionWrapper lazyCollection = new LazyResourceCollectionWrapper();
+ lazyCollection.add(collectionTest);
+
+ assertTrue(lazyCollection.isCache());
+ Iterator<Resource> it1 = lazyCollection.iterator();
+ assertOneCreatedIterator(collectionTest);
+ Iterator<Resource> it2 = lazyCollection.iterator();
+ assertOneCreatedIterator(collectionTest);
+
+ StringResourceIterator stringResourceIterator =
+ collectionTest.createdIterators.get(0);
+ assertEquals("A resource was loaded without iterating", 1,
+ stringResourceIterator.cursor);
+
+ assertStringValue("r1", it1.next());
+ assertEquals("Iterating once load more than 1 resource", 2,
+ stringResourceIterator.cursor);
+
+ assertStringValue("r1", it2.next());
+ assertEquals(
+ "The second iterator did not lookup in the cache for a resource", 2,
+ stringResourceIterator.cursor);
+
+ assertStringValue("r2", it2.next());
+ assertEquals("Iterating twice load more than 2 resources", 3,
+ stringResourceIterator.cursor);
+
+ assertStringValue("r2", it1.next());
+ assertEquals(
+ "The first iterator did not lookup in the cache for a resource", 3,
+ stringResourceIterator.cursor);
+
+ assertStringValue("r3", it2.next());
+ assertEquals("Iterating 3 times load more than 3 resources", 3,
+ stringResourceIterator.cursor);
+
+ assertStringValue("r3", it1.next());
+ assertEquals(
+ "The first iterator did not lookup in the cache for a resource", 3,
+ stringResourceIterator.cursor);
+
+ try {
+ it1.next();
+ fail("NoSuchElementException should have been raised");
+ } catch (NoSuchElementException e) {
+ // ok
+ }
+
+ try {
+ it2.next();
+ fail("NoSuchElementException should have been raised");
+ } catch (NoSuchElementException e) {
+ // ok
+ }
+ }
+
+ private void assertStringValue(String expected, Resource r) {
+ assertEquals(expected, r.as(StringResource.class).getValue());
}
-}
+}