From 86b7bd05e5e839f7d70296065f4373098e44669a Mon Sep 17 00:00:00 2001 From: "Brian S. O'Neill" Date: Tue, 19 Sep 2006 06:22:33 +0000 Subject: Added SingletonCursor. --- .../com/amazon/carbonado/cursor/TestCursors.java | 39 ++++++++++++++++++++++ 1 file changed, 39 insertions(+) (limited to 'src/test/java') diff --git a/src/test/java/com/amazon/carbonado/cursor/TestCursors.java b/src/test/java/com/amazon/carbonado/cursor/TestCursors.java index f063a59..fa5d8a7 100644 --- a/src/test/java/com/amazon/carbonado/cursor/TestCursors.java +++ b/src/test/java/com/amazon/carbonado/cursor/TestCursors.java @@ -20,6 +20,8 @@ package com.amazon.carbonado.cursor; import java.util.Arrays; import java.util.Comparator; +import java.util.List; +import java.util.NoSuchElementException; import junit.framework.TestCase; import junit.framework.TestSuite; @@ -53,6 +55,43 @@ public class TestCursors extends TestCase { protected void tearDown() { } + public void testSingleton() throws Exception { + try { + new SingletonCursor(null); + fail(); + } catch (IllegalArgumentException e) { + } + + Cursor cursor = new SingletonCursor("hello"); + + assertTrue(cursor.hasNext()); + assertEquals("hello", cursor.next()); + assertFalse(cursor.hasNext()); + try { + cursor.next(); + fail(); + } catch (NoSuchElementException e) { + } + + assertEquals(0, cursor.skipNext(1)); + + cursor = new SingletonCursor("world"); + List list = cursor.toList(0); + assertEquals(0, list.size()); + list = cursor.toList(10); + assertEquals(1, list.size()); + assertEquals("world", list.get(0)); + + cursor = new SingletonCursor("world"); + cursor.close(); + assertFalse(cursor.hasNext()); + + cursor = new SingletonCursor("world"); + assertEquals(1, cursor.skipNext(2)); + assertEquals(0, cursor.skipNext(1)); + assertFalse(cursor.hasNext()); + } + public void testUnion() throws Exception { Cursor left, right, union; -- cgit v1.2.3