[Japi-cvs] SF.net SVN: japi: [118] trunk/src/test/net/sf/japi/util
Status: Beta
Brought to you by:
christianhujer
From: <chr...@us...> - 2006-05-25 23:58:21
|
Revision: 118 Author: christianhujer Date: 2006-05-25 16:58:03 -0700 (Thu, 25 May 2006) ViewCVS: http://svn.sourceforge.net/japi/?rev=118&view=rev Log Message: ----------- Moved Tests from Daimonin / Gridarta to JAPI. Modified Paths: -------------- trunk/src/test/net/sf/japi/util/EnumerationIteratorTest.java Added Paths: ----------- trunk/src/test/net/sf/japi/util/NodeListIteratorTest.java trunk/src/test/net/sf/japi/util/PairTest.java trunk/src/test/net/sf/japi/util/TableTest.java trunk/src/test/net/sf/japi/util/UtilTest.java Modified: trunk/src/test/net/sf/japi/util/EnumerationIteratorTest.java =================================================================== --- trunk/src/test/net/sf/japi/util/EnumerationIteratorTest.java 2006-05-25 23:53:53 UTC (rev 117) +++ trunk/src/test/net/sf/japi/util/EnumerationIteratorTest.java 2006-05-25 23:58:03 UTC (rev 118) @@ -18,6 +18,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA * 02111-1307, USA. */ + package test.net.sf.japi.util; import java.util.Arrays; Added: trunk/src/test/net/sf/japi/util/NodeListIteratorTest.java =================================================================== --- trunk/src/test/net/sf/japi/util/NodeListIteratorTest.java (rev 0) +++ trunk/src/test/net/sf/japi/util/NodeListIteratorTest.java 2006-05-25 23:58:03 UTC (rev 118) @@ -0,0 +1,110 @@ +/* + * 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.Iterator; +import java.util.NoSuchElementException; +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import junit.framework.TestCase; +import net.sf.japi.xml.NodeListIterator; +import org.w3c.dom.Document; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; + +/** Test class for {@link NodeListIterator}. + * @author <a href="mailto:ch...@it...">Christian Hujer</a> + */ +public class NodeListIteratorTest extends TestCase { + + /** Object Under Test: A NodeListIterator. */ + private NodeListIterator<Node> oUT; + + /** Mock NodeList. */ + private NodeList mockNodeList; + + /** {@inheritDoc} */ + @Override public void setUp() throws Exception { + super.setUp(); + mockNodeList = createMockNodeList(); + oUT = new NodeListIterator<Node>(mockNodeList); + } + + /** {@inheritDoc} */ + @Override public void tearDown() throws Exception { + super.tearDown(); + oUT = null; + } + + /** Test case for {@link NodeListIterator#iterator()}. */ + public void testIterator() throws Exception { + final Iterator<Node> iterator = oUT.iterator(); + assertNotNull("Iterator must exist", iterator); + } + + /** Test case for {@link net.sf.japi.util.NodeListIterator#hasNext()}. */ + public void testHasNext() throws Exception { + for (int i = 0; i < mockNodeList.getLength(); i++) { + assertTrue("Iterator must return as many elements as the underlying NodeList has.", oUT.hasNext()); + oUT.next(); + } + assertFalse("Iterator must not return more elements than the underlying NodeList.", oUT.hasNext()); + } + + /** Test case for {@link NodeListIterator#next()}. */ + public void testNext() throws Exception { + for (int i = 0; i < mockNodeList.getLength(); i++) { + assertSame("Iterator must return Nodes in original NodeList order.", oUT.next(), mockNodeList.item(i)); + } + try { + oUT.next(); + fail("Iterator must throw NoSuchElementException if invoking next() more often than available Nodes."); + } catch (final NoSuchElementException e) { + /* ignore, this exception is expected to occur. */ + } + } + + /** Test case for {@link NodeListIterator#remove()}. */ + public void testRemove() throws Exception { + try { + oUT.remove(); + fail("NodeListIterator.remove() is expected to always throw UnsupportedOperationException."); + } catch (final UnsupportedOperationException e) { + /* ignore, this exception is expected to occur. */ + } + } + + /** Create a mock NodeList. + * @return a mock NodeList + * @throws Exception in case the test setup couldn't be created + */ + private static NodeList createMockNodeList() throws Exception { + final DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); + final DocumentBuilder db = dbf.newDocumentBuilder(); + final Document doc = db.newDocument(); + doc.appendChild(doc.createComment("bla")); + doc.appendChild(doc.createElement("bla")); + doc.appendChild(doc.createComment("bla")); + return doc.getChildNodes(); + } + +} // class NodeListIteratorTest Property changes on: trunk/src/test/net/sf/japi/util/NodeListIteratorTest.java ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:eol-style + LF Added: trunk/src/test/net/sf/japi/util/PairTest.java =================================================================== --- trunk/src/test/net/sf/japi/util/PairTest.java (rev 0) +++ trunk/src/test/net/sf/japi/util/PairTest.java 2006-05-25 23:58:03 UTC (rev 118) @@ -0,0 +1,77 @@ +/* + * 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 junit.framework.TestCase; +import net.sf.japi.util.Pair; + +/** Test class for {@link Pair}. + * @author <a href="mailto:ch...@it...">Christian Hujer</a> + */ +public class PairTest extends TestCase { + + /** Object Under Test: A Table. */ + private Pair<Object,Object> oUT; + private String first; + private String second; + + /** {@inheritDoc} */ + @Override protected void setUp() throws Exception { + super.setUp(); + first = "First"; + second = "Second"; + oUT = new Pair<Object,Object>(first, second); + } + + /** {@inheritDoc} */ + @Override protected void tearDown() throws Exception { + super.tearDown(); + oUT = null; + first = null; + second = null; + } + + /** Test case for {@link Pair#getFirst()}. */ + public void testGetFirst() throws Exception { + assertSame("First must be retreivable via getFirst()", first, oUT.getFirst()); + } + + /** Test case for {@link Pair#getSecond()}. */ + public void testGetSecond() throws Exception { + assertSame("First must be retreivable via getSecond()", second, oUT.getSecond()); + } + + /** Test case for {@link Pair#Pair(Object,Object)}. */ + public void testPair() throws Exception { + assertTrue("Dummy assertion.", true); + // This test is already implicitly performed by #setUp(). + } + + /** Test case for {@link Pair#equals(Object)}. */ + public void testEquals() throws Exception { + assertFalse("A pair must not be equal to random objects.", oUT.equals(new Object())); + assertTrue("A pair must be equal to itself", oUT.equals(oUT)); + assertTrue("A pair must be equal to another pair with same first and second", oUT.equals(new Pair<Object,Object>(first, second))); + assertTrue("A pair must be equal to another pair with equal first and second", oUT.equals(new Pair<Object,Object>(new String(first.toCharArray()), new String(second.toCharArray())))); + } + +} // class PairTest Property changes on: trunk/src/test/net/sf/japi/util/PairTest.java ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:eol-style + LF Added: trunk/src/test/net/sf/japi/util/TableTest.java =================================================================== --- trunk/src/test/net/sf/japi/util/TableTest.java (rev 0) +++ trunk/src/test/net/sf/japi/util/TableTest.java 2006-05-25 23:58:03 UTC (rev 118) @@ -0,0 +1,90 @@ +/* + * 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 junit.framework.TestCase; +import net.sf.japi.util.Pair; +import net.sf.japi.util.Table; + +/** Test class for Table. + * @author <a href="mailto:ch...@it...">Christian Hujer</a> + */ +public class TableTest extends TestCase { + + /** Object Under Test: A Table. */ + private Table<Object,Object> oUT; + + /** {@inheritDoc} */ + @Override public void setUp() throws Exception { + super.setUp(); + oUT = new Table<Object,Object>(); + } + + /** {@inheritDoc} */ + @Override protected void tearDown() throws Exception { + super.tearDown(); + oUT = null; + } + + /** Test case for creating an empty table. */ + public void testTable() { + assertEquals("Newly created table must be empty.", 0, oUT.size()); + } + + /** Test case for clearing a table. */ + public void testClear() throws Exception { + oUT.putPair(new Object(), new Object()); + assertSize("Added 1 Element", 1); + oUT.clear(); + assertSize("Cleared", 0); + oUT.putPair(new Object(), new Object()); + assertSize("Added 1 Element", 1); + oUT.putPair(new Object(), new Object()); + assertSize("Added 2 Elements", 2); + oUT.putPair(new Object(), new Object()); + assertSize("Added 3 Elements", 3); + oUT.clear(); + assertSize("Cleared", 0); + } + + /** Test case for putPair() methods. */ + public void testPutPair() { + final String key1 = "key1"; + final Object value1 = "value1"; + oUT.putPair(key1, value1); + assertSize("Added 1 Element", 1); + final String key2 = "key2"; + final Object value2 = "value2"; + oUT.putPair(new Pair<Object,Object>(key2, value2)); + assertSize("Added 2 Elements", 2); + // TODO: Get pairs and compare... + } + + /** Assert that the table (oUT) has a certain size. + * @param reason Reason why the size is expected + * @param size Expected size + */ + private void assertSize(final String reason, final int size) { + assertEquals("Expected size " + size + " (Reason: " + reason + ')', size, oUT.size()); + } + +} // class TableTest Property changes on: trunk/src/test/net/sf/japi/util/TableTest.java ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:eol-style + LF Added: trunk/src/test/net/sf/japi/util/UtilTest.java =================================================================== --- trunk/src/test/net/sf/japi/util/UtilTest.java (rev 0) +++ trunk/src/test/net/sf/japi/util/UtilTest.java 2006-05-25 23:58:03 UTC (rev 118) @@ -0,0 +1,56 @@ +/* + * 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 junit.framework.TestCase; +import net.sf.japi.util.Arrays2; + +/** + * Test for {@link Arrays2}. + * @author <a href="mailto:ch...@it...">Christian Hujer</a> + */ +public class UtilTest extends TestCase { + + /** {@inheritDoc} */ + @Override + public void setUp() throws Exception { + super.setUp(); + } + + /** {@inheritDoc} */ + @Override + public void tearDown() throws Exception { + super.tearDown(); + } + + /** Test case for {@link Arrays2#linearSearch(int, int[])}. */ + public void testLinearSearch() throws Exception { + final int[] data = { 0, 1, 2, 3 }; + assertEquals(-1, Arrays2.linearSearch(-1, data)); + assertEquals( 0, Arrays2.linearSearch( 0, data)); + assertEquals( 1, Arrays2.linearSearch( 1, data)); + assertEquals( 2, Arrays2.linearSearch( 2, data)); + assertEquals( 3, Arrays2.linearSearch( 3, data)); + assertEquals(-1, Arrays2.linearSearch( 4, data)); + } + +} // class UtilTest Property changes on: trunk/src/test/net/sf/japi/util/UtilTest.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. |