Syncbase { public static void login(final String authToken, final String provider, final LoginCallback cb) { if (!(provider.equals(User.PROVIDER_GOOGLE) || provider.equals(User.PROVIDER_NONE))) { throw new IllegalArgumentException("Unsupported provider: " + provider); } new Thread(new Runnable() { @Override public void run() { try { io.v.syncbase.internal.Service.Login(provider, authToken); sDatabase = database(); if (sDatabase==null) { cb.onError(new IllegalStateException("not logged in")); return; } sDatabase.createIfMissing(); Collection userdata = sDatabase.createNamedCollection( USERDATA_NAME, new DatabaseHandle.CollectionOptions().setWithoutSyncgroup(true)); if (!sOpts.mDisableUserdataSyncgroup) { Syncgroup syncgroup = userdata.getSyncgroup(); try { syncgroup.join(); } catch(VError e) { syncgroup.createIfMissing(ImmutableList.of(userdata)); } Database.AddWatchChangeHandlerOptions opts = new Database .AddWatchChangeHandlerOptions.Builder(). setShowUserdataCollectionRow(true).build(); sDatabase.addWatchChangeHandler(new UserdataWatchHandler(), opts); } sOpts.mCallbackExecutor.execute(new Runnable() { @Override public void run() { cb.onSuccess(); } }); } catch (Throwable e) { cb.onError(e); } } }).start(); } private  Syncbase(); static void init(Options opts); static void executeCallback(Runnable runnable); static Database database(); static void shutdown(); static boolean isLoggedIn(); static User getLoggedInUser(); static void login(final String authToken, final String provider, final LoginCallback cb); static void addScanForUsersInNeighborhood(final ScanNeighborhoodForUsersCallback cb); static void removeScanForUsersInNeighborhood(ScanNeighborhoodForUsersCallback cb); static void removeAllScansForUsersInNeighborhood(); static void advertiseLoggedInUserInNeighborhood(); static void advertiseLoggedInUserInNeighborhood(Iterable<User> usersWhoCanSee); static void stopAdvertisingLoggedInUserInNeighborhood(); static boolean isAdvertisingLoggedInUserInNeighborhood(); static final String USERDATA_NAME; }
@Test public void unsupportedAuthenticationProvider() { thrown.expect(IllegalArgumentException.class); thrown.expectMessage("Unsupported provider: bogusProvider"); Syncbase.login("", "bogusProvider", new Syncbase.LoginCallback() { @Override public void onSuccess() { } @Override public void onError(Throwable e) { } }); }