Skip to content

Commit fb52e15

Browse files
committed
Expand CursorIteratorTest coverage
1 parent 30b827c commit fb52e15

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

src/test/java/org/lmdbjava/CursorIteratorTest.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import java.nio.ByteBuffer;
2121
import static java.util.Arrays.asList;
2222
import java.util.LinkedList;
23+
import java.util.NoSuchElementException;
2324
import static org.hamcrest.CoreMatchers.is;
2425
import static org.hamcrest.MatcherAssert.assertThat;
2526
import org.junit.Before;
@@ -51,6 +52,7 @@ public void backward() {
5152
for (KeyVal<ByteBuffer> kv : c.iterable()) {
5253
assertThat(kv.val.getInt(), is(list.pollLast()));
5354
assertThat(kv.key.getInt(), is(list.pollLast()));
55+
assertThat(c.hasNext(), is(list.peekFirst() != null));
5456
}
5557
}
5658
}
@@ -93,6 +95,7 @@ public void forward() {
9395
for (KeyVal<ByteBuffer> kv : c.iterable()) {
9496
assertThat(kv.key.getInt(), is(list.pollFirst()));
9597
assertThat(kv.val.getInt(), is(list.pollFirst()));
98+
assertThat(c.hasNext(), is(list.peekFirst() != null));
9699
}
97100
}
98101
}
@@ -123,4 +126,25 @@ public void iterate() {
123126
}
124127
}
125128

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+
126150
}

0 commit comments

Comments
 (0)