Search in sources :

Example 6 with TargetApi

use of android.annotation.TargetApi in project materialistic by hidroh.

the class FavoriteActivityTest method testVoteItemFailed.

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
@Test
public void testVoteItemFailed() {
    shadowAdapter.getViewHolder(0).itemView.findViewById(R.id.button_more).performClick();
    PopupMenu popupMenu = ShadowPopupMenu.getLatestPopupMenu();
    Assert.assertNotNull(popupMenu);
    shadowOf(popupMenu).getOnMenuItemClickListener().onMenuItemClick(new RoboMenuItem(R.id.menu_contextual_vote));
    verify(userServices).voteUp(any(Context.class), any(), userServicesCallback.capture());
    userServicesCallback.getValue().onError(new IOException());
    assertEquals(activity.getString(R.string.vote_failed), ShadowToast.getTextOfLatestToast());
}
Also used : Context(android.content.Context) IOException(java.io.IOException) 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 7 with TargetApi

use of android.annotation.TargetApi in project materialistic by hidroh.

the class FavoriteActivityTest method testVoteItem.

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
@Test
public void testVoteItem() {
    shadowAdapter.getViewHolder(0).itemView.findViewById(R.id.button_more).performClick();
    PopupMenu popupMenu = ShadowPopupMenu.getLatestPopupMenu();
    Assert.assertNotNull(popupMenu);
    shadowOf(popupMenu).getOnMenuItemClickListener().onMenuItemClick(new RoboMenuItem(R.id.menu_contextual_vote));
    verify(userServices).voteUp(any(Context.class), any(), userServicesCallback.capture());
    userServicesCallback.getValue().onDone(true);
    assertEquals(activity.getString(R.string.voted), ShadowToast.getTextOfLatestToast());
}
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 8 with TargetApi

use of android.annotation.TargetApi in project materialistic by hidroh.

the class FavoriteActivityTest method testShare.

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
@Test
public void testShare() {
    TestApplication.addResolver(new Intent(Intent.ACTION_SEND));
    shadowAdapter.getViewHolder(0).itemView.findViewById(R.id.button_more).performClick();
    PopupMenu popupMenu = ShadowPopupMenu.getLatestPopupMenu();
    Assert.assertNotNull(popupMenu);
    shadowOf(popupMenu).getOnMenuItemClickListener().onMenuItemClick(new RoboMenuItem(R.id.menu_contextual_share));
    assertThat(shadowOf(activity).getNextStartedActivity()).hasAction(Intent.ACTION_SEND);
}
Also used : Intent(android.content.Intent) 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 9 with TargetApi

use of android.annotation.TargetApi in project materialistic by hidroh.

the class ItemFragmentSinglePageTest method testVoteItemPromptToLogin.

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
@Test
public void testVoteItemPromptToLogin() {
    viewHolder.itemView.findViewById(R.id.button_more).performClick();
    PopupMenu popupMenu = ShadowPopupMenu.getLatestPopupMenu();
    assertNotNull(popupMenu);
    shadowOf(popupMenu).getOnMenuItemClickListener().onMenuItemClick(new RoboMenuItem(R.id.menu_contextual_vote));
    verify(userServices).voteUp(any(Context.class), any(), voteCallback.capture());
    voteCallback.getValue().onDone(false);
    assertThat(shadowOf(activity).getNextStartedActivity()).hasComponent(activity, LoginActivity.class);
}
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 10 with TargetApi

use of android.annotation.TargetApi in project materialistic by hidroh.

the class ListFragmentViewHolderTest method testReply.

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
@Test
public void testReply() {
    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);
    shadowOf(popupMenu).getOnMenuItemClickListener().onMenuItemClick(new RoboMenuItem(R.id.menu_contextual_comment));
    assertThat(shadowOf(activity).getNextStartedActivity()).hasComponent(activity, ComposeActivity.class).hasExtra(ComposeActivity.EXTRA_PARENT_ID, "1");
}
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)

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