Author: navssurtani
Date: 2008-06-26 10:57:18 -0400 (Thu, 26 Jun 2008)
New Revision: 6057
Modified:
searchable/trunk/src/test/java/org/jboss/cache/search/QueryResultIteratorImplTest.java
Log:
QueryResultIteratorImpl test written.
Modified:
searchable/trunk/src/test/java/org/jboss/cache/search/QueryResultIteratorImplTest.java
===================================================================
---
searchable/trunk/src/test/java/org/jboss/cache/search/QueryResultIteratorImplTest.java 2008-06-26
14:44:44 UTC (rev 6056)
+++
searchable/trunk/src/test/java/org/jboss/cache/search/QueryResultIteratorImplTest.java 2008-06-26
14:57:18 UTC (rev 6057)
@@ -24,7 +24,7 @@
QueryResultIterator iterator;
@BeforeMethod
- public void SetUp()
+ public void setUp()
{
// create a set of dummy cache entity IDs
ids = new ArrayList();
@@ -46,7 +46,7 @@
for (CacheEntityId id : ids)
{
// for each cache entity ID, create a dummy result that will be returned when
loading it.
- dummyResults.put(id, "Result number " + counter);
+ dummyResults.put(id, "Result number " + counter++);
}
// now create a dummy entity loader
@@ -63,94 +63,221 @@
iterator = null;
}
- public void jumpToResultTest(int index) throws IndexOutOfBoundsException
+ public void testJumpToResult() throws IndexOutOfBoundsException
{
- //To change body of implemented methods use File | Settings | File Templates.
+ iterator.jumpToResult(0);
+ assert iterator.isFirst();
+
+ iterator.jumpToResult(1);
+ assert iterator.isAfterFirst();
+
+ iterator.jumpToResult((ids.size() - 1));
+ assert iterator.isLast();
+
+ iterator.jumpToResult(ids.size() - 2);
+ assert iterator.isBeforeLast();
}
- public void firstTest()
+ public void testFirst()
{
- //To change body of implemented methods use File | Settings | File Templates.
+ assert iterator.isFirst() : "We should be pointing at the first
element";
+ Object next = iterator.next();
+ assert next == dummyResults.get(ids.get(0));
+ assert !iterator.isFirst();
+
+ iterator.first();
+
+ assert iterator.isFirst() : "We should be pointing at the first
element";
+ next = iterator.next();
+ assert next == dummyResults.get(ids.get(0));
+ assert !iterator.isFirst();
+
}
- public void lastTest()
+ public void testLast()
{
- //To change body of implemented methods use File | Settings | File Templates.
+ //Jumps to the last element
+ iterator.last();
+
+ //Makes sure that the iterator is pointing at the last element.
+ assert iterator.isLast();
+
+ //Iterator points at the previous element.
+ Object previous = iterator.previous();
+
+ //Returns the size of the list of ids.
+ int size = ids.size();
+
+ //Makes sure that previous is the last element.
+ assert previous == dummyResults.get(ids.get(size - 1));
+
+ //Check that the iterator is NOT pointing at the last element.
+ assert !iterator.isLast();
}
- public void afterFirstTest()
+ public void testAfterFirst()
{
- //To change body of implemented methods use File | Settings | File Templates.
+ //Jump to the second element.
+ iterator.afterFirst();
+
+ //Check this
+ assert iterator.isAfterFirst();
+
+ //Previous element in the list
+ Object previous = iterator.previous();
+
+ //Check that previous is the second element.
+ assert previous == dummyResults.get(ids.get(0));
+
+ //Make sure that the iterator isn't pointing at the second element.
+ assert !iterator.isAfterFirst();
+
}
- public void beforeLastTest()
+ public void testBeforeLast()
{
- //To change body of implemented methods use File | Settings | File Templates.
+ //Jump to the penultimate element.
+ iterator.beforeLast();
+
+ //Check this
+ assert iterator.isBeforeLast();
+
+ //Next element - which should be the last.
+ Object next = iterator.next();
+
+ //Check that next is the penultimate element.
+ int size = ids.size();
+ assert next == dummyResults.get(ids.get(size - 1));
+
+ //Make sure that the iterator is not pointing at the penultimate element.
+ assert !iterator.isAfterFirst();
}
- public boolean isFirstTest()
+ public void testIsFirst()
{
- return false; //To change body of implemented methods use File | Settings | File
Templates.
+ iterator.first();
+ assert iterator.isFirst();
+
+ iterator.next();
+ assert !iterator.isFirst();
}
- public boolean isLastTest()
+ public void testIsLast()
{
- return false; //To change body of implemented methods use File | Settings | File
Templates.
+ iterator.last();
+ assert iterator.isLast();
+
+ iterator.previous();
+ assert !iterator.isLast();
}
- public boolean isAfterFirstTest()
+ public void testIsAfterFirst()
{
- return false; //To change body of implemented methods use File | Settings | File
Templates.
+ iterator.afterFirst();
+ assert iterator.isAfterFirst();
+
+ iterator.previous();
+ assert !iterator.isAfterFirst();
}
- public boolean isBeforeLastTest()
+ public void testIsBeforeLast()
{
- return false; //To change body of implemented methods use File | Settings | File
Templates.
+ iterator.beforeLast();
+ assert iterator.isBeforeLast();
}
- public boolean hasNextTest()
+ public void testHasNext()
{
- return false; //To change body of implemented methods use File | Settings | File
Templates.
+ int size = ids.size();
+
+ if (size > 1)
+ {
+ iterator.first();
+ assert iterator.hasNext();
+
+ iterator.last();
+ assert !iterator.hasNext();
+
+ }
+
+ else
+ {
+ assert false;
+ }
+
}
- public Object nextTest()
+ public void testNext()
{
- return null; //To change body of implemented methods use File | Settings | File
Templates.
+ iterator.first();
+ if (iterator.hasNext())
+ {
+ iterator.next();
+
+ assert iterator.isAfterFirst();
+ assert !iterator.isFirst();
+ }
+
+ else
+ {
+ assert false;
+ }
}
- public boolean hasPreviousTest()
+ public void testHasPrevious()
{
- return false; //To change body of implemented methods use File | Settings | File
Templates.
+ int size = ids.size();
+
+ if (size > 1)
+ {
+ iterator.first();
+ assert !iterator.hasPrevious();
+
+ iterator.last();
+ assert iterator.hasPrevious();
+
+ }
+
+ else
+ {
+ assert false;
+ }
}
- public Object previousTest()
+ public void testPrevious()
{
- return null; //To change body of implemented methods use File | Settings | File
Templates.
- }
+ iterator.last();
+ if(iterator.hasPrevious())
+ {
+ iterator.previous();
+ assert iterator.isBeforeLast();
+ assert !iterator.isLast();
+
+ }
+ else
+ {
+ assert false;
+ }
- public int nextIndexTest()
- {
- return 0; //To change body of implemented methods use File | Settings | File
Templates.
}
- public int previousIndexTest()
+ public void testNextIndex()
{
- return 0; //To change body of implemented methods use File | Settings | File
Templates.
- }
+ iterator.first();
+ assert iterator.nextIndex() == 1;
- public void removeTest()
- {
- //To change body of implemented methods use File | Settings | File Templates.
+ iterator.last();
+ assert iterator.nextIndex() == ids.size();
+
}
- public void setTest(Object o)
+ public void previousIndexTest()
{
- //To change body of implemented methods use File | Settings | File Templates.
- }
+ iterator.first();
+ assert iterator.previousIndex() == -1;
- public void addTest(Object o)
- {
- //To change body of implemented methods use File | Settings | File Templates.
+ iterator.last();
+ assert iterator.previousIndex() == (ids.size() - 1);
}
public static class DummyEntityLoader extends CacheEntityLoader
Show replies by date