Browse Source

tests shouldn't pass if wrong part of test throws exception

master
Stefan Bodewig 7 years ago
parent
commit
fc1a841c0c
3 changed files with 47 additions and 6 deletions
  1. +7
    -2
      src/tests/junit/org/apache/tools/ant/taskdefs/optional/net/FTPTest.java
  2. +30
    -2
      src/tests/junit/org/apache/tools/ant/types/resources/LazyResourceCollectionTest.java
  3. +10
    -2
      src/tests/junit/org/apache/tools/ant/util/VectorSetTest.java

+ 7
- 2
src/tests/junit/org/apache/tools/ant/taskdefs/optional/net/FTPTest.java View File

@@ -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);
}
/**


+ 30
- 2
src/tests/junit/org/apache/tools/ant/types/resources/LazyResourceCollectionTest.java View File

@@ -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


+ 10
- 2
src/tests/junit/org/apache/tools/ant/util/VectorSetTest.java View File

@@ -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);
}



Loading…
Cancel
Save