Search in sources :

Example 11 with TargetApi

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());
}
Also used : Context(android.content.Context) RoboMenuItem(org.robolectric.fakes.RoboMenuItem) PopupMenu(android.widget.PopupMenu) ShadowPopupMenu(org.robolectric.shadows.ShadowPopupMenu) SlowTest(io.github.hidroh.materialistic.test.suite.SlowTest) Test(org.junit.Test) TargetApi(android.annotation.TargetApi)

Example 12 with TargetApi

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);
}
Also used : Context(android.content.Context) Canvas(android.graphics.Canvas) RecyclerView(android.support.v7.widget.RecyclerView) ShadowRecyclerView(io.github.hidroh.materialistic.test.shadow.ShadowRecyclerView) Paint(android.graphics.Paint) SlowTest(io.github.hidroh.materialistic.test.suite.SlowTest) Test(org.junit.Test) TargetApi(android.annotation.TargetApi)

Example 13 with TargetApi

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);
}
Also used : Context(android.content.Context) Canvas(android.graphics.Canvas) RecyclerView(android.support.v7.widget.RecyclerView) ShadowRecyclerView(io.github.hidroh.materialistic.test.shadow.ShadowRecyclerView) Paint(android.graphics.Paint) SlowTest(io.github.hidroh.materialistic.test.suite.SlowTest) Test(org.junit.Test) TargetApi(android.annotation.TargetApi)

Example 14 with TargetApi

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());
}
Also used : RoboMenuItem(org.robolectric.fakes.RoboMenuItem) PopupMenu(android.widget.PopupMenu) ShadowPopupMenu(org.robolectric.shadows.ShadowPopupMenu) SlowTest(io.github.hidroh.materialistic.test.suite.SlowTest) Test(org.junit.Test) TargetApi(android.annotation.TargetApi)

Example 15 with TargetApi

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());
}
Also used : Context(android.content.Context) ShadowContentObserver(org.robolectric.shadows.ShadowContentObserver) View(android.view.View) TextView(android.widget.TextView) RecyclerView(android.support.v7.widget.RecyclerView) ShadowRecyclerView(io.github.hidroh.materialistic.test.shadow.ShadowRecyclerView) RoboMenuItem(org.robolectric.fakes.RoboMenuItem) PopupMenu(android.widget.PopupMenu) ShadowPopupMenu(org.robolectric.shadows.ShadowPopupMenu) SlowTest(io.github.hidroh.materialistic.test.suite.SlowTest) Test(org.junit.Test) TargetApi(android.annotation.TargetApi)

Aggregations

TargetApi (android.annotation.TargetApi)1367 Intent (android.content.Intent)153 View (android.view.View)148 Test (org.junit.Test)119 SuppressLint (android.annotation.SuppressLint)115 Uri (android.net.Uri)70 ArrayList (java.util.ArrayList)68 Animator (android.animation.Animator)67 Point (android.graphics.Point)64 Window (android.view.Window)56 TextView (android.widget.TextView)56 IOException (java.io.IOException)56 ViewGroup (android.view.ViewGroup)54 Matchers.anyString (org.mockito.Matchers.anyString)53 SharedPreferences (android.content.SharedPreferences)44 File (java.io.File)44 Field (java.lang.reflect.Field)44 AnimatorListenerAdapter (android.animation.AnimatorListenerAdapter)43 Bitmap (android.graphics.Bitmap)43 ImageView (android.widget.ImageView)40