[Japi-cvs] SF.net SVN: japi:[753] libs/util/trunk/src/tst/test/net/sf/japi/util/ EnumerationIterato
Status: Beta
Brought to you by:
christianhujer
|
From: <chr...@us...> - 2008-12-28 23:25:52
|
Revision: 753
http://japi.svn.sourceforge.net/japi/?rev=753&view=rev
Author: christianhujer
Date: 2008-12-28 23:25:49 +0000 (Sun, 28 Dec 2008)
Log Message:
-----------
Improved UnitTest for EnumerationIterator.
Modified Paths:
--------------
libs/util/trunk/src/tst/test/net/sf/japi/util/EnumerationIteratorTest.java
Modified: libs/util/trunk/src/tst/test/net/sf/japi/util/EnumerationIteratorTest.java
===================================================================
--- libs/util/trunk/src/tst/test/net/sf/japi/util/EnumerationIteratorTest.java 2008-12-28 21:50:19 UTC (rev 752)
+++ libs/util/trunk/src/tst/test/net/sf/japi/util/EnumerationIteratorTest.java 2008-12-28 23:25:49 UTC (rev 753)
@@ -23,6 +23,7 @@
import java.util.Arrays;
import java.util.Collections;
+import java.util.Iterator;
import java.util.NoSuchElementException;
import net.sf.japi.util.EnumerationIterator;
import org.junit.Assert;
@@ -33,68 +34,77 @@
*/
public class EnumerationIteratorTest {
- /** Test case for {@link EnumerationIterator#iterator()}.
- * @throws Exception (unexpected).
- */
+ /** Test case for {@link EnumerationIterator#iterator()}. */
@Test
- public void testIterator() throws Exception {
- EnumerationIterator<?> oUT = new EnumerationIterator<String>(Collections.enumeration(Arrays.asList("foo", "bar")));
+ public void testIteratorEmptyList() {
+ final Iterable<?> oUT = new EnumerationIterator<Object>(Collections.enumeration(Arrays.asList()));
Assert.assertNotNull("Even empty enumerations must generate an iterator instance.", oUT.iterator());
- oUT = new EnumerationIterator<Object>(Collections.enumeration(Arrays.asList()));
+ }
+
+ /** Test case for {@link EnumerationIterator#iterator()}. */
+ @Test
+ public void testIteratorTwoElements() {
+ final Iterable<?> oUT = new EnumerationIterator<String>(Collections.enumeration(Arrays.asList("foo", "bar")));
Assert.assertNotNull("Even empty enumerations must generate an iterator instance.", oUT.iterator());
}
- /** Test case for {@link EnumerationIterator#hasNext()}.
- * @throws Exception (unexpected).
- */
- @Test public void testHasNext() throws Exception {
- EnumerationIterator<?> oUT = new EnumerationIterator<Object>(Collections.enumeration(Arrays.asList()));
+ /** Test case for {@link EnumerationIterator#hasNext()}. */
+ @Test public void testHasNextEmpty() {
+ final Iterator<?> oUT = new EnumerationIterator<Object>(Collections.enumeration(Arrays.asList()));
Assert.assertFalse("hasNext() on empty enumeration must instantly return false.", oUT.hasNext());
- oUT = new EnumerationIterator<String>(Collections.enumeration(Arrays.asList("foo", "bar")));
+ }
+
+ /** Test case for {@link EnumerationIterator#hasNext()}. */
+ @Test public void testHasNextTwoElements() {
+ final Iterator<?> oUT = new EnumerationIterator<String>(Collections.enumeration(Arrays.asList("foo", "bar")));
Assert.assertTrue("hasNext() on nonempty enumeration must first return true.", oUT.hasNext());
}
/** Test case for {@link EnumerationIterator#next()}.
- * @throws Exception (unexpected).
+ * @throws NoSuchElementException (expected).
*/
- @Test public void testNext() throws Exception {
- EnumerationIterator<?> oUT = new EnumerationIterator<Object>(Collections.enumeration(Arrays.asList()));
+ @Test(expected = NoSuchElementException.class)
+ public void testNextEmpty() throws NoSuchElementException {
+ final Iterator<?> oUT = new EnumerationIterator<Object>(Collections.enumeration(Arrays.asList()));
+ oUT.next();
+ }
+
+ /** Test case for {@link EnumerationIterator#next()}.
+ * @throws NoSuchElementException (expected).
+ */
+ @Test(expected = NoSuchElementException.class)
+ public void testNextTwoElements() throws NoSuchElementException {
+ final Iterator<?> oUT = new EnumerationIterator<String>(Collections.enumeration(Arrays.asList("foo", "bar")));
try {
oUT.next();
- Assert.fail("next() on empty enumeration must instantly throw NoSuchElementException.");
+ oUT.next();
} catch (final NoSuchElementException ignore) {
- /* Expected exception. */
+ Assert.fail("next() on two elements enumeration must not throw NoSuchElementException before third invocation.");
}
- oUT = new EnumerationIterator<String>(Collections.enumeration(Arrays.asList("foo", "bar")));
oUT.next();
- oUT.next();
- try {
- oUT.next();
- Assert.fail("next() on two elements enumeration must throw NoSuchElementException on third invocation.");
- } catch (final NoSuchElementException ignore) {
- /* Expected exception. */
- }
}
/** Test case for {@link EnumerationIterator#remove()}.
- * @throws Exception (unexpected).
+ * @throws UnsupportedOperationException (unexpected).
*/
- @Test public void testRemove() throws Exception {
- EnumerationIterator<?> oUT = new EnumerationIterator<Object>(Collections.enumeration(Arrays.asList()));
+ @Test(expected = UnsupportedOperationException.class)
+ public void testRemoveEmpty() throws UnsupportedOperationException {
+ final Iterator<?> oUT = new EnumerationIterator<Object>(Collections.enumeration(Arrays.asList()));
+ oUT.remove();
+ }
+
+ /** Test case for {@link EnumerationIterator#remove()}.
+ * @throws UnsupportedOperationException (unexpected).
+ */
+ @Test(expected = UnsupportedOperationException.class)
+ public void testRemoveTwoElements() throws UnsupportedOperationException {
+ final Iterator<?> oUT = new EnumerationIterator<String>(Collections.enumeration(Arrays.asList("foo", "bar")));
try {
- oUT.remove();
- Assert.fail("remove() on empty enumeration must instantly throw UnsupportedOperationException.");
- } catch (final UnsupportedOperationException ignore) {
- /* Expected exception. */
- }
- oUT = new EnumerationIterator<String>(Collections.enumeration(Arrays.asList("foo", "bar")));
- try {
oUT.next();
- oUT.remove();
- Assert.fail("remove() must throw UnsupportedOperationException.");
} catch (final UnsupportedOperationException ignore) {
- /* Expected exception. */
+ Assert.fail("Unexpected UnsupportedOperationException.");
}
+ oUT.remove();
}
} // class EnumerationIteratorTest
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|