Skip to content

Commit 2be1723

Browse files
committed
add some null related tests
1 parent 7f13af5 commit 2be1723

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

tests/objectbox-java-test/src/main/java/io/objectbox/query/PropertyQueryTest.java

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,7 @@
3333
import io.objectbox.query.QueryBuilder.StringOrder;
3434

3535
import static io.objectbox.TestEntity_.*;
36-
import static org.junit.Assert.assertEquals;
37-
import static org.junit.Assert.assertTrue;
36+
import static org.junit.Assert.*;
3837

3938
public class PropertyQueryTest extends AbstractObjectBoxTest {
4039

@@ -151,8 +150,10 @@ public void testFindLongs() {
151150

152151
@Test
153152
public void testFindLong() {
154-
putTestEntities(5);
155153
Query<TestEntity> query = box.query().greater(simpleLong, 1002).build();
154+
assertNull(query.property(simpleLong).findFirstLong());
155+
assertNull(query.property(simpleLong).findUniqueLong());
156+
putTestEntities(5);
156157
long result = query.property(simpleLong).findFirstLong();
157158
assertEquals(1003, result);
158159

@@ -169,13 +170,24 @@ public void testFindLong_uniqueFails() {
169170

170171
@Test
171172
public void testFindInt() {
172-
putTestEntities(5);
173173
Query<TestEntity> query = box.query().greater(simpleLong, 1002).build();
174-
long result = query.property(simpleInt).findFirstInt();
174+
assertNull(query.property(simpleInt).findFirstInt());
175+
assertNull(query.property(simpleInt).findUniqueInt());
176+
putTestEntities(5);
177+
int result = query.property(simpleInt).findFirstInt();
175178
assertEquals(3, result);
176179

177180
query = box.query().greater(simpleLong, 1004).build();
178-
assertEquals(5, (long) query.property(simpleInt).distinct().findUniqueInt());
181+
assertEquals(5, (int) query.property(simpleInt).distinct().findUniqueInt());
182+
183+
TestEntityCursor.INT_NULL_HACK = true;
184+
try {
185+
putTestEntity(null, 6);
186+
} finally {
187+
TestEntityCursor.INT_NULL_HACK = false;
188+
}
189+
query.setParameter(simpleLong, 1005);
190+
assertEquals(-99, (int) query.property(simpleInt).nullValue(-99).findUniqueInt());
179191
}
180192

181193
@Test(expected = DbException.class)
@@ -185,6 +197,8 @@ public void testFindInt_uniqueFails() {
185197
box.query().build().property(simpleInt).findUniqueInt();
186198
}
187199

200+
// TODO add test for other types of single object find methods
201+
188202
@Test
189203
public void testFindInts() {
190204
putTestEntities(5);

0 commit comments

Comments
 (0)