tests shouldn't pass if wrong part of test throws exception
Project: http://git-wip-us.apache.org/repos/asf/ant/repo Commit: http://git-wip-us.apache.org/repos/asf/ant/commit/fc1a841c Tree: http://git-wip-us.apache.org/repos/asf/ant/tree/fc1a841c Diff: http://git-wip-us.apache.org/repos/asf/ant/diff/fc1a841c Branch: refs/heads/master Commit: fc1a841c0c96c07a7d8c733ded81b8c978b2e8f9 Parents: 1cf647b Author: Stefan Bodewig <bode...@apache.org> Authored: Mon Apr 23 12:05:05 2018 +0200 Committer: Stefan Bodewig <bode...@apache.org> Committed: Mon Apr 23 12:31:34 2018 +0200 ---------------------------------------------------------------------- .../ant/taskdefs/optional/net/FTPTest.java | 9 ++++-- .../resources/LazyResourceCollectionTest.java | 32 ++++++++++++++++++-- .../apache/tools/ant/util/VectorSetTest.java | 12 ++++++-- 3 files changed, 47 insertions(+), 6 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ant/blob/fc1a841c/src/tests/junit/org/apache/tools/ant/taskdefs/optional/net/FTPTest.java ---------------------------------------------------------------------- diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/net/FTPTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/net/FTPTest.java index 9104a40..3e552f2 100644 --- a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/net/FTPTest.java +++ b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/net/FTPTest.java @@ -611,10 +611,15 @@ public class FTPTest { performConfigTest("configuration.3", expectedCounts); } - @Test(expected = BuildException.class) - public void testConfigurationLang() { + @Test + public void testConfigurationGoodLang() { int[] expectedCounts = {1, 1, 0, 0, 0, 0, 1}; performConfigTest("configuration.lang.good", expectedCounts); + } + + @Test(expected = BuildException.class) + public void testConfigurationBadLang() { + int[] expectedCounts = {1, 1, 0, 0, 0, 0, 1}; performConfigTest("configuration.lang.bad", expectedCounts); } /** http://git-wip-us.apache.org/repos/asf/ant/blob/fc1a841c/src/tests/junit/org/apache/tools/ant/types/resources/LazyResourceCollectionTest.java ---------------------------------------------------------------------- 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 8cb20aa..9bfe0c8 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 @@ -75,7 +75,7 @@ public class LazyResourceCollectionTest { } } - @Test(expected = NoSuchElementException.class) + @Test public void testLazyLoading() { StringResourceCollection collectionTest = new StringResourceCollection(); LazyResourceCollectionWrapper lazyCollection = new LazyResourceCollectionWrapper(); @@ -101,7 +101,18 @@ public class LazyResourceCollectionTest { assertOneCreatedIterator(collectionTest); assertEquals("Iterating 3 times load more than 3 resources", 3, stringResourceIterator.cursor); + } + @Test(expected = NoSuchElementException.class) + public void testLazyLoadingFailsOnceWrappedCollectionIsExhausted() { + StringResourceCollection collectionTest = new StringResourceCollection(); + LazyResourceCollectionWrapper lazyCollection = new LazyResourceCollectionWrapper(); + lazyCollection.add(collectionTest); + + Iterator<Resource> it = lazyCollection.iterator(); + it.next(); + it.next(); + it.next(); it.next(); } @@ -111,7 +122,7 @@ public class LazyResourceCollectionTest { testCollection.createdIterators.size()); } - @Test(expected = NoSuchElementException.class) + @Test public void testCaching() { StringResourceCollection collectionTest = new StringResourceCollection(); LazyResourceCollectionWrapper lazyCollection = new LazyResourceCollectionWrapper(); @@ -153,6 +164,23 @@ public class LazyResourceCollectionTest { assertEquals( "The first iterator did not lookup in the cache for a resource", 3, stringResourceIterator.cursor); + } + + @Test(expected = NoSuchElementException.class) + public void testCachingFailsOnceWrappedCollectionIsExhausted() { + StringResourceCollection collectionTest = new StringResourceCollection(); + LazyResourceCollectionWrapper lazyCollection = new LazyResourceCollectionWrapper(); + lazyCollection.add(collectionTest); + + Iterator<Resource> it1 = lazyCollection.iterator(); + Iterator<Resource> it2 = lazyCollection.iterator(); + + it1.next(); + it2.next(); + it2.next(); + it1.next(); + it2.next(); + it1.next(); // next() must throw the expected NoSuchElementException; // if that does not happen, assertions throw the unexpected Assertion error http://git-wip-us.apache.org/repos/asf/ant/blob/fc1a841c/src/tests/junit/org/apache/tools/ant/util/VectorSetTest.java ---------------------------------------------------------------------- diff --git a/src/tests/junit/org/apache/tools/ant/util/VectorSetTest.java b/src/tests/junit/org/apache/tools/ant/util/VectorSetTest.java index 0785631..6eaf35c 100644 --- a/src/tests/junit/org/apache/tools/ant/util/VectorSetTest.java +++ b/src/tests/junit/org/apache/tools/ant/util/VectorSetTest.java @@ -107,11 +107,15 @@ public class VectorSetTest { assertEquals(1, v.size()); } - @Test(expected = ArrayIndexOutOfBoundsException.class) + @Test public void testRemoveIndex() { v.add(O); assertSame(O, v.remove(0)); assertEquals(0, v.size()); + } + + @Test(expected = ArrayIndexOutOfBoundsException.class) + public void testCantRemoveByIndexFromEmptySet() { v.remove(0); } @@ -197,11 +201,15 @@ public class VectorSetTest { assertFalse(v.removeElement(O)); } - @Test(expected = ArrayIndexOutOfBoundsException.class) + @Test public void testRemoveElementAt() { v.add(O); v.removeElementAt(0); assertEquals(0, v.size()); + } + + @Test(expected = ArrayIndexOutOfBoundsException.class) + public void testCantRemoveAtFromEmptySet() { v.removeElementAt(0); }