Skip to content

Commit 0216c92

Browse files
committed
Add more test coverage
1 parent 1312e10 commit 0216c92

File tree

7 files changed

+112
-39
lines changed

7 files changed

+112
-39
lines changed

src/test/java/org/lmdbjava/CopyFlagSetTest.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,15 +76,13 @@ Function<EnumSet<CopyFlags>, CopyFlagSet> getConstructor() {
7676
}
7777

7878
/**
79-
* {@link FlagSet#isSet(MaskedFlag)} on the flag enum is tested in {@link AbstractFlagSetTest} but the coverage check
80-
* doesn't seem to notice it.
79+
* {@link FlagSet#isSet(MaskedFlag)} on the flag enum is tested in {@link AbstractFlagSetTest} but
80+
* the coverage check doesn't seem to notice it.
8181
*/
8282
@Test
8383
void testIsSet() {
84-
assertThat(CopyFlags.MDB_CP_COMPACT.isSet(CopyFlags.MDB_CP_COMPACT))
85-
.isTrue();
84+
assertThat(CopyFlags.MDB_CP_COMPACT.isSet(CopyFlags.MDB_CP_COMPACT)).isTrue();
8685
//noinspection ConstantValue
87-
assertThat(CopyFlags.MDB_CP_COMPACT.isSet(null))
88-
.isFalse();
86+
assertThat(CopyFlags.MDB_CP_COMPACT.isSet(null)).isFalse();
8987
}
9088
}

src/test/java/org/lmdbjava/CursorDeprecatedTest.java

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ void cursorFirstLastNextPrev() {
138138
}
139139

140140
@Test
141-
void delete() {
141+
void delete1() {
142142
final Dbi<ByteBuffer> db = env.openDbi(DB_1, MDB_CREATE, MDB_DUPSORT);
143143
try (Txn<ByteBuffer> txn = env.txnWrite();
144144
Cursor<ByteBuffer> c = db.openCursor(txn)) {
@@ -147,11 +147,49 @@ void delete() {
147147
assertThat(c.seek(MDB_FIRST)).isTrue();
148148
assertThat(c.key().getInt()).isEqualTo(1);
149149
assertThat(c.val().getInt()).isEqualTo(2);
150-
c.delete();
150+
c.delete(new PutFlags[0]);
151151
assertThat(c.seek(MDB_FIRST)).isTrue();
152152
assertThat(c.key().getInt()).isEqualTo(3);
153153
assertThat(c.val().getInt()).isEqualTo(4);
154-
c.delete();
154+
c.delete(new PutFlags[0]);
155+
assertThat(c.seek(MDB_FIRST)).isFalse();
156+
}
157+
}
158+
159+
@Test
160+
void delete2() {
161+
final Dbi<ByteBuffer> db = env.openDbi(DB_1, MDB_CREATE, MDB_DUPSORT);
162+
try (Txn<ByteBuffer> txn = env.txnWrite();
163+
Cursor<ByteBuffer> c = db.openCursor(txn)) {
164+
c.put(bb(1), bb(2), MDB_NOOVERWRITE);
165+
c.put(bb(3), bb(4), new PutFlags[0]);
166+
assertThat(c.seek(MDB_FIRST)).isTrue();
167+
assertThat(c.key().getInt()).isEqualTo(1);
168+
assertThat(c.val().getInt()).isEqualTo(2);
169+
c.delete((PutFlags[]) null);
170+
assertThat(c.seek(MDB_FIRST)).isTrue();
171+
assertThat(c.key().getInt()).isEqualTo(3);
172+
assertThat(c.val().getInt()).isEqualTo(4);
173+
c.delete((PutFlags[]) null);
174+
assertThat(c.seek(MDB_FIRST)).isFalse();
175+
}
176+
}
177+
178+
@Test
179+
void delete3() {
180+
final Dbi<ByteBuffer> db = env.openDbi(DB_1, MDB_CREATE, MDB_DUPSORT);
181+
try (Txn<ByteBuffer> txn = env.txnWrite();
182+
Cursor<ByteBuffer> c = db.openCursor(txn)) {
183+
c.put(bb(1), bb(2), MDB_NOOVERWRITE);
184+
c.put(bb(3), bb(4), new PutFlags[0]);
185+
assertThat(c.seek(MDB_FIRST)).isTrue();
186+
assertThat(c.key().getInt()).isEqualTo(1);
187+
assertThat(c.val().getInt()).isEqualTo(2);
188+
c.delete((PutFlags) null);
189+
assertThat(c.seek(MDB_FIRST)).isTrue();
190+
assertThat(c.key().getInt()).isEqualTo(3);
191+
assertThat(c.val().getInt()).isEqualTo(4);
192+
c.delete((PutFlags) null);
155193
assertThat(c.seek(MDB_FIRST)).isFalse();
156194
}
157195
}

src/test/java/org/lmdbjava/CursorTest.java

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,54 @@ void delete() {
276276
}
277277
}
278278

279+
@Test
280+
void delete2() {
281+
final Dbi<ByteBuffer> db =
282+
env.createDbi()
283+
.setDbName(DB_1)
284+
.withDefaultComparator()
285+
.setDbiFlags(MDB_CREATE, MDB_DUPSORT)
286+
.open();
287+
try (Txn<ByteBuffer> txn = env.txnWrite();
288+
Cursor<ByteBuffer> c = db.openCursor(txn)) {
289+
c.put(bb(1), bb(2), MDB_NOOVERWRITE);
290+
c.put(bb(3), bb(4));
291+
assertThat(c.seek(MDB_FIRST)).isTrue();
292+
assertThat(c.key().getInt()).isEqualTo(1);
293+
assertThat(c.val().getInt()).isEqualTo(2);
294+
c.delete(PutFlags.EMPTY);
295+
assertThat(c.seek(MDB_FIRST)).isTrue();
296+
assertThat(c.key().getInt()).isEqualTo(3);
297+
assertThat(c.val().getInt()).isEqualTo(4);
298+
c.delete(PutFlags.EMPTY);
299+
assertThat(c.seek(MDB_FIRST)).isFalse();
300+
}
301+
}
302+
303+
@Test
304+
void delete3() {
305+
final Dbi<ByteBuffer> db =
306+
env.createDbi()
307+
.setDbName(DB_1)
308+
.withDefaultComparator()
309+
.setDbiFlags(MDB_CREATE, MDB_DUPSORT)
310+
.open();
311+
try (Txn<ByteBuffer> txn = env.txnWrite();
312+
Cursor<ByteBuffer> c = db.openCursor(txn)) {
313+
c.put(bb(1), bb(2), MDB_NOOVERWRITE);
314+
c.put(bb(3), bb(4));
315+
assertThat(c.seek(MDB_FIRST)).isTrue();
316+
assertThat(c.key().getInt()).isEqualTo(1);
317+
assertThat(c.val().getInt()).isEqualTo(2);
318+
c.delete((PutFlagSet) null);
319+
assertThat(c.seek(MDB_FIRST)).isTrue();
320+
assertThat(c.key().getInt()).isEqualTo(3);
321+
assertThat(c.val().getInt()).isEqualTo(4);
322+
c.delete((PutFlagSet) null);
323+
assertThat(c.seek(MDB_FIRST)).isFalse();
324+
}
325+
}
326+
279327
@Test
280328
void getKeyVal() {
281329
final Dbi<ByteBuffer> db =

src/test/java/org/lmdbjava/DbiFlagSetTest.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -76,17 +76,14 @@ Function<EnumSet<DbiFlags>, DbiFlagSet> getConstructor() {
7676
}
7777

7878
/**
79-
* {@link FlagSet#isSet(MaskedFlag)} on the flag enum is tested in {@link AbstractFlagSetTest} but the coverage check
80-
* doesn't seem to notice it.
79+
* {@link FlagSet#isSet(MaskedFlag)} on the flag enum is tested in {@link AbstractFlagSetTest} but
80+
* the coverage check doesn't seem to notice it.
8181
*/
8282
@Test
8383
void testIsSet() {
84-
assertThat(DbiFlags.MDB_CREATE.isSet(DbiFlags.MDB_CREATE))
85-
.isTrue();
86-
assertThat(DbiFlags.MDB_CREATE.isSet(DbiFlags.MDB_REVERSEKEY))
87-
.isFalse();
84+
assertThat(DbiFlags.MDB_CREATE.isSet(DbiFlags.MDB_CREATE)).isTrue();
85+
assertThat(DbiFlags.MDB_CREATE.isSet(DbiFlags.MDB_REVERSEKEY)).isFalse();
8886
//noinspection ConstantValue
89-
assertThat(DbiFlags.MDB_CREATE.isSet(null))
90-
.isFalse();
87+
assertThat(DbiFlags.MDB_CREATE.isSet(null)).isFalse();
9188
}
9289
}

src/test/java/org/lmdbjava/EnvFlagSetTest.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -76,17 +76,14 @@ Function<EnumSet<EnvFlags>, EnvFlagSet> getConstructor() {
7676
}
7777

7878
/**
79-
* {@link FlagSet#isSet(MaskedFlag)} on the flag enum is tested in {@link AbstractFlagSetTest} but the coverage check
80-
* doesn't seem to notice it.
79+
* {@link FlagSet#isSet(MaskedFlag)} on the flag enum is tested in {@link AbstractFlagSetTest} but
80+
* the coverage check doesn't seem to notice it.
8181
*/
8282
@Test
8383
void testIsSet() {
84-
assertThat(EnvFlags.MDB_RDONLY_ENV.isSet(EnvFlags.MDB_RDONLY_ENV))
85-
.isTrue();
86-
assertThat(EnvFlags.MDB_RDONLY_ENV.isSet(EnvFlags.MDB_WRITEMAP))
87-
.isFalse();
84+
assertThat(EnvFlags.MDB_RDONLY_ENV.isSet(EnvFlags.MDB_RDONLY_ENV)).isTrue();
85+
assertThat(EnvFlags.MDB_RDONLY_ENV.isSet(EnvFlags.MDB_WRITEMAP)).isFalse();
8886
//noinspection ConstantValue
89-
assertThat(EnvFlags.MDB_RDONLY_ENV.isSet(null))
90-
.isFalse();
87+
assertThat(EnvFlags.MDB_RDONLY_ENV.isSet(null)).isFalse();
9188
}
9289
}

src/test/java/org/lmdbjava/PutFlagSetTest.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -79,18 +79,15 @@ Function<EnumSet<PutFlags>, PutFlagSet> getConstructor() {
7979
}
8080

8181
/**
82-
* {@link FlagSet#isSet(MaskedFlag)} on the flag enum is tested in {@link AbstractFlagSetTest} but the coverage check
83-
* doesn't seem to notice it.
82+
* {@link FlagSet#isSet(MaskedFlag)} on the flag enum is tested in {@link AbstractFlagSetTest} but
83+
* the coverage check doesn't seem to notice it.
8484
*/
8585
@Test
8686
void testIsSet() {
87-
assertThat(PutFlags.MDB_APPEND.isSet(PutFlags.MDB_APPEND))
88-
.isTrue();
89-
assertThat(PutFlags.MDB_APPEND.isSet(PutFlags.MDB_MULTIPLE))
90-
.isFalse();
87+
assertThat(PutFlags.MDB_APPEND.isSet(PutFlags.MDB_APPEND)).isTrue();
88+
assertThat(PutFlags.MDB_APPEND.isSet(PutFlags.MDB_MULTIPLE)).isFalse();
9189
//noinspection ConstantValue
92-
assertThat(PutFlags.MDB_APPEND.isSet(null))
93-
.isFalse();
90+
assertThat(PutFlags.MDB_APPEND.isSet(null)).isFalse();
9491
}
9592

9693
@Test

src/test/java/org/lmdbjava/TxnFlagSetTest.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,15 +76,13 @@ Function<EnumSet<TxnFlags>, TxnFlagSet> getConstructor() {
7676
}
7777

7878
/**
79-
* {@link FlagSet#isSet(MaskedFlag)} on the flag enum is tested in {@link AbstractFlagSetTest} but the coverage check
80-
* doesn't seem to notice it.
79+
* {@link FlagSet#isSet(MaskedFlag)} on the flag enum is tested in {@link AbstractFlagSetTest} but
80+
* the coverage check doesn't seem to notice it.
8181
*/
8282
@Test
8383
void testIsSet() {
84-
assertThat(MDB_RDONLY_TXN.isSet(MDB_RDONLY_TXN))
85-
.isTrue();
84+
assertThat(MDB_RDONLY_TXN.isSet(MDB_RDONLY_TXN)).isTrue();
8685
//noinspection ConstantValue
87-
assertThat(MDB_RDONLY_TXN.isSet(null))
88-
.isFalse();
86+
assertThat(MDB_RDONLY_TXN.isSet(null)).isFalse();
8987
}
9088
}

0 commit comments

Comments
 (0)