Network { public Observable<User> loginWithEmail(String email, String password) { EmailLoginPayload payload = new EmailLoginPayload(email, password); return service.login(payload).map(new SessionTokenExtractor()).map(sessionStore.store()); } Network(ServiceFactory serviceFactory, Context context); Observable<User> loginWithUsername(String username, String password); Observable<User> loginWithEmail(String email, String password); Observable<Void> logout(); Observable<User> createUser(User user); Observable<Void> deleteCurrentUser(); Observable<User> updateCurrentUser(User user); Observable<User> retrieveUser(String id); Observable<User> refreshCurrentUser(); void clearLocalSessionToken(); Observable<RxPage<List<User>>> retrieveFollowings(); Observable<RxPage<List<User>>> retrieveFollowers(); Observable<RxPage<List<User>>> retrieveUserFollowings(String userId); Observable<RxPage<List<User>>> retrieveUserFollowers(String userId); Observable<RxPage<List<User>>> retrieveFriends(); Observable<RxPage<List<User>>> retrieveUserFriends(String userId); Observable<Connection> createConnection(Connection connection); Observable<List<User>> createSocialConnections(SocialConnections connections); Observable<Void> deleteConnection(String userId, Type type); Observable<RxPage<List<User>>> searchUsers(String searchTerm); Observable<RxPage<List<User>>> searchUsersByEmail(List<String> emails); Observable<RxPage<List<User>>> searchUsersBySocialIds(String platform, List<String> socialIds); Observable<RxPage<ConnectionList>> retrievePendingConnections(); Observable<RxPage<ConnectionList>> retrieveRejectedConnections(); Observable<Post> createPost(Post post); Observable<Post> retrievePost(String id); Observable<Post> updatePost(String id, Post post); Observable<Void> deletePost(String id); Observable<RxPage<List<Post>>> retrievePosts(); Observable<RxPage<List<Post>>> retrievePostsByUser(String id); Observable<Like> createLike(String id); Observable<Void> deleteLike(String id); Observable<RxPage<List<Like>>> retrieveLikesForPost(String id); Observable<RxPage<List<Like>>> retrieveLikesByUser(String userId); Observable<Void> createReaction(String postId, Reaction reaction); Observable<Void> deleteReaction(String postId, Reaction reaction); Observable<Comment> createComment(String postId, Comment comment); Observable<Void> deleteComment(String postId, String commentId); Observable<Comment> updateComment(String postId, String commentId, Comment comment); Observable<Void> sendAnalytics(); Observable<RxPage<List<Comment>>> retrieveCommentsForPost(String postId); Observable<RxPage<List<Post>>> retrievePostFeed(); Observable<List<Event>> retrieveEventFeed(); Observable<RxPage<NewsFeed>> retrieveNewsFeed(); Observable<RxPage<List<Event>>> retrieveMeFeed(); Observable<JsonObject> paginatedGet(String pointer); Observable<JsonObject> paginatedPost(String pointer, RequestBody payload);  }
@Test public void emailLoginSetsSessionTokenToServiceFactory() { when(user.getSessionToken()).thenReturn("sessionToken"); TestSubscriber<User> ts = new TestSubscriber<>(); network.loginWithEmail(EMAIL, PASSWORD).subscribe(ts); verify(serviceFactory).setSessionToken("sessionToken"); }
@Test public void emailLoginStoresSessionToken() { when(user.getSessionToken()).thenReturn("sessionToken"); TestSubscriber<User> ts = new TestSubscriber<>(); network.loginWithEmail(EMAIL, PASSWORD).subscribe(ts); verify(storeFunc).call(user); }
@Test public void loginWithEmailReturnsUserFromService() { TestSubscriber<User> ts = new TestSubscriber<>(); network.loginWithEmail(EMAIL, PASSWORD).subscribe(ts); assertThat(ts.getOnNextEvents(), hasItems(user)); }