Skip to content

Commit 8bd4a79

Browse files
CursorTest: assert put with invalid ID error message.
1 parent 448bb63 commit 8bd4a79

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

tests/objectbox-java-test/src/test/java/io/objectbox/CursorTest.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,20 @@ public void testPutAndGetEntity() {
4949
transaction.abort();
5050
}
5151

52-
@Test(expected = IllegalArgumentException.class)
52+
@Test
5353
public void testPutEntityWithInvalidId() {
5454
TestEntity entity = new TestEntity();
5555
entity.setId(777);
5656
Transaction transaction = store.beginTx();
5757
Cursor<TestEntity> cursor = transaction.createCursor(TestEntity.class);
58+
5859
try {
59-
cursor.put(entity);
60+
IllegalArgumentException ex = assertThrows(IllegalArgumentException.class,
61+
() -> cursor.put(entity));
62+
assertEquals(ex.getMessage(), "ID is higher or equal to internal ID sequence: 777 (vs. 1)." +
63+
" Use ID 0 (zero) to insert new entities.");
6064
} finally {
65+
// Always clean up, even if assertions fail, to avoid misleading clean-up errors.
6166
cursor.close();
6267
transaction.close();
6368
}

0 commit comments

Comments
 (0)