Skip to content

Commit f2f4a75

Browse files
committed
Improve messages if Sync is unavailable etc.
1 parent 978df66 commit f2f4a75

File tree

4 files changed

+24
-9
lines changed

4 files changed

+24
-9
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@
55
import io.objectbox.sync.server.SyncServerBuilder;
66

77
/**
8+
* <a href="https://objectbox.io/sync/">ObjectBox Sync</a> makes data available on other devices.
89
* Start building a sync client using Sync.{@link #client(BoxStore, String, SyncCredentials)}
9-
* or a server using Sync.{@link #server(BoxStore, String, SyncCredentials)}.
10+
* or an embedded server using Sync.{@link #server(BoxStore, String, SyncCredentials)}.
1011
*/
1112
@SuppressWarnings({"unused", "WeakerAccess"})
12-
@Experimental
1313
public final class Sync {
1414

1515
/**
16-
* Returns true if the included native (JNI) ObjectBox library supports sync.
16+
* Returns true if the included native (JNI) ObjectBox library supports Sync.
1717
*/
1818
public static boolean isAvailable() {
1919
return BoxStore.isSyncAvailable();

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@ public SyncBuilder(BoxStore boxStore, String url, SyncCredentials credentials) {
7272
checkNotNull(credentials, "Sync credentials are required.");
7373
if (!BoxStore.isSyncAvailable()) {
7474
throw new IllegalStateException(
75-
"This ObjectBox library (JNI) does not include sync. Please update your dependencies.");
75+
"This library does not include ObjectBox Sync. " +
76+
"Please visit https://objectbox.io/sync/ for options.");
7677
}
7778
this.platform = Platform.findPlatform();
7879
this.boxStore = boxStore;

objectbox-java/src/main/java/io/objectbox/sync/server/SyncServerBuilder.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ public SyncServerBuilder(BoxStore boxStore, String url, SyncCredentials authenti
3030
checkNotNull(authenticatorCredentials, "Authenticator credentials are required.");
3131
if (!BoxStore.isSyncServerAvailable()) {
3232
throw new IllegalStateException(
33-
"This ObjectBox library (JNI) does not include sync server. Check your dependencies.");
33+
"This library does not include ObjectBox Sync Server. " +
34+
"Please visit https://objectbox.io/sync/ for options.");
3435
}
3536
this.boxStore = boxStore;
3637
this.url = url;

tests/objectbox-java-test/src/test/java/io/objectbox/sync/SyncTest.java

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@
66
import io.objectbox.BoxStore;
77

88

9-
import static org.junit.Assert.assertEquals;
109
import static org.junit.Assert.assertFalse;
1110
import static org.junit.Assert.assertThrows;
11+
import static org.junit.Assert.assertTrue;
1212

1313
public class SyncTest extends AbstractObjectBoxTest {
1414

1515
/**
1616
* Ensure that non-sync native library correctly reports sync client availability.
17-
*
17+
* <p>
1818
* Note: this test is mirrored in objectbox-integration-test sync tests, where sync is available.
1919
*/
2020
@Test
@@ -24,7 +24,7 @@ public void clientIsNotAvailable() {
2424

2525
/**
2626
* Ensure that non-sync native library correctly reports sync server availability.
27-
*
27+
* <p>
2828
* Note: this test is mirrored in objectbox-integration-test sync tests, where sync is available.
2929
*/
3030
@Test
@@ -38,6 +38,19 @@ public void creatingSyncClient_throws() {
3838
IllegalStateException.class,
3939
() -> Sync.client(store, "wss://127.0.0.1", SyncCredentials.none())
4040
);
41-
assertEquals("This ObjectBox library (JNI) does not include sync. Please update your dependencies.", exception.getMessage());
41+
String message = exception.getMessage();
42+
assertTrue(message, message.contains("does not include ObjectBox Sync") &&
43+
message.contains("https://objectbox.io/sync") && !message.contains("erver"));
44+
}
45+
46+
@Test
47+
public void creatingSyncServer_throws() {
48+
IllegalStateException exception = assertThrows(
49+
IllegalStateException.class,
50+
() -> Sync.server(store, "wss://127.0.0.1", SyncCredentials.none())
51+
);
52+
String message = exception.getMessage();
53+
assertTrue(message, message.contains("does not include ObjectBox Sync Server") &&
54+
message.contains("https://objectbox.io/sync"));
4255
}
4356
}

0 commit comments

Comments
 (0)