Skip to content

Commit 55ea65e

Browse files
Merge branch 'tests-java8-and-updates' into dev
2 parents 5775414 + 3ad05f9 commit 55ea65e

27 files changed

+313
-521
lines changed

build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ buildscript {
2828
objectboxNativeDependency = "io.objectbox:objectbox-$objectboxPlatform:$ob_native_version"
2929
println "ObjectBox native dependency: $objectboxNativeDependency"
3030
}
31+
ext.junit_version = '4.13'
3132

3233
repositories {
3334
mavenCentral()

objectbox-kotlin/build.gradle

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,6 @@ dependencies {
5858
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
5959

6060
compile project(':objectbox-java')
61-
62-
//testCompile 'junit:junit:4.12'
6361
}
6462

6563

objectbox-rxjava/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ dependencies {
99
compile project(':objectbox-java')
1010
compile 'io.reactivex.rxjava2:rxjava:2.2.9'
1111

12-
testCompile 'junit:junit:4.12'
12+
testCompile "junit:junit:$junit_version"
1313
testCompile 'org.mockito:mockito-core:2.25.1'
1414
}
1515

tests/objectbox-java-test/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ dependencies {
3333
println "Did NOT add native dependency"
3434
}
3535

36-
testCompile 'junit:junit:4.12'
36+
testCompile "junit:junit:$junit_version"
3737
}
3838

3939
test {

tests/objectbox-java-test/src/main/java/io/objectbox/index/model/EntityLongIndex_.java

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,16 @@ public class EntityLongIndex_ implements EntityInfo<EntityLongIndex> {
3838

3939
public final static EntityLongIndex_ __INSTANCE = new EntityLongIndex_();
4040

41-
public final static Property id = new Property(__INSTANCE, 0, 7, long.class, "id", true, "_id");
42-
public final static Property indexedLong = new Property(__INSTANCE, 1, 1, long.class, "indexedLong");
43-
public final static Property float1 = new Property(__INSTANCE, 2, 2, Float.class, "float1");
44-
public final static Property float2 = new Property(__INSTANCE, 3, 3, Float.class, "float2");
45-
public final static Property float3 = new Property(__INSTANCE, 4, 4, Float.class, "float3");
46-
public final static Property float4 = new Property(__INSTANCE, 5, 5, Float.class, "float4");
47-
public final static Property float5 = new Property(__INSTANCE, 6, 6, Float.class, "float5");
48-
49-
public final static Property[] __ALL_PROPERTIES = {
41+
public final static Property<EntityLongIndex> id = new Property<>(__INSTANCE, 0, 7, long.class, "id", true, "_id");
42+
public final static Property<EntityLongIndex> indexedLong = new Property<>(__INSTANCE, 1, 1, long.class, "indexedLong");
43+
public final static Property<EntityLongIndex> float1 = new Property<>(__INSTANCE, 2, 2, Float.class, "float1");
44+
public final static Property<EntityLongIndex> float2 = new Property<>(__INSTANCE, 3, 3, Float.class, "float2");
45+
public final static Property<EntityLongIndex> float3 = new Property<>(__INSTANCE, 4, 4, Float.class, "float3");
46+
public final static Property<EntityLongIndex> float4 = new Property<>(__INSTANCE, 5, 5, Float.class, "float4");
47+
public final static Property<EntityLongIndex> float5 = new Property<>(__INSTANCE, 6, 6, Float.class, "float5");
48+
49+
@SuppressWarnings("unchecked")
50+
public final static Property<EntityLongIndex>[] __ALL_PROPERTIES = new Property[]{
5051
id,
5152
indexedLong,
5253
float1,
@@ -56,15 +57,15 @@ public class EntityLongIndex_ implements EntityInfo<EntityLongIndex> {
5657
float5
5758
};
5859

59-
public final static Property __ID_PROPERTY = id;
60+
public final static Property<EntityLongIndex> __ID_PROPERTY = id;
6061

6162
@Override
62-
public Property[] getAllProperties() {
63+
public Property<EntityLongIndex>[] getAllProperties() {
6364
return __ALL_PROPERTIES;
6465
}
6566

6667
@Override
67-
public Property getIdProperty() {
68+
public Property<EntityLongIndex> getIdProperty() {
6869
return __ID_PROPERTY;
6970
}
7071

tests/objectbox-java-test/src/main/java/io/objectbox/relation/Customer_.java

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717

1818
package io.objectbox.relation;
1919

20+
import java.util.List;
21+
2022
import io.objectbox.EntityInfo;
2123
import io.objectbox.Property;
2224
import io.objectbox.annotation.apihint.Internal;
@@ -48,15 +50,16 @@ public class Customer_ implements EntityInfo<Customer> {
4850

4951
public final static Customer_ __INSTANCE = new Customer_();
5052

51-
public final static Property id = new Property(__INSTANCE, 0, 1, long.class, "id", true, "_id");
52-
public final static Property name = new Property(__INSTANCE, 1, 2, String.class, "name");
53+
public final static Property<Customer> id = new Property<>(__INSTANCE, 0, 1, long.class, "id", true, "_id");
54+
public final static Property<Customer> name = new Property<>(__INSTANCE, 1, 2, String.class, "name");
5355

54-
public final static Property[] __ALL_PROPERTIES = {
56+
@SuppressWarnings("unchecked")
57+
public final static Property<Customer>[] __ALL_PROPERTIES = new Property[]{
5558
id,
5659
name
5760
};
5861

59-
public final static Property __ID_PROPERTY = id;
62+
public final static Property<Customer> __ID_PROPERTY = id;
6063

6164
@Override
6265
public String getEntityName() {
@@ -79,12 +82,12 @@ public String getDbName() {
7982
}
8083

8184
@Override
82-
public Property[] getAllProperties() {
85+
public Property<Customer>[] getAllProperties() {
8386
return __ALL_PROPERTIES;
8487
}
8588

8689
@Override
87-
public Property getIdProperty() {
90+
public Property<Customer> getIdProperty() {
8891
return __ID_PROPERTY;
8992
}
9093

@@ -108,8 +111,8 @@ public long getId(Customer object) {
108111
static final RelationInfo<Customer, Order> orders =
109112
new RelationInfo<>(Customer_.__INSTANCE, Order_.__INSTANCE, new ToManyGetter<Customer>() {
110113
@Override
111-
public ToMany<Order> getToMany(Customer customer) {
112-
return (ToMany<Order>) customer.getOrders();
114+
public List<Order> getToMany(Customer customer) {
115+
return customer.getOrders();
113116
}
114117
}, Order_.customerId, new ToOneGetter<Order>() {
115118
@Override
@@ -121,8 +124,8 @@ public ToOne<Customer> getToOne(Order order) {
121124
static final RelationInfo<Customer, Order> ordersStandalone =
122125
new RelationInfo<>(Customer_.__INSTANCE, Order_.__INSTANCE, new ToManyGetter<Customer>() {
123126
@Override
124-
public ToMany<Order> getToMany(Customer customer) {
125-
return (ToMany<Order>) customer.getOrders();
127+
public List<Order> getToMany(Customer customer) {
128+
return customer.getOrders();
126129
}
127130
}, 1);
128131

tests/objectbox-java-test/src/main/java/io/objectbox/relation/Order_.java

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,8 @@
1717

1818
package io.objectbox.relation;
1919

20-
import javax.annotation.Nullable;
21-
22-
import io.objectbox.BoxStore;
23-
import io.objectbox.Cursor;
2420
import io.objectbox.EntityInfo;
2521
import io.objectbox.Property;
26-
import io.objectbox.Transaction;
2722
import io.objectbox.annotation.apihint.Internal;
2823
import io.objectbox.internal.CursorFactory;
2924
import io.objectbox.internal.IdGetter;
@@ -53,19 +48,20 @@ public class Order_ implements EntityInfo<Order> {
5348

5449
public final static Order_ __INSTANCE = new Order_();
5550

56-
public final static Property id = new Property(__INSTANCE, 0, 1, long.class, "id", true, "_id");
57-
public final static Property date = new Property(__INSTANCE, 1, 2, java.util.Date.class, "date");
58-
public final static Property customerId = new Property(__INSTANCE, 2, 3, long.class, "customerId");
59-
public final static Property text = new Property(__INSTANCE, 3, 4, String.class, "text");
51+
public final static Property<Order> id = new Property<>(__INSTANCE, 0, 1, long.class, "id", true, "_id");
52+
public final static Property<Order> date = new Property<>(__INSTANCE, 1, 2, java.util.Date.class, "date");
53+
public final static Property<Order> customerId = new Property<>(__INSTANCE, 2, 3, long.class, "customerId");
54+
public final static Property<Order> text = new Property<>(__INSTANCE, 3, 4, String.class, "text");
6055

61-
public final static Property[] __ALL_PROPERTIES = {
56+
@SuppressWarnings("unchecked")
57+
public final static Property<Order>[] __ALL_PROPERTIES = new Property[]{
6258
id,
6359
date,
6460
customerId,
6561
text
6662
};
6763

68-
public final static Property __ID_PROPERTY = id;
64+
public final static Property<Order> __ID_PROPERTY = id;
6965

7066
@Override
7167
public String getEntityName() {
@@ -88,12 +84,12 @@ public String getDbName() {
8884
}
8985

9086
@Override
91-
public Property[] getAllProperties() {
87+
public Property<Order>[] getAllProperties() {
9288
return __ALL_PROPERTIES;
9389
}
9490

9591
@Override
96-
public Property getIdProperty() {
92+
public Property<Order> getIdProperty() {
9793
return __ID_PROPERTY;
9894
}
9995

@@ -116,7 +112,7 @@ public long getId(Order object) {
116112

117113
static final RelationInfo<Order, Customer> customer = new RelationInfo<>(Order_.__INSTANCE, Customer_.__INSTANCE, customerId, new ToOneGetter<Order>() {
118114
@Override
119-
public ToOne getToOne(Order object) {
115+
public ToOne<Customer> getToOne(Order object) {
120116
return object.customer__toOne;
121117
}
122118
});

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ protected Box<TestEntity> getTestEntityBox() {
100100
}
101101

102102
@After
103-
public void tearDown() throws Exception {
103+
public void tearDown() {
104104
// Collect dangling Cursors and TXs before store closes
105105
System.gc();
106106
System.runFinalization();

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

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -78,33 +78,27 @@ public void testDefaultStoreNull() {
7878
}
7979

8080
@Test
81-
public void testMaxReaders() throws InterruptedException {
81+
public void testMaxReaders() {
8282
builder = createBoxStoreBuilder(false);
8383
store = builder.maxReaders(1).build();
8484
final Exception[] exHolder = {null};
85-
final Thread thread = new Thread(new Runnable() {
86-
@Override
87-
public void run() {
88-
try {
89-
getTestEntityBox().count();
90-
} catch (Exception e) {
91-
exHolder[0] = e;
92-
}
93-
getTestEntityBox().closeThreadResources();
85+
final Thread thread = new Thread(() -> {
86+
try {
87+
getTestEntityBox().count();
88+
} catch (Exception e) {
89+
exHolder[0] = e;
9490
}
91+
getTestEntityBox().closeThreadResources();
9592
});
9693

9794
getTestEntityBox().count();
98-
store.runInReadTx(new Runnable() {
99-
@Override
100-
public void run() {
101-
getTestEntityBox().count();
102-
thread.start();
103-
try {
104-
thread.join(5000);
105-
} catch (InterruptedException e) {
106-
e.printStackTrace();
107-
}
95+
store.runInReadTx(() -> {
96+
getTestEntityBox().count();
97+
thread.start();
98+
try {
99+
thread.join(5000);
100+
} catch (InterruptedException e) {
101+
e.printStackTrace();
108102
}
109103
});
110104

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

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -194,12 +194,9 @@ public void testCallInReadTxWithRetry_callback() {
194194
final int[] countHolderCallback = {0};
195195

196196
BoxStoreBuilder builder = new BoxStoreBuilder(createTestModel(false)).directory(boxStoreDir)
197-
.failedReadTxAttemptCallback(new TxCallback() {
198-
@Override
199-
public void txFinished(@Nullable Object result, @Nullable Throwable error) {
200-
assertNotNull(error);
201-
countHolderCallback[0]++;
202-
}
197+
.failedReadTxAttemptCallback((result, error) -> {
198+
assertNotNull(error);
199+
countHolderCallback[0]++;
203200
});
204201
store = builder.build();
205202
String value = store.callInReadTxWithRetry(createTestCallable(countHolder), 5, 0, true);
@@ -209,15 +206,12 @@ public void txFinished(@Nullable Object result, @Nullable Throwable error) {
209206
}
210207

211208
private Callable<String> createTestCallable(final int[] countHolder) {
212-
return new Callable<String>() {
213-
@Override
214-
public String call() throws Exception {
215-
int count = ++countHolder[0];
216-
if (count < 5) {
217-
throw new DbException("Count: " + count);
218-
}
219-
return "42";
209+
return () -> {
210+
int count = ++countHolder[0];
211+
if (count < 5) {
212+
throw new DbException("Count: " + count);
220213
}
214+
return "42";
221215
};
222216
}
223217

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

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -193,14 +193,11 @@ public void testPanicModeRemoveAllObjects() {
193193
@Test
194194
public void testRunInTx() {
195195
final long[] counts = {0, 0};
196-
store.runInTx(new Runnable() {
197-
@Override
198-
public void run() {
199-
box.put(new TestEntity());
200-
counts[0] = box.count();
201-
box.put(new TestEntity());
202-
counts[1] = box.count();
203-
}
196+
store.runInTx(() -> {
197+
box.put(new TestEntity());
198+
counts[0] = box.count();
199+
box.put(new TestEntity());
200+
counts[1] = box.count();
204201
});
205202
assertEquals(1, counts[0]);
206203
assertEquals(2, counts[1]);

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,7 @@ public void testFirstLastNextPrev() {
6161

6262
@Test
6363
public void testRemove() {
64-
Transaction transaction = store.beginTx();
65-
try {
64+
try (Transaction transaction = store.beginTx()) {
6665
KeyValueCursor cursor = transaction.createKeyValueCursor();
6766

6867
cursor.put(1, new byte[]{1, 1, 0, 0});
@@ -76,8 +75,6 @@ public void testRemove() {
7675
byte[] next = cursor.getNext();
7776
assertNotNull(next);
7877
assertTrue(Arrays.equals(new byte[]{4, 1, 0, 0}, next));
79-
} finally {
80-
transaction.close();
8178
}
8279
}
8380

0 commit comments

Comments
 (0)