CommentsPresenter implements ReplyView.Listener, CommentsAdapter.Listener, LoaderManager.LoaderCallbacks<Cursor> { public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.action_bookmark: if (item.isChecked()) { onBookmarkUnselected(item); } else { onBookmarkSelected(item); } return true; case android.R.id.home: activity.finish(); return true; default: return false; } } CommentsPresenter(HNewsActivity activity, SwipeRefreshLayout.OnRefreshListener refreshListener); void onCreate(); void onPostCreate(boolean online); void onCreateOptionsMenu(Menu menu); void onBookmarkUnselected(MenuItem item); void onBookmarkSelected(MenuItem item); void showReplyViewForComment(Long commentId); void showNotImplemented(); void showLoginExpired(); void showContentUpdating(); @Override void onReplyCancelled(); @Override void onReplySuccessful(); @Override void onLoginExpired(); @Override void onCommentReplyAction(Long id); @Override void onCommentVoteAction(Long id); @Override Loader<Cursor> onCreateLoader(int id, Bundle args); @Override void onLoadFinished(Loader<Cursor> loader, Cursor data); @Override void onLoaderReset(Loader<Cursor> loader); void hideRefreshAnimation(); boolean onOptionsItemSelected(MenuItem item); void onRefresh(boolean isOnline); void onBackPressed(); boolean inReplyMode(); static final String VIEW_NAME_HEADER_TITLE; }
@Test public void removesBookmarkWhenBookmarkItemWasSelected() { when(menuItem.getItemId()).thenReturn(R.id.action_bookmark); when(menuItem.isChecked()).thenReturn(true); commentsPresenter.onOptionsItemSelected(menuItem); verify(menuItem).setIcon(R.drawable.ic_bookmark_outline_white); verify(menuItem).setChecked(false); }
@Test public void addsBookmarkWhenBookmarkItemWasNotSelected() { when(menuItem.getItemId()).thenReturn(R.id.action_bookmark); when(menuItem.isChecked()).thenReturn(false); commentsPresenter.onOptionsItemSelected(menuItem); verify(menuItem).setIcon(R.drawable.ic_bookmark_white); verify(menuItem).setChecked(true); }