[Japi-cvs] SF.net SVN: japi: [117] trunk/src/test/net/sf/japi/util/EnumerationIteratorTest.java
Status: Beta
Brought to you by:
christianhujer
|
From: <chr...@us...> - 2006-05-25 23:54:04
|
Revision: 117 Author: christianhujer Date: 2006-05-25 16:53:53 -0700 (Thu, 25 May 2006) ViewCVS: http://svn.sourceforge.net/japi/?rev=117&view=rev Log Message: ----------- Added Unit Test for EnumerationIterator (copied from Gridarta / Daimonin). Added Paths: ----------- trunk/src/test/net/sf/japi/util/EnumerationIteratorTest.java Added: trunk/src/test/net/sf/japi/util/EnumerationIteratorTest.java =================================================================== --- trunk/src/test/net/sf/japi/util/EnumerationIteratorTest.java (rev 0) +++ trunk/src/test/net/sf/japi/util/EnumerationIteratorTest.java 2006-05-25 23:53:53 UTC (rev 117) @@ -0,0 +1,99 @@ +/* + * JAPI - (Yet another (hopefully) useful) Java API + * + * Copyright (C) 2006 Christian Hujer + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA + * 02111-1307, USA. + */ +package test.net.sf.japi.util; + +import java.util.Arrays; +import java.util.Collections; +import java.util.NoSuchElementException; +import junit.framework.TestCase; +import net.sf.japi.util.EnumerationIterator; + +/** Test class for {@link EnumerationIterator}. + * @author <a href="mailto:ch...@it...">Christian Hujer</a> + */ +public class EnumerationIteratorTest extends TestCase { + + /** {@inheritDoc} */ + @Override public void setUp() throws Exception { + super.setUp(); + } + + /** {@inheritDoc} */ + @Override public void tearDown() throws Exception { + super.tearDown(); + } + + /** Test case for {@link EnumerationIterator#iterator()}. */ + public void testIterator() throws Exception { + EnumerationIterator<?> oUT = new EnumerationIterator<String>(Collections.enumeration(Arrays.asList("foo", "bar"))); + assertNotNull("Even empty enumerations must generate an iterator instance.", oUT.iterator()); + oUT = new EnumerationIterator<Object>(Collections.enumeration(Arrays.asList())); + assertNotNull("Even empty enumerations must generate an iterator instance.", oUT.iterator()); + } + + /** Test case for {@link EnumerationIterator#hasNext()}. */ + public void testHasNext() throws Exception { + EnumerationIterator<?> oUT = new EnumerationIterator<Object>(Collections.enumeration(Arrays.asList())); + assertFalse("hasNext() on empty enumeration must instantly return false.", oUT.hasNext()); + oUT = new EnumerationIterator<String>(Collections.enumeration(Arrays.asList("foo", "bar"))); + assertTrue("hasNext() on nonempty enumeration must first return true.", oUT.hasNext()); + } + + /** Test case for {@link EnumerationIterator#next()}. */ + public void testNext() throws Exception { + EnumerationIterator<?> oUT = new EnumerationIterator<Object>(Collections.enumeration(Arrays.asList())); + try { + oUT.next(); + fail("next() on empty enumeration must instantly throw NoSuchElementException."); + } catch (final NoSuchElementException e) { + /* Expected exception. */ + } + oUT = new EnumerationIterator<String>(Collections.enumeration(Arrays.asList("foo", "bar"))); + oUT.next(); + oUT.next(); + try { + oUT.next(); + fail("next() on two elements enumeration must throw NoSuchElementException on third invocation."); + } catch (final NoSuchElementException e) { + /* Expected exception. */ + } + } + + /** Test case for {@link EnumerationIterator#remove()}. */ + public void testRemove() throws Exception { + EnumerationIterator<?> oUT = new EnumerationIterator<Object>(Collections.enumeration(Arrays.asList())); + try { + oUT.remove(); + fail("remove() on empty enumeration must instantly throw UnsupportedOperationException."); + } catch (final UnsupportedOperationException e) { + /* Expected exception. */ + } + oUT = new EnumerationIterator<String>(Collections.enumeration(Arrays.asList("foo", "bar"))); + try { + oUT.next(); + oUT.remove(); + fail("remove() must throw UnsupportedOperationException."); + } catch (final UnsupportedOperationException e) { + /* Expected exception. */ + } + } + +} // class EnumerationIteratorTest Property changes on: trunk/src/test/net/sf/japi/util/EnumerationIteratorTest.java ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:eol-style + LF This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |