UserDataSource { public Observable<Boolean> login(final String userName, String password) { authRetrofit.setUserInfo(userName, password); final UserService api = authRetrofit.build().create(UserService.class); CreateAuthorization createAuthorization = new CreateAuthorization(); createAuthorization.note = GithubConfig.NOTE; createAuthorization.client_id = GithubConfig.CLIENT_ID; createAuthorization.client_secret = GithubConfig.CLIENT_SECRET; createAuthorization.scopes = GithubConfig.SCOPES; return api.createAuthorization(createAuthorization) .flatMap(new Func1<Authorization, Observable<UserInfo>>() { @Override public Observable<UserInfo> call(Authorization authorization) { String token = authorization.getToken(); AccountPrefs.saveLoginToken(mCtx, token); return api.getUserInfo(userName); } }) .compose(RxJavaUtils.<UserInfo>applySchedulers()) .map(new Func1<UserInfo, Boolean>() { @Override public Boolean call(UserInfo userInfo) { if (userInfo != null) { AccountPrefs.saveLoginUser(mCtx, userInfo); return true; } return false; } }); } UserDataSource(GithubAuthRetrofit authRetrofit, UserService userApi, Context ctx); Observable<UserInfo> getUserInfo(String user); Observable<Boolean> login(final String userName, String password); Observable<List<UserEntity>> listFollowers(String userName, int page); Observable<List<UserEntity>> listFollowing(String user, int page); Observable<List<RepositoryInfo>> listStarredRepo(String user, int page); Observable<List<RepositoryInfo>> listStarredRepo(String user, SortType_Repo sort, int page); Observable<List<RepositoryInfo>> listWatchingRepo(String user, int page); Observable<List<RepositoryInfo>> listOwnRepo(String user, int page); Observable<List<Event>> listNews(String user, int page); Observable<SearchResult<UserEntity>> search(String keyWord, String language, SortType_User sort, int page); Observable<Boolean> signOut(); String getLoginUserName(); Observable<Boolean> toFollow(String user); Observable<Boolean> toUnFollow(String user); Observable<Boolean> checkIfFollowing(String user);  }
@Test public void login() throws Exception { TestSubscriber<Boolean> subscriber = TestSubscriber.create(); userDataSource.login("Nolan1995", "a123456").subscribe(subscriber); subscriber.assertValue(true); subscriber = TestSubscriber.create(); userDataSource.login("Nolan1995", "").subscribe(subscriber); subscriber.assertNoValues(); }