|
20 | 20 | import java.nio.ByteBuffer; |
21 | 21 | import static java.util.Arrays.asList; |
22 | 22 | import java.util.LinkedList; |
| 23 | +import java.util.NoSuchElementException; |
23 | 24 | import static org.hamcrest.CoreMatchers.is; |
24 | 25 | import static org.hamcrest.MatcherAssert.assertThat; |
25 | 26 | import org.junit.Before; |
@@ -51,6 +52,7 @@ public void backward() { |
51 | 52 | for (KeyVal<ByteBuffer> kv : c.iterable()) { |
52 | 53 | assertThat(kv.val.getInt(), is(list.pollLast())); |
53 | 54 | assertThat(kv.key.getInt(), is(list.pollLast())); |
| 55 | + assertThat(c.hasNext(), is(list.peekFirst() != null)); |
54 | 56 | } |
55 | 57 | } |
56 | 58 | } |
@@ -93,6 +95,7 @@ public void forward() { |
93 | 95 | for (KeyVal<ByteBuffer> kv : c.iterable()) { |
94 | 96 | assertThat(kv.key.getInt(), is(list.pollFirst())); |
95 | 97 | assertThat(kv.val.getInt(), is(list.pollFirst())); |
| 98 | + assertThat(c.hasNext(), is(list.peekFirst() != null)); |
96 | 99 | } |
97 | 100 | } |
98 | 101 | } |
@@ -123,4 +126,25 @@ public void iterate() { |
123 | 126 | } |
124 | 127 | } |
125 | 128 |
|
| 129 | + @Test(expected = NoSuchElementException.class) |
| 130 | + public void nextThrowsNoSuchElementExceptionIfNoMoreElements() { |
| 131 | + try (final Txn<ByteBuffer> txn = env.txnRead(); |
| 132 | + CursorIterator<ByteBuffer> c = db.iterate(txn)) { |
| 133 | + for (KeyVal<ByteBuffer> kv : c.iterable()) { |
| 134 | + assertThat(kv.key.getInt(), is(list.pollFirst())); |
| 135 | + assertThat(kv.val.getInt(), is(list.pollFirst())); |
| 136 | + } |
| 137 | + assertThat(c.hasNext(), is(false)); |
| 138 | + c.next(); |
| 139 | + } |
| 140 | + } |
| 141 | + |
| 142 | + @Test(expected = UnsupportedOperationException.class) |
| 143 | + public void removeUnsupported() { |
| 144 | + try (final Txn<ByteBuffer> txn = env.txnRead(); |
| 145 | + CursorIterator<ByteBuffer> c = db.iterate(txn)) { |
| 146 | + c.remove(); |
| 147 | + } |
| 148 | + } |
| 149 | + |
126 | 150 | } |
0 commit comments