protected ComponentName startService(Intent intent) { startedServices.add(new Intent.FilterComparison(intent)); if (intent.getComponent() != null) { return intent.getComponent(); } return new ComponentName("some.service.package", "SomeServiceName-FIXME"); }
public Intent getIntent() { Intent intent = this.intent == null ? new Intent(RuntimeEnvironment.application, component.getClass()) : this.intent; if (intent.getComponent() == null) { intent.setClass(RuntimeEnvironment.application, component.getClass()); } return intent; }
private static ComponentName getComponentForIntent(Intent intent) { ComponentName component = intent.getComponent(); if (component == null) { if (intent.getSelector() != null) { intent = intent.getSelector(); component = intent.getComponent(); } } return component; }
@Override public Activity newActivity(ClassLoader cl, String className, Intent intent) throws InstantiationException, IllegalAccessException, ClassNotFoundException { if (processIntent(cl, intent)) { return super.newActivity(cl, intent.getComponent().getClassName(), intent); } else { return super.newActivity(cl, className, intent); } }
@Test public void testSetClassName() throws Exception { Intent intent = new Intent(); Class<? extends ShadowIntentTest> thisClass = getClass(); intent.setClassName("package.name", thisClass.getName()); assertSame(thisClass.getName(), intent.getComponent().getClassName()); assertEquals("package.name", intent.getComponent().getPackageName()); assertSame(intent.getComponent().getClassName(), thisClass.getName()); }
@Test public void testSetClassThroughConstructor() throws Exception { Intent intent = new Intent(ApplicationProvider.getApplicationContext(), getClass()); assertThat(intent.getComponent().getClassName()).isEqualTo(getClass().getName()); }
@Test public void testSetClass() throws Exception { Intent intent = new Intent(); Class<? extends ShadowIntentTest> thisClass = getClass(); Intent output = intent.setClass(ApplicationProvider.getApplicationContext(), thisClass); assertSame(output, intent); assertThat(intent.getComponent().getClassName()).isEqualTo(thisClass.getName()); }
@Test public void constructor_shouldSetComponentAndActionAndData() { Intent intent = new Intent( "roboaction", Uri.parse("http://www.robolectric.org"), ApplicationProvider.getApplicationContext(), Activity.class); assertThat(intent.getComponent()).isEqualTo(new ComponentName("org.robolectric", "android.app.Activity")); assertThat(intent.getAction()).isEqualTo("roboaction"); assertThat(intent.getData()).isEqualTo(Uri.parse("http://www.robolectric.org")); }
@Test public void getParentActivityIntent() { Activity activity = setupActivity(ChildActivity.class); assertThat(activity.getParentActivityIntent().getComponent().getClassName()) .isEqualTo(ParentActivity.class.getName()); }
@Test public void queryActivityIcons_Match() throws Exception { Intent i = new Intent(); i.setComponent(new ComponentName(TEST_PACKAGE_NAME, "")); Drawable d = new BitmapDrawable(); shadowPackageManager.addActivityIcon(i, d); assertThat(packageManager.getActivityIcon(i)).isSameAs(d); assertThat(packageManager.getActivityIcon(i.getComponent())).isSameAs(d); }
@Test public void inflate_shouldParseIntentContainedInPreference() throws Exception { final PreferenceScreen screen = inflatePreferenceActivity(); final Preference intentPreference = screen.findPreference("intent"); Intent intent = intentPreference.getIntent(); assertThat(intent).isNotNull(); assertThat(intent.getAction()).isEqualTo("action"); assertThat(intent.getData()).isEqualTo(Uri.parse("tel://1235")); assertThat(intent.getType()).isEqualTo("application/text"); assertThat(intent.getComponent().getClassName()).isEqualTo("org.robolectric.test.Intent"); assertThat(intent.getComponent().getPackageName()).isEqualTo("org.robolectric"); }
@Test public void startIntentSender_serviceIntent() throws IntentSender.SendIntentException { PendingIntent intent = PendingIntent.getService( context, 0, new Intent().setClassName(context, "ServiceIntent"), PendingIntent.FLAG_UPDATE_CURRENT); context.startIntentSender(intent.getIntentSender(), null, 0, 0, 0); assertThat(shadowOf(context).getNextStartedService().getComponent().getClassName()) .isEqualTo("ServiceIntent"); }
@Test public void onBindShouldSetIntentComponentWithCustomIntentWithoutComponentSet() throws Exception { MyService myService = Robolectric.buildService(MyService.class, new Intent(Intent.ACTION_VIEW)).bind().get(); assertThat(myService.boundIntent.getAction()).isEqualTo(Intent.ACTION_VIEW); assertThat(myService.boundIntent.getComponent()).isEqualTo(componentName); }
@Test public void onBindShouldSetIntentComponentWithCustomIntentWithoutComponentSet() throws Exception { MyService myService = Robolectric.buildIntentService(MyService.class, new Intent(Intent.ACTION_VIEW)).bind().get(); assertThat(myService.boundIntent.getAction()).isEqualTo(Intent.ACTION_VIEW); assertThat(myService.boundIntent.getComponent()).isEqualTo(componentName); }
@Test public void onStartCommandShouldSetIntentAndFlags() throws Exception { MyService myService = controller.create().startCommand(3, 4).get(); assertThat(myService.startIntent).isNotNull(); assertThat(myService.startIntent.getComponent()).isEqualTo(componentName); assertThat(myService.startFlags).isEqualTo(3); assertThat(myService.startId).isEqualTo(4); }
@Test public void shouldSetIntentComponentWithCustomIntentWithoutComponentSet() throws Exception { MyActivity myActivity = Robolectric.buildActivity(MyActivity.class, new Intent(Intent.ACTION_VIEW)).create().get(); assertThat(myActivity.getIntent().getAction()).isEqualTo(Intent.ACTION_VIEW); assertThat(myActivity.getIntent().getComponent()).isEqualTo(componentName); }
@Test public void onBindShouldSetIntent() throws Exception { MyService myService = controller.create().bind().get(); assertThat(myService.boundIntent).isNotNull(); assertThat(myService.boundIntent.getComponent()).isEqualTo(componentName); }
@Test public void onStartCommandShouldSetIntent() throws Exception { MyService myService = controller.create().startCommand(3, 4).get(); assertThat(myService.startIntent).isNotNull(); assertThat(myService.startIntent.getComponent()).isEqualTo(componentName); }
@Test public void onBindShouldSetIntent() throws Exception { MyService myService = controller.create().bind().get(); assertThat(myService.boundIntent).isNotNull(); assertThat(myService.boundIntent.getComponent()).isEqualTo(componentName); }
@Test public void shouldSetIntent() throws Exception { MyActivity myActivity = controller.create().get(); assertThat(myActivity.getIntent()).isNotNull(); assertThat(myActivity.getIntent().getComponent()).isEqualTo(componentName); }