use of android.annotation.TargetApi in project materialistic by hidroh.
the class ListFragmentViewHolderTest method testVoteItem.
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
@Test
public void testVoteItem() {
verify(itemManager).getItem(any(), eq(ItemManager.MODE_DEFAULT), itemListener.capture());
itemListener.getValue().onResponse(item);
adapter.getViewHolder(0).itemView.performLongClick();
PopupMenu popupMenu = ShadowPopupMenu.getLatestPopupMenu();
assertNotNull(popupMenu);
assertThat(popupMenu.getMenu().findItem(R.id.menu_contextual_vote).isVisible()).isFalse();
shadowOf(popupMenu).getOnMenuItemClickListener().onMenuItemClick(new RoboMenuItem(R.id.menu_contextual_vote));
verify(userServices).voteUp(any(Context.class), eq(item.getId()), voteCallback.capture());
}
use of android.annotation.TargetApi in project materialistic by hidroh.
the class ListFragmentViewHolderTest method testSwipeToSaveItem.
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
@Test
public void testSwipeToSaveItem() {
verify(itemManager).getItem(any(), eq(ItemManager.MODE_DEFAULT), itemListener.capture());
itemListener.getValue().onResponse(item);
RecyclerView.ViewHolder holder = adapter.getViewHolder(0);
assertThat(swipeCallback.onMove(recyclerView, holder, holder)).isFalse();
assertThat(swipeCallback.getSwipeThreshold(holder)).isGreaterThan(0f);
assertThat(swipeCallback.getSwipeDirs(recyclerView, holder)).isEqualTo(ItemTouchHelper.LEFT | ItemTouchHelper.RIGHT);
Canvas canvas = mock(Canvas.class);
swipeCallback.onChildDraw(canvas, recyclerView, holder, -1f, 0f, ItemTouchHelper.ACTION_STATE_SWIPE, true);
verify(canvas).drawText(eq(activity.getString(R.string.save).toUpperCase()), anyFloat(), anyFloat(), any(Paint.class));
swipeCallback.onSwiped(holder, ItemTouchHelper.LEFT);
verify(favoriteManager).add(any(Context.class), eq(item));
item.setFavorite(true);
assertThat(swipeCallback.getSwipeDirs(recyclerView, holder)).isEqualTo(ItemTouchHelper.LEFT | ItemTouchHelper.RIGHT);
}
use of android.annotation.TargetApi in project materialistic by hidroh.
the class ListFragmentViewHolderTest method testSwipeToVoteItem.
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
@Test
public void testSwipeToVoteItem() {
verify(itemManager).getItem(any(), eq(ItemManager.MODE_DEFAULT), itemListener.capture());
itemListener.getValue().onResponse(item);
RecyclerView.ViewHolder holder = adapter.getViewHolder(0);
assertThat(swipeCallback.getSwipeDirs(recyclerView, holder)).isEqualTo(ItemTouchHelper.LEFT | ItemTouchHelper.RIGHT);
Canvas canvas = mock(Canvas.class);
swipeCallback.onChildDraw(canvas, recyclerView, holder, 1f, 0f, ItemTouchHelper.ACTION_STATE_SWIPE, true);
verify(canvas).drawText(eq(activity.getString(R.string.vote_up).toUpperCase()), anyFloat(), anyFloat(), any(Paint.class));
swipeCallback.onSwiped(holder, ItemTouchHelper.RIGHT);
verify(userServices).voteUp(any(Context.class), eq(item.getId()), voteCallback.capture());
item.incrementScore();
assertThat(swipeCallback.getSwipeDirs(recyclerView, holder)).isEqualTo(ItemTouchHelper.LEFT);
item.clearPendingVoted();
assertThat(swipeCallback.getSwipeDirs(recyclerView, holder)).isEqualTo(ItemTouchHelper.LEFT);
}
use of android.annotation.TargetApi in project materialistic by hidroh.
the class ListFragmentViewHolderTest method testRefresh.
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
@Test
public void testRefresh() {
verify(itemManager).getItem(any(), eq(ItemManager.MODE_DEFAULT), itemListener.capture());
itemListener.getValue().onResponse(item);
reset(itemManager);
adapter.getViewHolder(0).itemView.performLongClick();
PopupMenu popupMenu = ShadowPopupMenu.getLatestPopupMenu();
assertNotNull(popupMenu);
shadowOf(popupMenu).getOnMenuItemClickListener().onMenuItemClick(new RoboMenuItem(R.id.menu_contextual_refresh));
verify(itemManager).getItem(any(), eq(ItemManager.MODE_DEFAULT), any());
}
use of android.annotation.TargetApi in project materialistic by hidroh.
the class ListFragmentViewHolderTest method testSaveItem.
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
@Test
public void testSaveItem() {
ShadowContentObserver observer = shadowOf(shadowOf(activity.getContentResolver()).getContentObservers(MaterialisticProvider.URI_FAVORITE).iterator().next());
verify(itemManager).getItem(any(), eq(ItemManager.MODE_DEFAULT), itemListener.capture());
itemListener.getValue().onResponse(item);
adapter.getViewHolder(0).itemView.performLongClick();
PopupMenu popupMenu = ShadowPopupMenu.getLatestPopupMenu();
assertNotNull(popupMenu);
assertThat(popupMenu.getMenu().findItem(R.id.menu_contextual_save).isVisible()).isFalse();
shadowOf(popupMenu).getOnMenuItemClickListener().onMenuItemClick(new RoboMenuItem(R.id.menu_contextual_save));
verify(favoriteManager).add(any(Context.class), eq(item));
observer.dispatchChange(false, MaterialisticProvider.URI_FAVORITE.buildUpon().appendPath("add").appendPath("1").build());
assertTrue(item.isFavorite());
View snackbarView = ShadowSnackbar.getLatestView();
assertThat((TextView) snackbarView.findViewById(R.id.snackbar_text)).isNotNull().containsText(R.string.toast_saved);
snackbarView.findViewById(R.id.snackbar_action).performClick();
verify(favoriteManager).remove(any(Context.class), eq("1"));
observer.dispatchChange(false, MaterialisticProvider.URI_FAVORITE.buildUpon().appendPath("remove").appendPath("1").build());
assertFalse(item.isFavorite());
}
Aggregations