@Test(expected = ActivityNotFoundException.class) public void checkActivities_shouldSetValueOnShadowApplication() throws Exception { ShadowApplication.getInstance().checkActivities(true); context.startActivity( new Intent("i.dont.exist.activity").addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)); }
@Test public void startActivity_whenActivityCheckingEnabled_findsResolveInfo() throws Exception { shadowOf(context).checkActivities(true); context.startActivity( new Intent() .setClassName(context, TestActivity.class.getName()) .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)); assertThat(shadowOf(context).getNextStartedActivity()).isNotNull(); }
@Test public void startActivity_whenActivityCheckingEnabled_doesntFindResolveInfo() throws Exception { shadowOf(context).checkActivities(true); String action = "com.does.not.exist.android.app.v2.mobile"; try { context.startActivity(new Intent(action).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)); fail("Expected startActivity to throw ActivityNotFoundException!"); } catch (ActivityNotFoundException e) { assertThat(e.getMessage()).contains(action); assertThat(shadowOf(context).getNextStartedActivity()).isNull(); } }