@Test public void testCommentNotLoggedIn() { Preferences.setUsername(RuntimeEnvironment.application, null); UserServices.Callback callback = mock(UserServices.Callback.class); userServices.reply(RuntimeEnvironment.application, "1", "reply", callback); verify(call, never()).enqueue(any(Callback.class)); verify(callback).onDone(eq(false)); }
@Override public void reply(Context context, String parentId, String text, Callback callback) { Pair<String, String> credentials = AppUtils.getCredentials(context); if (credentials == null) { callback.onDone(false); return; } execute(postReply(parentId, text, credentials.first, credentials.second)) .map(response -> response.code() == HttpURLConnection.HTTP_MOVED_TEMP) .observeOn(AndroidSchedulers.mainThread()) .subscribe(callback::onDone, callback::onError); }
UserServicesClient implements UserServices { @Override public void reply(Context context, String parentId, String text, Callback callback) { Pair<String, String> credentials = AppUtils.getCredentials(context); if (credentials == null) { callback.onDone(false); return; } execute(postReply(parentId, text, credentials.first, credentials.second)) .map(response -> response.code() == HttpURLConnection.HTTP_MOVED_TEMP) .observeOn(AndroidSchedulers.mainThread()) .subscribe(callback::onDone, callback::onError); } }
UserServicesClient implements UserServices { @Override public void reply(Context context, String parentId, String text, Callback callback) { Pair<String, String> credentials = AppUtils.getCredentials(context); if (credentials == null) { callback.onDone(false); return; } execute(postReply(parentId, text, credentials.first, credentials.second)) .map(response -> response.code() == HttpURLConnection.HTTP_MOVED_TEMP) .observeOn(AndroidSchedulers.mainThread()) .subscribe(callback::onDone, callback::onError); } @Inject  UserServicesClient(Call.Factory callFactory, Scheduler ioScheduler); }
UserServicesClient implements UserServices { @Override public void reply(Context context, String parentId, String text, Callback callback) { Pair<String, String> credentials = AppUtils.getCredentials(context); if (credentials == null) { callback.onDone(false); return; } execute(postReply(parentId, text, credentials.first, credentials.second)) .map(response -> response.code() == HttpURLConnection.HTTP_MOVED_TEMP) .observeOn(AndroidSchedulers.mainThread()) .subscribe(callback::onDone, callback::onError); } @Inject  UserServicesClient(Call.Factory callFactory, Scheduler ioScheduler); @Override void login(String username, String password, boolean createAccount, Callback callback); @Override boolean voteUp(Context context, String itemId, Callback callback); @Override void reply(Context context, String parentId, String text, Callback callback); @Override void submit(Context context, String title, String content, boolean isUrl, Callback callback); }
UserServicesClient implements UserServices { @Override public void reply(Context context, String parentId, String text, Callback callback) { Pair<String, String> credentials = AppUtils.getCredentials(context); if (credentials == null) { callback.onDone(false); return; } execute(postReply(parentId, text, credentials.first, credentials.second)) .map(response -> response.code() == HttpURLConnection.HTTP_MOVED_TEMP) .observeOn(AndroidSchedulers.mainThread()) .subscribe(callback::onDone, callback::onError); } @Inject  UserServicesClient(Call.Factory callFactory, Scheduler ioScheduler); @Override void login(String username, String password, boolean createAccount, Callback callback); @Override boolean voteUp(Context context, String itemId, Callback callback); @Override void reply(Context context, String parentId, String text, Callback callback); @Override void submit(Context context, String title, String content, boolean isUrl, Callback callback);  }