@Test public void testVoteNoAccount() { AccountManager.get(RuntimeEnvironment.application) .removeAccount(account, null, null); UserServices.Callback callback = mock(UserServices.Callback.class); assertFalse(userServices.voteUp(RuntimeEnvironment.application, "1", callback)); verify(call, never()).enqueue(any(Callback.class)); }
@Override public boolean voteUp(Context context, String itemId, Callback callback) { Pair<String, String> credentials = AppUtils.getCredentials(context); if (credentials == null) { return false; } Toast.makeText(context, R.string.sending, Toast.LENGTH_SHORT).show(); execute(postVote(credentials.first, credentials.second, itemId)) .map(response -> response.code() == HttpURLConnection.HTTP_MOVED_TEMP) .observeOn(AndroidSchedulers.mainThread()) .subscribe(callback::onDone, callback::onError); return true; }
UserServicesClient implements UserServices { @Override public boolean voteUp(Context context, String itemId, Callback callback) { Pair<String, String> credentials = AppUtils.getCredentials(context); if (credentials == null) { return false; } Toast.makeText(context, R.string.sending, Toast.LENGTH_SHORT).show(); execute(postVote(credentials.first, credentials.second, itemId)) .map(response -> response.code() == HttpURLConnection.HTTP_MOVED_TEMP) .observeOn(AndroidSchedulers.mainThread()) .subscribe(callback::onDone, callback::onError); return true; } }
UserServicesClient implements UserServices { @Override public boolean voteUp(Context context, String itemId, Callback callback) { Pair<String, String> credentials = AppUtils.getCredentials(context); if (credentials == null) { return false; } Toast.makeText(context, R.string.sending, Toast.LENGTH_SHORT).show(); execute(postVote(credentials.first, credentials.second, itemId)) .map(response -> response.code() == HttpURLConnection.HTTP_MOVED_TEMP) .observeOn(AndroidSchedulers.mainThread()) .subscribe(callback::onDone, callback::onError); return true; } @Inject  UserServicesClient(Call.Factory callFactory, Scheduler ioScheduler); }
UserServicesClient implements UserServices { @Override public boolean voteUp(Context context, String itemId, Callback callback) { Pair<String, String> credentials = AppUtils.getCredentials(context); if (credentials == null) { return false; } Toast.makeText(context, R.string.sending, Toast.LENGTH_SHORT).show(); execute(postVote(credentials.first, credentials.second, itemId)) .map(response -> response.code() == HttpURLConnection.HTTP_MOVED_TEMP) .observeOn(AndroidSchedulers.mainThread()) .subscribe(callback::onDone, callback::onError); return true; } @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 boolean voteUp(Context context, String itemId, Callback callback) { Pair<String, String> credentials = AppUtils.getCredentials(context); if (credentials == null) { return false; } Toast.makeText(context, R.string.sending, Toast.LENGTH_SHORT).show(); execute(postVote(credentials.first, credentials.second, itemId)) .map(response -> response.code() == HttpURLConnection.HTTP_MOVED_TEMP) .observeOn(AndroidSchedulers.mainThread()) .subscribe(callback::onDone, callback::onError); return true; } @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);  }