Skip to content

Commit 26ccc3e

Browse files
Boolean arrays: update TestEntity, put and get test from integ tests #265
1 parent a15933c commit 26ccc3e

File tree

8 files changed

+93
-56
lines changed

8 files changed

+93
-56
lines changed

tests/objectbox-java-test/src/main/java/io/objectbox/TestEntity.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2017-2024 ObjectBox Ltd. All rights reserved.
2+
* Copyright 2017-2025 ObjectBox Ltd. All rights reserved.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -68,6 +68,7 @@ public class TestEntity {
6868
private long simpleLongU;
6969
private Map<String, Object> stringObjectMap;
7070
private Object flexProperty;
71+
private boolean[] booleanArray;
7172
private short[] shortArray;
7273
private char[] charArray;
7374
private int[] intArray;
@@ -106,6 +107,7 @@ public TestEntity(long id,
106107
long simpleLongU,
107108
Map<String, Object> stringObjectMap,
108109
Object flexProperty,
110+
boolean[] booleanArray,
109111
short[] shortArray,
110112
char[] charArray,
111113
int[] intArray,
@@ -132,6 +134,7 @@ public TestEntity(long id,
132134
this.simpleLongU = simpleLongU;
133135
this.stringObjectMap = stringObjectMap;
134136
this.flexProperty = flexProperty;
137+
this.booleanArray = booleanArray;
135138
this.shortArray = shortArray;
136139
this.charArray = charArray;
137140
this.intArray = intArray;
@@ -293,6 +296,16 @@ public TestEntity setFlexProperty(@Nullable Object flexProperty) {
293296
return this;
294297
}
295298

299+
@Nullable
300+
public boolean[] getBooleanArray() {
301+
return booleanArray;
302+
}
303+
304+
public TestEntity setBooleanArray(@Nullable boolean[] booleanArray) {
305+
this.booleanArray = booleanArray;
306+
return this;
307+
}
308+
296309
@Nullable
297310
public short[] getShortArray() {
298311
return shortArray;
@@ -386,6 +399,7 @@ public String toString() {
386399
", simpleLongU=" + simpleLongU +
387400
", stringObjectMap=" + stringObjectMap +
388401
", flexProperty=" + flexProperty +
402+
", booleanArray=" + Arrays.toString(booleanArray) +
389403
", shortArray=" + Arrays.toString(shortArray) +
390404
", charArray=" + Arrays.toString(charArray) +
391405
", intArray=" + Arrays.toString(intArray) +

tests/objectbox-java-test/src/main/java/io/objectbox/TestEntityCursor.java

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2017-2024 ObjectBox Ltd. All rights reserved.
2+
* Copyright 2017-2025 ObjectBox Ltd. All rights reserved.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -66,6 +66,7 @@ public Cursor<TestEntity> createCursor(io.objectbox.Transaction tx, long cursorH
6666
private final static int __ID_simpleLongU = TestEntity_.simpleLongU.id;
6767
private final static int __ID_stringObjectMap = TestEntity_.stringObjectMap.id;
6868
private final static int __ID_flexProperty = TestEntity_.flexProperty.id;
69+
private final static int __ID_booleanArray = TestEntity_.booleanArray.id;
6970
private final static int __ID_shortArray = TestEntity_.shortArray.id;
7071
private final static int __ID_charArray = TestEntity_.charArray.id;
7172
private final static int __ID_intArray = TestEntity_.intArray.id;
@@ -92,41 +93,47 @@ public long getId(TestEntity entity) {
9293
@SuppressWarnings({"rawtypes", "unchecked"})
9394
@Override
9495
public long put(TestEntity entity) {
96+
boolean[] booleanArray = entity.getBooleanArray();
97+
int __id17 = booleanArray != null ? __ID_booleanArray : 0;
98+
99+
collectBooleanArray(cursor, 0, PUT_FLAG_FIRST,
100+
__id17, booleanArray);
101+
95102
short[] shortArray = entity.getShortArray();
96-
int __id17 = shortArray != null ? __ID_shortArray : 0;
103+
int __id18 = shortArray != null ? __ID_shortArray : 0;
97104

98-
collectShortArray(cursor, 0, PUT_FLAG_FIRST,
99-
__id17, shortArray);
105+
collectShortArray(cursor, 0, 0,
106+
__id18, shortArray);
100107

101108
char[] charArray = entity.getCharArray();
102-
int __id18 = charArray != null ? __ID_charArray : 0;
109+
int __id19 = charArray != null ? __ID_charArray : 0;
103110

104111
collectCharArray(cursor, 0, 0,
105-
__id18, charArray);
112+
__id19, charArray);
106113

107114
int[] intArray = entity.getIntArray();
108-
int __id19 = intArray != null ? __ID_intArray : 0;
115+
int __id20 = intArray != null ? __ID_intArray : 0;
109116

110117
collectIntArray(cursor, 0, 0,
111-
__id19, intArray);
118+
__id20, intArray);
112119

113120
long[] longArray = entity.getLongArray();
114-
int __id20 = longArray != null ? __ID_longArray : 0;
121+
int __id21 = longArray != null ? __ID_longArray : 0;
115122

116123
collectLongArray(cursor, 0, 0,
117-
__id20, longArray);
124+
__id21, longArray);
118125

119126
float[] floatArray = entity.getFloatArray();
120-
int __id21 = floatArray != null ? __ID_floatArray : 0;
127+
int __id22 = floatArray != null ? __ID_floatArray : 0;
121128

122129
collectFloatArray(cursor, 0, 0,
123-
__id21, floatArray);
130+
__id22, floatArray);
124131

125132
double[] doubleArray = entity.getDoubleArray();
126-
int __id22 = doubleArray != null ? __ID_doubleArray : 0;
133+
int __id23 = doubleArray != null ? __ID_doubleArray : 0;
127134

128135
collectDoubleArray(cursor, 0, 0,
129-
__id22, doubleArray);
136+
__id23, doubleArray);
130137

131138
String[] simpleStringArray = entity.getSimpleStringArray();
132139
int __id10 = simpleStringArray != null ? __ID_simpleStringArray : 0;
@@ -145,26 +152,26 @@ public long put(TestEntity entity) {
145152
byte[] simpleByteArray = entity.getSimpleByteArray();
146153
int __id9 = simpleByteArray != null ? __ID_simpleByteArray : 0;
147154
byte[] externalId = entity.getExternalId();
148-
int __id24 = externalId != null ? __ID_externalId : 0;
155+
int __id25 = externalId != null ? __ID_externalId : 0;
149156
Map stringObjectMap = entity.getStringObjectMap();
150157
int __id15 = stringObjectMap != null ? __ID_stringObjectMap : 0;
151158

152159
collect430000(cursor, 0, 0,
153160
__id8, simpleString, 0, null,
154161
0, null, 0, null,
155-
__id9, simpleByteArray, __id24, externalId,
162+
__id9, simpleByteArray, __id25, externalId,
156163
__id15, __id15 != 0 ? stringObjectMapConverter.convertToDatabaseValue(stringObjectMap) : null);
157164

158165
Object flexProperty = entity.getFlexProperty();
159166
int __id16 = flexProperty != null ? __ID_flexProperty : 0;
160167
java.util.Date date = entity.getDate();
161-
int __id23 = date != null ? __ID_date : 0;
168+
int __id24 = date != null ? __ID_date : 0;
162169

163170
collect313311(cursor, 0, 0,
164171
0, null, 0, null,
165172
0, null, __id16, __id16 != 0 ? flexPropertyConverter.convertToDatabaseValue(flexProperty) : null,
166173
__ID_simpleLong, entity.getSimpleLong(), __ID_simpleLongU, entity.getSimpleLongU(),
167-
__id23, __id23 != 0 ? date.getTime() : 0, INT_NULL_HACK ? 0 : __ID_simpleInt, entity.getSimpleInt(),
174+
__id24, __id24 != 0 ? date.getTime() : 0, INT_NULL_HACK ? 0 : __ID_simpleInt, entity.getSimpleInt(),
168175
__ID_simpleIntU, entity.getSimpleIntU(), __ID_simpleShort, entity.getSimpleShort(),
169176
__ID_simpleFloat, entity.getSimpleFloat(), __ID_simpleDouble, entity.getSimpleDouble());
170177

tests/objectbox-java-test/src/main/java/io/objectbox/TestEntity_.java

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2017-2024 ObjectBox Ltd. All rights reserved.
2+
* Copyright 2017-2025 ObjectBox Ltd. All rights reserved.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -103,29 +103,32 @@ public final class TestEntity_ implements EntityInfo<TestEntity> {
103103
public final static io.objectbox.Property<TestEntity> flexProperty =
104104
new io.objectbox.Property<>(__INSTANCE, 16, 17, byte[].class, "flexProperty", false, "flexProperty", FlexObjectConverter.class, Object.class);
105105

106+
public final static io.objectbox.Property<TestEntity> booleanArray =
107+
new io.objectbox.Property<>(__INSTANCE, 17, 26, boolean[].class, "booleanArray");
108+
106109
public final static io.objectbox.Property<TestEntity> shortArray =
107-
new io.objectbox.Property<>(__INSTANCE, 17, 18, short[].class, "shortArray");
110+
new io.objectbox.Property<>(__INSTANCE, 18, 18, short[].class, "shortArray");
108111

109112
public final static io.objectbox.Property<TestEntity> charArray =
110-
new io.objectbox.Property<>(__INSTANCE, 18, 19, char[].class, "charArray");
113+
new io.objectbox.Property<>(__INSTANCE, 19, 19, char[].class, "charArray");
111114

112115
public final static io.objectbox.Property<TestEntity> intArray =
113-
new io.objectbox.Property<>(__INSTANCE, 19, 20, int[].class, "intArray");
116+
new io.objectbox.Property<>(__INSTANCE, 20, 20, int[].class, "intArray");
114117

115118
public final static io.objectbox.Property<TestEntity> longArray =
116-
new io.objectbox.Property<>(__INSTANCE, 20, 21, long[].class, "longArray");
119+
new io.objectbox.Property<>(__INSTANCE, 21, 21, long[].class, "longArray");
117120

118121
public final static io.objectbox.Property<TestEntity> floatArray =
119-
new io.objectbox.Property<>(__INSTANCE, 21, 22, float[].class, "floatArray");
122+
new io.objectbox.Property<>(__INSTANCE, 22, 22, float[].class, "floatArray");
120123

121124
public final static io.objectbox.Property<TestEntity> doubleArray =
122-
new io.objectbox.Property<>(__INSTANCE, 22, 23, double[].class, "doubleArray");
125+
new io.objectbox.Property<>(__INSTANCE, 23, 23, double[].class, "doubleArray");
123126

124127
public final static io.objectbox.Property<TestEntity> date =
125-
new io.objectbox.Property<>(__INSTANCE, 23, 24, java.util.Date.class, "date");
128+
new io.objectbox.Property<>(__INSTANCE, 24, 24, java.util.Date.class, "date");
126129

127130
public final static io.objectbox.Property<TestEntity> externalId =
128-
new io.objectbox.Property<>(__INSTANCE, 24, 25, byte[].class, "externalId");
131+
new io.objectbox.Property<>(__INSTANCE, 25, 25, byte[].class, "externalId");
129132

130133
@SuppressWarnings("unchecked")
131134
public final static io.objectbox.Property<TestEntity>[] __ALL_PROPERTIES = new io.objectbox.Property[]{
@@ -146,6 +149,7 @@ public final class TestEntity_ implements EntityInfo<TestEntity> {
146149
simpleLongU,
147150
stringObjectMap,
148151
flexProperty,
152+
booleanArray,
149153
shortArray,
150154
charArray,
151155
intArray,

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

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2017-2024 ObjectBox Ltd. All rights reserved.
2+
* Copyright 2017-2025 ObjectBox Ltd. All rights reserved.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -294,6 +294,7 @@ private void addTestEntity(ModelBuilder modelBuilder, @Nullable IndexType simple
294294
entityBuilder.property("flexProperty", PropertyType.Flex).id(TestEntity_.flexProperty.id, ++lastUid);
295295

296296
// Integer and floating point arrays
297+
entityBuilder.property("booleanArray", PropertyType.BoolVector).id(TestEntity_.booleanArray.id, ++lastUid);
297298
entityBuilder.property("shortArray", PropertyType.ShortVector).id(TestEntity_.shortArray.id, ++lastUid);
298299
entityBuilder.property("charArray", PropertyType.CharVector).id(TestEntity_.charArray.id, ++lastUid);
299300
entityBuilder.property("intArray", PropertyType.IntVector).id(TestEntity_.intArray.id, ++lastUid);
@@ -336,38 +337,46 @@ private void addTestEntityMinimal(ModelBuilder modelBuilder, boolean withIndex)
336337
}
337338

338339
protected TestEntity createTestEntity(@Nullable String simpleString, int nr) {
340+
boolean simpleBoolean = nr % 2 == 0;
341+
short simpleShort = (short) (100 + nr);
342+
int simpleLong = 1000 + nr;
343+
float simpleFloat = 200 + nr / 10f;
344+
double simpleDouble = 2000 + nr / 100f;
345+
byte[] simpleByteArray = {1, 2, (byte) nr};
346+
String[] simpleStringArray = {simpleString};
347+
339348
TestEntity entity = new TestEntity();
340349
entity.setSimpleString(simpleString);
341350
entity.setSimpleInt(nr);
342351
entity.setSimpleByte((byte) (10 + nr));
343-
entity.setSimpleBoolean(nr % 2 == 0);
344-
entity.setSimpleShort((short) (100 + nr));
345-
entity.setSimpleLong(1000 + nr);
346-
entity.setSimpleFloat(200 + nr / 10f);
347-
entity.setSimpleDouble(2000 + nr / 100f);
348-
entity.setSimpleByteArray(new byte[]{1, 2, (byte) nr});
349-
String[] stringArray = {simpleString};
350-
entity.setSimpleStringArray(stringArray);
351-
entity.setSimpleStringList(Arrays.asList(stringArray));
352-
entity.setSimpleShortU((short) (100 + nr));
352+
entity.setSimpleBoolean(simpleBoolean);
353+
entity.setSimpleShort(simpleShort);
354+
entity.setSimpleLong(simpleLong);
355+
entity.setSimpleFloat(simpleFloat);
356+
entity.setSimpleDouble(simpleDouble);
357+
entity.setSimpleByteArray(simpleByteArray);
358+
entity.setSimpleStringArray(simpleStringArray);
359+
entity.setSimpleStringList(Arrays.asList(simpleStringArray));
360+
entity.setSimpleShortU(simpleShort);
353361
entity.setSimpleIntU(nr);
354-
entity.setSimpleLongU(1000 + nr);
362+
entity.setSimpleLongU(simpleLong);
355363
if (simpleString != null) {
356364
Map<String, Object> stringObjectMap = new HashMap<>();
357365
stringObjectMap.put(simpleString, simpleString);
358366
entity.setStringObjectMap(stringObjectMap);
359367
}
360368
entity.setFlexProperty(simpleString);
361-
entity.setShortArray(new short[]{(short) -(100 + nr), entity.getSimpleShort()});
369+
entity.setBooleanArray(new boolean[]{simpleBoolean, false, true});
370+
entity.setShortArray(new short[]{(short) -(100 + nr), simpleShort});
362371
entity.setCharArray(simpleString != null ? simpleString.toCharArray() : null);
363-
entity.setIntArray(new int[]{-entity.getSimpleInt(), entity.getSimpleInt()});
364-
entity.setLongArray(new long[]{-entity.getSimpleLong(), entity.getSimpleLong()});
365-
entity.setFloatArray(new float[]{-entity.getSimpleFloat(), entity.getSimpleFloat()});
366-
entity.setDoubleArray(new double[]{-entity.getSimpleDouble(), entity.getSimpleDouble()});
367-
entity.setDate(new Date(1000 + nr));
372+
entity.setIntArray(new int[]{-nr, nr});
373+
entity.setLongArray(new long[]{-simpleLong, simpleLong});
374+
entity.setFloatArray(new float[]{-simpleFloat, simpleFloat});
375+
entity.setDoubleArray(new double[]{-simpleDouble, simpleDouble});
376+
entity.setDate(new Date(simpleLong));
368377
// Note: there is no way to test external type mapping works here. Instead, verify that
369378
// there are no side effects for put and get.
370-
entity.setExternalId(entity.getSimpleByteArray());
379+
entity.setExternalId(simpleByteArray);
371380
return entity;
372381
}
373382

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2017-2024 ObjectBox Ltd. All rights reserved.
2+
* Copyright 2017-2025 ObjectBox Ltd. All rights reserved.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -302,7 +302,7 @@ public void maxDataSize() {
302302
DbMaxDataSizeExceededException.class,
303303
() -> getTestEntityBox().put(testEntity2)
304304
);
305-
assertEquals("Exceeded user-set maximum by [bytes]: 560", maxDataExc.getMessage());
305+
assertEquals("Exceeded user-set maximum by [bytes]: 592", maxDataExc.getMessage());
306306

307307
// Remove to get below max data size, then put again.
308308
getTestEntityBox().remove(testEntity1);

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2017-2024 ObjectBox Ltd. All rights reserved.
2+
* Copyright 2017-2025 ObjectBox Ltd. All rights reserved.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -325,7 +325,7 @@ public void validate() {
325325
// Note: not implemented for in-memory, returns 0.
326326
// No limit.
327327
long validated = store.validate(0, true);
328-
assertEquals(IN_MEMORY ? 0 : 14, validated);
328+
assertEquals(IN_MEMORY ? 0 : 15, validated);
329329

330330
// With limit.
331331
validated = store.validate(1, true);

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2017-2024 ObjectBox Ltd. All rights reserved.
2+
* Copyright 2017-2025 ObjectBox Ltd. All rights reserved.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -81,6 +81,7 @@ public void testPutAndGet() {
8181
assertEquals(1, entityRead.getStringObjectMap().size());
8282
assertEquals(simpleString, entityRead.getStringObjectMap().get(simpleString));
8383
assertEquals(simpleString, entityRead.getFlexProperty());
84+
assertArrayEquals(new boolean[]{false, false, true}, entity.getBooleanArray());
8485
assertArrayEquals(new short[]{(short) -valShort, valShort}, entity.getShortArray());
8586
assertArrayEquals(simpleString.toCharArray(), entity.getCharArray());
8687
assertArrayEquals(new int[]{-simpleInt, simpleInt}, entity.getIntArray());
@@ -133,6 +134,7 @@ public void testPutAndGet_defaultOrNullValues() {
133134
assertEquals(0, defaultEntity.getSimpleLongU());
134135
assertNull(defaultEntity.getStringObjectMap());
135136
assertNull(defaultEntity.getFlexProperty());
137+
assertNull(defaultEntity.getBooleanArray());
136138
assertNull(defaultEntity.getShortArray());
137139
assertNull(defaultEntity.getCharArray());
138140
assertNull(defaultEntity.getIntArray());

tests/objectbox-java-test/src/test/java/io/objectbox/query/AbstractQueryTest.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2018-2023 ObjectBox Ltd. All rights reserved.
2+
* Copyright 2018-2025 ObjectBox Ltd. All rights reserved.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,20 +16,20 @@
1616

1717
package io.objectbox.query;
1818

19-
import io.objectbox.annotation.IndexType;
2019
import org.junit.Before;
2120

2221
import java.util.ArrayList;
2322
import java.util.List;
2423

24+
import javax.annotation.Nullable;
25+
2526
import io.objectbox.AbstractObjectBoxTest;
2627
import io.objectbox.Box;
2728
import io.objectbox.BoxStoreBuilder;
2829
import io.objectbox.TestEntity;
30+
import io.objectbox.annotation.IndexType;
2931
import io.objectbox.config.DebugFlags;
3032

31-
import javax.annotation.Nullable;
32-
3333
public class AbstractQueryTest extends AbstractObjectBoxTest {
3434
protected Box<TestEntity> box;
3535

@@ -55,6 +55,7 @@ public void setUpBox() {
5555
* <li>simpleFloat = [400.0..400.9]</li>
5656
* <li>simpleDouble = [2020.00..2020.09] (approximately)</li>
5757
* <li>simpleByteArray = [{1,2,2000}..{1,2,2009}]</li>
58+
* <li>boolArray = [{true, false, true}..{false, false, true}]</li>
5859
* <li>shortArray = [{-2100,2100}..{-2109,2109}]</li>
5960
* <li>intArray = [{-2000,2000}..{-2009,2009}]</li>
6061
* <li>longArray = [{-3000,3000}..{-3009,3009}]</li>

0 commit comments

Comments
 (0)