use of com.kickstarter.models.Comment in project android-oss by kickstarter.
the class CommentsAdapter method takeData.
public void takeData(@NonNull final CommentsData data) {
final Project project = data.project();
final List<Comment> comments = data.comments();
final User user = data.user();
sections().clear();
sections().add(Collections.singletonList(project));
addSection(Observable.from(comments).map(comment -> Pair.create(project, comment)).toList().toBlocking().single());
if (comments.size() == 0) {
sections().add(Collections.singletonList(new Pair<>(project, user)));
} else {
sections().add(Collections.emptyList());
}
notifyDataSetChanged();
}
use of com.kickstarter.models.Comment in project android-oss by kickstarter.
the class CommentsViewModelTest method testCommentsViewModel_postCommentError.
@Test
public void testCommentsViewModel_postCommentError() {
final ApiClientType apiClient = new MockApiClient() {
@Override
@NonNull
public Observable<Comment> postComment(@NonNull final Project project, @NonNull final String body) {
return Observable.error(ApiExceptionFactory.badRequestException());
}
};
final Environment env = environment().toBuilder().apiClient(apiClient).build();
final CommentsViewModel vm = new CommentsViewModel(env);
final TestSubscriber<String> showPostCommentErrorToast = new TestSubscriber<>();
vm.outputs.showPostCommentErrorToast().subscribe(showPostCommentErrorToast);
final TestSubscriber<Void> showCommentPostedToast = new TestSubscriber<>();
vm.outputs.showCommentPostedToast().subscribe(showCommentPostedToast);
// Start the view model with a project.
vm.intent(new Intent().putExtra(IntentKey.PROJECT, ProjectFactory.backedProject()));
// Click the comment button and write a comment.
vm.inputs.commentButtonClicked();
vm.inputs.commentBodyChanged("Mic check mic check.");
// Post comment. Error should be shown. Comment posted toast should not be shown.
vm.inputs.postCommentClicked();
showPostCommentErrorToast.assertValueCount(1);
showCommentPostedToast.assertNoValues();
}
Aggregations