Skip to content

Commit 0c7c3f8

Browse files
BoxTest: move put and get tests together for easier updating
1 parent a9483cb commit 0c7c3f8

File tree

1 file changed

+21
-21
lines changed
  • tests/objectbox-java-test/src/test/java/io/objectbox

1 file changed

+21
-21
lines changed

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

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -92,27 +92,6 @@ public void testPutAndGet() {
9292
assertArrayEquals(valByteArray, entity.getExternalId());
9393
}
9494

95-
// Note: There is a similar test using the Cursor API directly (which is deprecated) in CursorTest.
96-
@Test
97-
public void testPut_notAssignedId_fails() {
98-
TestEntity entity = new TestEntity();
99-
// Set ID that was not assigned
100-
entity.setId(1);
101-
IllegalArgumentException ex = assertThrows(IllegalArgumentException.class, () -> box.put(entity));
102-
assertEquals("ID is higher or equal to internal ID sequence: 1 (vs. 1). Use ID 0 (zero) to insert new objects.", ex.getMessage());
103-
}
104-
105-
@Test
106-
public void testPut_assignedId_inserts() {
107-
long id = box.put(new TestEntity());
108-
box.remove(id);
109-
// Put with previously assigned ID should insert
110-
TestEntity entity = new TestEntity();
111-
entity.setId(id);
112-
box.put(entity);
113-
assertEquals(1L, box.count());
114-
}
115-
11695
@Test
11796
public void testPutAndGet_defaultOrNullValues() {
11897
long id = box.put(new TestEntity());
@@ -145,6 +124,27 @@ public void testPutAndGet_defaultOrNullValues() {
145124
assertNull(defaultEntity.getExternalId());
146125
}
147126

127+
// Note: There is a similar test using the Cursor API directly (which is deprecated) in CursorTest.
128+
@Test
129+
public void testPut_notAssignedId_fails() {
130+
TestEntity entity = new TestEntity();
131+
// Set ID that was not assigned
132+
entity.setId(1);
133+
IllegalArgumentException ex = assertThrows(IllegalArgumentException.class, () -> box.put(entity));
134+
assertEquals("ID is higher or equal to internal ID sequence: 1 (vs. 1). Use ID 0 (zero) to insert new objects.", ex.getMessage());
135+
}
136+
137+
@Test
138+
public void testPut_assignedId_inserts() {
139+
long id = box.put(new TestEntity());
140+
box.remove(id);
141+
// Put with previously assigned ID should insert
142+
TestEntity entity = new TestEntity();
143+
entity.setId(id);
144+
box.put(entity);
145+
assertEquals(1L, box.count());
146+
}
147+
148148
@Test
149149
public void testPutStrings_withNull_ignoresNull() {
150150
final String[] stringArray = new String[]{"sunrise", null, "sunset"};

0 commit comments

Comments
 (0)