Skip to content

Commit b967dff

Browse files
Merge branch '86-sync-is-available' into sync
2 parents 6aa5f37 + 23b1dbe commit b967dff

File tree

4 files changed

+52
-10
lines changed

4 files changed

+52
-10
lines changed

objectbox-java/src/main/java/io/objectbox/sync/Sync.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,13 @@
1212
@Experimental
1313
public final class Sync {
1414

15+
/**
16+
* Returns true if the included native (JNI) ObjectBox library supports sync.
17+
*/
18+
public static boolean isAvailable() {
19+
return BoxStore.isSyncAvailable();
20+
}
21+
1522
/**
1623
* Start building a sync client. Requires the BoxStore that should be synced with the server,
1724
* the URL and port of the server to connect to and credentials to authenticate against the server.

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

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -240,14 +240,4 @@ public void testIsObjectBrowserAvailable() {
240240
assertFalse(BoxStore.isObjectBrowserAvailable());
241241
}
242242

243-
@Test
244-
public void testIsSyncAvailable() {
245-
// The individual values don't matter; basically just ensure the methods are available and don't crash...
246-
if(BoxStore.isSyncServerAvailable()) {
247-
assertTrue(BoxStore.isSyncAvailable());
248-
} else {
249-
BoxStore.isSyncAvailable();
250-
}
251-
}
252-
253243
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import io.objectbox.relation.ToOneTest;
3030
import io.objectbox.sync.ConnectivityMonitorTest;
3131
import io.objectbox.sync.PlatformTest;
32+
import io.objectbox.sync.SyncTest;
3233

3334
import org.junit.runner.RunWith;
3435
import org.junit.runners.Suite;
@@ -55,6 +56,7 @@
5556
QueryTest.class,
5657
RelationTest.class,
5758
RelationEagerTest.class,
59+
SyncTest.class,
5860
ToManyStandaloneTest.class,
5961
ToManyTest.class,
6062
ToOneTest.class,
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package io.objectbox.sync;
2+
3+
import org.junit.Test;
4+
5+
import io.objectbox.AbstractObjectBoxTest;
6+
import io.objectbox.BoxStore;
7+
8+
9+
import static org.junit.Assert.assertEquals;
10+
import static org.junit.Assert.assertFalse;
11+
import static org.junit.Assert.assertThrows;
12+
13+
public class SyncTest extends AbstractObjectBoxTest {
14+
15+
/**
16+
* Ensure that non-sync native library correctly reports sync client availability.
17+
*
18+
* Note: this test is mirrored in objectbox-integration-test sync tests, where sync is available.
19+
*/
20+
@Test
21+
public void clientIsNotAvailable() {
22+
assertFalse(Sync.isAvailable());
23+
}
24+
25+
/**
26+
* Ensure that non-sync native library correctly reports sync server availability.
27+
*
28+
* Note: this test is mirrored in objectbox-integration-test sync tests, where sync is available.
29+
*/
30+
@Test
31+
public void serverIsNotAvailable() {
32+
assertFalse(BoxStore.isSyncServerAvailable());
33+
}
34+
35+
@Test
36+
public void creatingSyncClient_throws() {
37+
IllegalStateException exception = assertThrows(
38+
IllegalStateException.class,
39+
() -> Sync.client(store, "wss://127.0.0.1", SyncCredentials.none())
40+
);
41+
assertEquals("This ObjectBox library (JNI) does not include sync. Please update your dependencies.", exception.getMessage());
42+
}
43+
}

0 commit comments

Comments
 (0)