use of android.content.Intent in project android-job by evernote.
the class PlatformAlarmService method createIntent.
/*package*/
static Intent createIntent(Context context, int jobId) {
Intent intent = new Intent(context, PlatformAlarmService.class);
intent.putExtra(PlatformAlarmReceiver.EXTRA_JOB_ID, jobId);
return intent;
}
use of android.content.Intent in project materialistic by hidroh.
the class ItemActivityTest method testScrollToTop.
@Config(shadows = ShadowRecyclerView.class)
@Test
public void testScrollToTop() {
Intent intent = new Intent();
intent.putExtra(ItemActivity.EXTRA_ITEM, new TestItem() {
@NonNull
@Override
public String getType() {
return STORY_TYPE;
}
@Override
public String getId() {
return "1";
}
@Override
public boolean isStoryType() {
return true;
}
@Override
public int getKidCount() {
return 10;
}
@Override
public String getUrl() {
return "http://example.com";
}
});
controller.withIntent(intent).create().start().resume();
// see https://github.com/robolectric/robolectric/issues/1326
ShadowLooper.pauseMainLooper();
controller.visible();
ShadowApplication.getInstance().getForegroundThreadScheduler().advanceToLastPostedRunnable();
RecyclerView recyclerView = (RecyclerView) activity.findViewById(R.id.recycler_view);
recyclerView.smoothScrollToPosition(1);
assertThat(customShadowOf(recyclerView).getScrollPosition()).isEqualTo(1);
TabLayout tabLayout = (TabLayout) activity.findViewById(R.id.tab_layout);
assertThat(tabLayout.getTabCount()).isEqualTo(2);
tabLayout.getTabAt(1).select();
tabLayout.getTabAt(0).select();
tabLayout.getTabAt(0).select();
assertThat(customShadowOf(recyclerView).getScrollPosition()).isEqualTo(0);
}
use of android.content.Intent in project materialistic by hidroh.
the class ItemActivityTest method testVoteError.
@Test
public void testVoteError() {
Intent intent = new Intent();
intent.putExtra(ItemActivity.EXTRA_ITEM, new TestHnItem(1));
controller.withIntent(intent).create().start().resume();
activity.findViewById(R.id.vote_button).performClick();
verify(userServices).voteUp(any(Context.class), eq("1"), userServicesCallback.capture());
userServicesCallback.getValue().onError(new IOException());
assertEquals(activity.getString(R.string.vote_failed), ShadowToast.getTextOfLatestToast());
}
use of android.content.Intent in project materialistic by hidroh.
the class ItemActivityTest method testOptionExternal.
@SuppressLint("NewApi")
@Test
public void testOptionExternal() {
RobolectricPackageManager packageManager = (RobolectricPackageManager) RuntimeEnvironment.application.getPackageManager();
packageManager.addResolveInfoForIntent(new Intent(Intent.ACTION_VIEW, Uri.parse("http://example.com")), ShadowResolveInfo.newResolveInfo("label", "com.android.chrome", "DefaultActivity"));
packageManager.addResolveInfoForIntent(new Intent(Intent.ACTION_VIEW, Uri.parse(String.format(HackerNewsClient.WEB_ITEM_PATH, "1"))), ShadowResolveInfo.newResolveInfo("label", "com.android.chrome", "DefaultActivity"));
Intent intent = new Intent();
intent.putExtra(ItemActivity.EXTRA_ITEM, new TestItem() {
@NonNull
@Override
public String getType() {
return STORY_TYPE;
}
@Override
public String getUrl() {
return "http://example.com";
}
@Override
public boolean isStoryType() {
return true;
}
@Override
public String getId() {
return "1";
}
});
controller.withIntent(intent).create().start().resume();
// inflate menu, see https://github.com/robolectric/robolectric/issues/1326
ShadowLooper.pauseMainLooper();
controller.visible();
ShadowApplication.getInstance().getForegroundThreadScheduler().advanceToLastPostedRunnable();
// open article
shadowOf(activity).clickMenuItem(R.id.menu_external);
shadowOf(ShadowPopupMenu.getLatestPopupMenu()).getOnMenuItemClickListener().onMenuItemClick(new RoboMenuItem(R.id.menu_article));
ShadowApplication.getInstance().getForegroundThreadScheduler().advanceToLastPostedRunnable();
assertThat(shadowOf(activity).getNextStartedActivity()).hasAction(Intent.ACTION_VIEW);
// open item
shadowOf(activity).clickMenuItem(R.id.menu_external);
shadowOf(ShadowPopupMenu.getLatestPopupMenu()).getOnMenuItemClickListener().onMenuItemClick(new RoboMenuItem(R.id.menu_comments));
ShadowApplication.getInstance().getForegroundThreadScheduler().advanceToLastPostedRunnable();
assertThat(shadowOf(activity).getNextStartedActivity()).hasAction(Intent.ACTION_VIEW);
}
use of android.content.Intent in project materialistic by hidroh.
the class ItemFragmentMultiPageTest method testBindLocalKidData.
@Test
public void testBindLocalKidData() {
Item story = new TestHnItem(0L);
story.populate(new TestItem() {
@Override
public int getDescendants() {
return 1;
}
@Override
public long[] getKids() {
return new long[] { 1L };
}
});
story.getKidItems()[0].populate(new TestItem() {
@Override
public String getText() {
return "text";
}
@Override
public long[] getKids() {
return new long[] { 2L };
}
@Override
public int getDescendants() {
return 1;
}
});
Bundle args = new Bundle();
args.putParcelable(ItemFragment.EXTRA_ITEM, story);
Fragment fragment = Fragment.instantiate(RuntimeEnvironment.application, ItemFragment.class.getName(), args);
makeVisible(fragment);
assertThat(fragment.getView().findViewById(R.id.empty)).isNotVisible();
RecyclerView recyclerView = (RecyclerView) fragment.getView().findViewById(R.id.recycler_view);
RecyclerView.ViewHolder viewHolder = CustomShadows.customShadowOf(recyclerView.getAdapter()).getViewHolder(0);
assertThat((TextView) viewHolder.itemView.findViewById(R.id.text)).hasTextString("text");
assertThat(viewHolder.itemView.findViewById(R.id.comment)).isVisible();
viewHolder.itemView.findViewById(R.id.comment).performClick();
Intent actual = shadowOf(fragment.getActivity()).getNextStartedActivity();
assertEquals(ItemActivity.class.getName(), actual.getComponent().getClassName());
assertThat(actual).hasExtra(ItemActivity.EXTRA_OPEN_COMMENTS, true);
}
Aggregations