Skip to content

Commit 873115b

Browse files
Merge branch 'property-find-tests' into dev
2 parents 49cc45e + 2ee6d2c commit 873115b

File tree

1 file changed

+88
-1
lines changed

1 file changed

+88
-1
lines changed

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

Lines changed: 88 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,88 @@ public void testFindInt_uniqueFails() {
221221
box.query().build().property(simpleInt).unique().findInt();
222222
}
223223

224+
@Test
225+
public void testFindShort() {
226+
Query<TestEntity> query = box.query().greater(simpleLong, 1002).build();
227+
assertNull(query.property(simpleShort).findShort());
228+
assertNull(query.property(simpleShort).unique().findShort());
229+
230+
putTestEntities(5);
231+
assertEquals(103, (short) query.property(simpleShort).findShort());
232+
233+
query = box.query().greater(simpleLong, 1004).build();
234+
assertEquals(105, (short) query.property(simpleShort).distinct().unique().findShort());
235+
}
236+
237+
@Test(expected = DbException.class)
238+
public void testFindShort_uniqueFails() {
239+
putTestEntity(null, 1);
240+
putTestEntity(null, 1);
241+
box.query().build().property(simpleShort).unique().findShort();
242+
}
243+
244+
// TODO add test for findChar
245+
246+
@Test
247+
public void testFindByte() {
248+
Query<TestEntity> query = box.query().greater(simpleLong, 1002).build();
249+
assertNull(query.property(simpleByte).findByte());
250+
assertNull(query.property(simpleByte).unique().findByte());
251+
252+
putTestEntities(5);
253+
assertEquals((byte) 13, (byte) query.property(simpleByte).findByte());
254+
255+
query = box.query().greater(simpleLong, 1004).build();
256+
assertEquals((byte) 15, (byte) query.property(simpleByte).distinct().unique().findByte());
257+
}
258+
259+
@Test(expected = DbException.class)
260+
public void testFindByte_uniqueFails() {
261+
putTestEntity(null, 1);
262+
putTestEntity(null, 1);
263+
box.query().build().property(simpleByte).unique().findByte();
264+
}
265+
266+
@Test
267+
public void testFindBoolean() {
268+
Query<TestEntity> query = box.query().greater(simpleLong, 1002).build();
269+
assertNull(query.property(simpleBoolean).findBoolean());
270+
assertNull(query.property(simpleBoolean).unique().findBoolean());
271+
272+
putTestEntities(5);
273+
assertFalse(query.property(simpleBoolean).findBoolean());
274+
275+
query = box.query().greater(simpleLong, 1004).build();
276+
assertFalse(query.property(simpleBoolean).distinct().unique().findBoolean());
277+
}
278+
279+
@Test(expected = DbException.class)
280+
public void testFindBoolean_uniqueFails() {
281+
putTestEntity(null, 1);
282+
putTestEntity(null, 1);
283+
box.query().build().property(simpleBoolean).unique().findBoolean();
284+
}
285+
286+
@Test
287+
public void testFindFloat() {
288+
Query<TestEntity> query = box.query().greater(simpleLong, 1002).build();
289+
assertNull(query.property(simpleFloat).findFloat());
290+
assertNull(query.property(simpleFloat).unique().findFloat());
291+
292+
putTestEntities(5);
293+
assertEquals(200.3f, query.property(simpleFloat).findFloat(), 0.001f);
294+
295+
query = box.query().greater(simpleLong, 1004).build();
296+
assertEquals(200.5f, query.property(simpleFloat).distinct().unique().findFloat(), 0.001f);
297+
}
298+
299+
@Test(expected = DbException.class)
300+
public void testFindFloat_uniqueFails() {
301+
putTestEntity(null, 1);
302+
putTestEntity(null, 1);
303+
box.query().build().property(simpleFloat).unique().findFloat();
304+
}
305+
224306
@Test
225307
public void testFindDouble() {
226308
Query<TestEntity> query = box.query().greater(simpleLong, 1002).build();
@@ -233,7 +315,12 @@ public void testFindDouble() {
233315
assertEquals(2000.05, query.property(simpleDouble).distinct().unique().findDouble(), 0.001);
234316
}
235317

236-
// TODO add test for other types of single object find methods
318+
@Test(expected = DbException.class)
319+
public void testFindDouble_uniqueFails() {
320+
putTestEntity(null, 1);
321+
putTestEntity(null, 1);
322+
box.query().build().property(simpleDouble).unique().findDouble();
323+
}
237324

238325
@Test
239326
public void testFindInts() {

0 commit comments

Comments
 (0)