org.robolectric.shadow.api.Shadow Java Examples
The following examples show how to use
org.robolectric.shadow.api.Shadow.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FragmentsSelectTest.java From itag with GNU General Public License v3.0 | 6 votes |
@Before public void setupActivity() { Application application = ApplicationProvider.getApplicationContext(); ShadowApplication shadowApplication = shadowOf(application); shadowApplication.grantPermissions(Manifest.permission.ACCESS_FINE_LOCATION); Intent intent = new Intent(application, ITagsService.class); ITagsService iTagsService = new ITagsService(); shadowApplication.setComponentNameAndServiceForBindServiceForIntent( intent, new ComponentName(ITagApplication.class.getPackage().getName(),ITagsService.class.getName()), iTagsService.onBind(null) ); mockBluetoothManager = Mockito.mock(BluetoothManager.class); ShadowContextImpl shadowContext = Shadow.extract(application.getBaseContext()); shadowContext.setSystemService(Context.BLUETOOTH_SERVICE, mockBluetoothManager); }
Example #2
Source File: AnimationViewBehaviorTest.java From simple-view-behavior with MIT License | 6 votes |
@Test public void animations() { ScaleAnimation animation = new ScaleAnimation(1f, 0f, 1f, 0f); AnimationViewBehavior behavior = new AnimationViewBehavior.Builder() .dependsOn(firstView.getId(), SimpleViewBehavior.DEPEND_TYPE_Y) .targetValue(100) .animation(animation) .build(); CoordinatorLayout.LayoutParams params = new CoordinatorLayout.LayoutParams(320, 200); params.setBehavior(behavior); secondView.setLayoutParams(params); ShadowAnimation shadowAnimation = Shadow.extract(animation); firstView.setY(50); coordinatorLayout.requestLayout(); assertEquals(500L, shadowAnimation.getLastTimeGetTransform()); firstView.setY(100); coordinatorLayout.requestLayout(); assertEquals(1000L, shadowAnimation.getLastTimeGetTransform()); }
Example #3
Source File: DrawerActivityLoginTest.java From materialistic with Apache License 2.0 | 6 votes |
@Test public void testAddAccount() { AccountManager.get(activity).addAccountExplicitly(new Account("existing", BuildConfig.APPLICATION_ID), "password", null); drawerAccount.performClick(); AlertDialog alertDialog = ShadowAlertDialog.getLatestAlertDialog(); assertNotNull(alertDialog); assertThat(alertDialog.getListView().getAdapter()).hasCount(1); alertDialog.getButton(DialogInterface.BUTTON_NEGATIVE).performClick(); assertThat(alertDialog).isNotShowing(); ((ShadowSupportDrawerLayout) Shadow.extract(activity.findViewById(R.id.drawer_layout))) .getDrawerListeners().get(0) .onDrawerClosed(activity.findViewById(R.id.drawer)); assertThat(shadowOf(activity).getNextStartedActivity()) .hasComponent(activity, LoginActivity.class); }
Example #4
Source File: WebFragmentTest.java From materialistic with Apache License 2.0 | 6 votes |
@SuppressLint("NewApi") @Test public void testWebControls() { LocalBroadcastManager.getInstance(activity) .sendBroadcast(new Intent(WebFragment.ACTION_FULLSCREEN) .putExtra(WebFragment.EXTRA_FULLSCREEN, true)); ShadowWebView shadowWebView = Shadow.extract(activity.findViewById(R.id.web_view)); activity.findViewById(R.id.button_more).performClick(); shadowOf(ShadowPopupMenu.getLatestPopupMenu()).getOnMenuItemClickListener() .onMenuItemClick(new RoboMenuItem(R.id.menu_zoom_in)); assertThat(shadowWebView.getZoomDegree()).isEqualTo(1); activity.findViewById(R.id.button_more).performClick(); shadowOf(ShadowPopupMenu.getLatestPopupMenu()).getOnMenuItemClickListener() .onMenuItemClick(new RoboMenuItem(R.id.menu_zoom_out)); assertThat(shadowWebView.getZoomDegree()).isEqualTo(0); activity.findViewById(R.id.button_forward).performClick(); assertThat(shadowWebView.getPageIndex()).isEqualTo(1); activity.findViewById(R.id.button_back).performClick(); assertThat(shadowWebView.getPageIndex()).isEqualTo(0); }
Example #5
Source File: WebFragmentTest.java From materialistic with Apache License 2.0 | 6 votes |
@Test public void testDownloadPdf() { ResolveInfo resolverInfo = new ResolveInfo(); resolverInfo.activityInfo = new ActivityInfo(); resolverInfo.activityInfo.applicationInfo = new ApplicationInfo(); resolverInfo.activityInfo.applicationInfo.packageName = ListActivity.class.getPackage().getName(); resolverInfo.activityInfo.name = ListActivity.class.getName(); ShadowPackageManager rpm = shadowOf(RuntimeEnvironment.application.getPackageManager()); when(item.getUrl()).thenReturn("http://example.com/file.pdf"); rpm.addResolveInfoForIntent(new Intent(Intent.ACTION_VIEW, Uri.parse(item.getUrl())), resolverInfo); WebView webView = activity.findViewById(R.id.web_view); ShadowWebView shadowWebView = Shadow.extract(webView); WebFragment fragment = (WebFragment) activity.getSupportFragmentManager() .findFragmentByTag(WebFragment.class.getName()); shadowWebView.getDownloadListener().onDownloadStart(item.getUrl(), "", "", "application/pdf", 0L); shadowWebView.getWebViewClient().onPageFinished(webView, PDF_LOADER_URL); verify(fragment.mFileDownloader).downloadFile( eq(item.getUrl()), eq("application/pdf"), any(FileDownloader.FileDownloaderCallback.class)); }
Example #6
Source File: WebFragmentTest.java From materialistic with Apache License 2.0 | 6 votes |
@Test public void testDownloadContent() { ResolveInfo resolverInfo = new ResolveInfo(); resolverInfo.activityInfo = new ActivityInfo(); resolverInfo.activityInfo.applicationInfo = new ApplicationInfo(); resolverInfo.activityInfo.applicationInfo.packageName = ListActivity.class.getPackage().getName(); resolverInfo.activityInfo.name = ListActivity.class.getName(); ShadowPackageManager rpm = shadowOf(RuntimeEnvironment.application.getPackageManager()); final String url = "http://example.com/file.doc"; rpm.addResolveInfoForIntent(new Intent(Intent.ACTION_VIEW, Uri.parse(url)), resolverInfo); WebView webView = activity.findViewById(R.id.web_view); ShadowWebView shadowWebView = Shadow.extract(webView); when(item.getUrl()).thenReturn(url); shadowWebView.getDownloadListener().onDownloadStart(url, "", "", "", 0L); assertThat((View) activity.findViewById(R.id.empty)).isVisible(); activity.findViewById(R.id.download_button).performClick(); assertNotNull(shadowOf(activity).getNextStartedActivity()); }
Example #7
Source File: AnimationViewBehaviorTest.java From simple-view-behavior with MIT License | 6 votes |
@Test public void animations() { ScaleAnimation animation = new ScaleAnimation(1f, 0f, 1f, 0f); AnimationViewBehavior behavior = new AnimationViewBehavior.Builder() .dependsOn(firstView.getId(), SimpleViewBehavior.DEPEND_TYPE_Y) .targetValue(100) .animation(animation) .build(); CoordinatorLayout.LayoutParams params = new CoordinatorLayout.LayoutParams(320, 200); params.setBehavior(behavior); secondView.setLayoutParams(params); ShadowAnimation shadowAnimation = Shadow.extract(animation); firstView.setY(50); coordinatorLayout.requestLayout(); assertEquals(500L, shadowAnimation.getLastTimeGetTransform()); firstView.setY(100); coordinatorLayout.requestLayout(); assertEquals(1000L, shadowAnimation.getLastTimeGetTransform()); }
Example #8
Source File: BluetoothCentralTest.java From blessed-android with MIT License | 6 votes |
@Before public void setUp() throws Exception { initMocks(this); application = ShadowApplication.getInstance(); bluetoothAdapter = Shadow.extract(ShadowBluetoothLEAdapter.getDefaultAdapter()); bluetoothAdapter.setEnabled(true); bluetoothAdapter.setBluetoothLeScanner(scanner); context = application.getApplicationContext(); // Setup hardware features PackageManager packageManager = context.getPackageManager(); ShadowPackageManager shadowPackageManager = shadowOf(packageManager); shadowPackageManager.setSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE, true); central = new BluetoothCentral(context, callback, handler); }
Example #9
Source File: LocaleChangerShadow.java From adamant-android with GNU General Public License v3.0 | 6 votes |
@Implementation public static void initialize(Context context, List<Locale> supportedLocales, MatchingAlgorithm matchingAlgorithm, LocalePreference preference) { //Block Multiple Initialization Error if (calls.get() == 0) { calls.compareAndSet(0, 1); Shadow.directlyOn( LocaleChanger.class, "initialize", ReflectionHelpers.ClassParameter.from(Context.class, context), ReflectionHelpers.ClassParameter.from(List.class, supportedLocales), ReflectionHelpers.ClassParameter.from(MatchingAlgorithm.class, matchingAlgorithm), ReflectionHelpers.ClassParameter.from(LocalePreference.class, preference) ); } }
Example #10
Source File: PersonTest.java From Awesome-WanAndroid with Apache License 2.0 | 5 votes |
@Test public void ShadowPerson() { Person person = new Person(); Log.d("My Name", person.getName()); Log.d("Age", String.valueOf(person.getAge())); ShadowPerson shadowPerson = Shadow.extract(person); Assert.assertEquals("JsonChao", shadowPerson.getName()); Assert.assertEquals(25, shadowPerson.getAge()); }
Example #11
Source File: BannerImpressionTests.java From mobile-sdk-android with Apache License 2.0 | 5 votes |
@Override public void setup() { super.setup(); connectivityManager = (ConnectivityManager) activity.getSystemService(Context.CONNECTIVITY_SERVICE); // Not using Shadows.shadowOf(connectivityManager) because of Robolectric bug when using API23+ // See: https://github.com/robolectric/robolectric/issues/1862 shadowConnectivityManager = (ShadowConnectivityManager) Shadow.extract(connectivityManager); }
Example #12
Source File: NodeTest.java From BlueSTSDK_Android with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Test public void enableDisableNotificationForFeature(){ SparseArray <Class <? extends Feature> > temp = new SparseArray<>(); temp.append(0x01,FakeFeature.class); try { Manager.addFeatureToNode((byte)0x00,temp); } catch (InvalidFeatureBitMaskException e) { Assert.fail("Impossible add the FakeFeature"); } BluetoothDevice device = spy(Shadow.newInstanceOf(BluetoothDevice.class)); BluetoothDeviceShadow shadowDevice = Shadow.extract(device); BluetoothGattService dataService = new BluetoothGattService( UUID.randomUUID(), BluetoothGattService.SERVICE_TYPE_PRIMARY); dataService.addCharacteristic(createReadNotifyChar( UUID.fromString("000000001-"+BLENodeDefines.FeatureCharacteristics.BASE_FEATURE_COMMON_UUID) )); shadowDevice.addService(dataService); Node n = createNode(device); n.connect(RuntimeEnvironment.application); TestUtil.execAllAsyncTask(); Feature f = n.getFeature(FakeFeature.class); Assert.assertFalse(n.isEnableNotification(f)); Assert.assertTrue(n.enableNotification(f)); Assert.assertTrue(n.isEnableNotification(f)); Assert.assertTrue(n.disableNotification(f)); Assert.assertFalse(n.isEnableNotification(f)); }
Example #13
Source File: NodeTest.java From BlueSTSDK_Android with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Test public void connectNodeWithDebug(){ BluetoothDevice device = spy(Shadow.newInstanceOf(BluetoothDevice.class)); BluetoothDeviceShadow shadowDevice = Shadow.extract(device); BluetoothGattService debugService = new BluetoothGattService(BLENodeDefines.Services .Debug.DEBUG_SERVICE_UUID,BluetoothGattService.SERVICE_TYPE_PRIMARY); debugService.addCharacteristic( new BluetoothGattCharacteristic(BLENodeDefines.Services.Debug.DEBUG_STDERR_UUID, BluetoothGattCharacteristic.PERMISSION_READ | BluetoothGattCharacteristic.PERMISSION_WRITE, BluetoothGattCharacteristic.PROPERTY_READ | BluetoothGattCharacteristic .PROPERTY_NOTIFY)); debugService.addCharacteristic( new BluetoothGattCharacteristic(BLENodeDefines.Services.Debug.DEBUG_TERM_UUID, BluetoothGattCharacteristic.PERMISSION_READ | BluetoothGattCharacteristic.PERMISSION_WRITE, BluetoothGattCharacteristic.PROPERTY_READ | BluetoothGattCharacteristic .PROPERTY_NOTIFY) ); shadowDevice.addService(debugService); Node node = createNode(device); Assert.assertEquals(Node.State.Idle, node.getState()); node.connect(RuntimeEnvironment.application); TestUtil.execAllAsyncTask(); verify(device).connectGatt(eq(RuntimeEnvironment.application), eq(false), any(BluetoothGattCallback.class)); Assert.assertEquals(Node.State.Connected, node.getState()); Assert.assertTrue(node.getDebug()!=null); }
Example #14
Source File: NodeTest.java From BlueSTSDK_Android with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Test public void connectEmptyNode(){ BluetoothDevice device = spy(Shadow.newInstanceOf(BluetoothDevice.class)); Node node = createNode(device); Assert.assertEquals(Node.State.Idle, node.getState()); node.connect(RuntimeEnvironment.application); TestUtil.execAllAsyncTask(); verify(device).connectGatt(eq(RuntimeEnvironment.application), eq(false), any(BluetoothGattCallback.class)); Assert.assertEquals(Node.State.Dead, node.getState()); }
Example #15
Source File: BluetoothDeviceShadow.java From BlueSTSDK_Android with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * open a connection with the device the returning connection is a shadow object that can be * queue with the mockito framework * @param c * @param b * @param callback * @return */ @Implementation public BluetoothGatt connectGatt(Context c,boolean b,BluetoothGattCallback callback){ mGattConnection = spy(Shadow.newInstanceOf(BluetoothGatt.class)); BluetoothGattShadow shadowGatt = Shadow.extract(mGattConnection); shadowGatt.setGattCallBack(callback); shadowGatt.setServices(mServices); mGattConnection.connect(); return mGattConnection; }
Example #16
Source File: ItemActivityTest.java From materialistic with Apache License 2.0 | 5 votes |
@Config(shadows = {ShadowFloatingActionButton.class}) @Test public void testFullscreen() { Intent intent = new Intent(); WebItem webItem = new TestWebItem() { @Override public String getUrl() { return "http://example.com"; } @Override public String getId() { return "1"; } }; intent.putExtra(ItemActivity.EXTRA_ITEM, webItem); controller = Robolectric.buildActivity(ItemActivity.class, intent); controller.create().start().resume().visible(); activity = controller.get(); ShadowFloatingActionButton shadowFab = Shadow.extract(activity.findViewById(R.id.reply_button)); assertTrue(shadowFab.isVisible()); LocalBroadcastManager.getInstance(activity) .sendBroadcast(new Intent(WebFragment.ACTION_FULLSCREEN) .putExtra(WebFragment.EXTRA_FULLSCREEN, true)); assertFalse(shadowFab.isVisible()); LocalBroadcastManager.getInstance(activity) .sendBroadcast(new Intent(WebFragment.ACTION_FULLSCREEN) .putExtra(WebFragment.EXTRA_FULLSCREEN, false)); assertTrue(shadowFab.isVisible()); }
Example #17
Source File: DrawerActivityLoginTest.java From materialistic with Apache License 2.0 | 5 votes |
@Test public void testOpenUserProfile() { Preferences.setUsername(activity, "username"); drawerUser.performClick(); ((ShadowSupportDrawerLayout) Shadow.extract(activity.findViewById(R.id.drawer_layout))) .getDrawerListeners().get(0) .onDrawerClosed(activity.findViewById(R.id.drawer)); assertThat(shadowOf(activity).getNextStartedActivity()) .hasComponent(activity, UserActivity.class) .hasExtra(UserActivity.EXTRA_USERNAME, "username"); }
Example #18
Source File: WebFragmentTest.java From materialistic with Apache License 2.0 | 5 votes |
@Test public void testFullScroll() { LocalBroadcastManager.getInstance(activity) .sendBroadcast(new Intent(WebFragment.ACTION_FULLSCREEN) .putExtra(WebFragment.EXTRA_FULLSCREEN, true)); ShadowWebView shadowWebView = Shadow.extract(activity.findViewById(R.id.web_view)); WebFragment fragment = (WebFragment) activity.getSupportFragmentManager() .findFragmentByTag(WebFragment.class.getName()); fragment.scrollToTop(); assertEquals(0, shadowWebView.getScrollY()); fragment.scrollToNext(); assertEquals(1, shadowWebView.getScrollY()); fragment.scrollToPrevious(); assertEquals(0, shadowWebView.getScrollY()); }
Example #19
Source File: MapTest.java From appinventor-extensions with Apache License 2.0 | 5 votes |
@Test public void testShowCompass() { /* We need to create a sensor for the orientation type, otherwise compass will fail to enable */ Context context = RuntimeEnvironment.application.getApplicationContext(); ShadowSensorManager sensorManager = Shadow.extract(context.getSystemService(Context.SENSOR_SERVICE)); Sensor s = Shadow.newInstanceOf(Sensor.class); sensorManager.addSensor(Sensor.TYPE_ORIENTATION, s); /* end setup */ map.ShowCompass(true); assertTrue(map.ShowCompass()); }
Example #20
Source File: WebFragmentTest.java From materialistic with Apache License 2.0 | 5 votes |
@Test public void testRefresh() { LocalBroadcastManager.getInstance(activity) .sendBroadcast(new Intent(WebFragment.ACTION_FULLSCREEN) .putExtra(WebFragment.EXTRA_FULLSCREEN, true)); ShadowWebView.lastGlobalLoadedUrl = null; ShadowWebView shadowWebView = Shadow.extract(activity.findViewById(R.id.web_view)); shadowWebView.setProgress(20); activity.findViewById(R.id.button_refresh).performClick(); assertThat(ShadowWebView.getLastGlobalLoadedUrl()).isNullOrEmpty(); shadowWebView.setProgress(100); activity.findViewById(R.id.button_refresh).performClick(); assertThat(ShadowWebView.getLastGlobalLoadedUrl()).isEqualTo(ShadowWebView.RELOADED); }
Example #21
Source File: WebFragmentTest.java From materialistic with Apache License 2.0 | 5 votes |
@Test public void testSearch() { LocalBroadcastManager.getInstance(activity) .sendBroadcast(new Intent(WebFragment.ACTION_FULLSCREEN) .putExtra(WebFragment.EXTRA_FULLSCREEN, true)); activity.findViewById(R.id.button_find).performClick(); ViewSwitcher controlSwitcher = activity.findViewById(R.id.control_switcher); assertThat(controlSwitcher.getDisplayedChild()).isEqualTo(1); ShadowWebView shadowWebView = Shadow.extract(activity.findViewById(R.id.web_view)); // no query EditText editText = activity.findViewById(R.id.edittext); shadowOf(editText).getOnEditorActionListener().onEditorAction(null, 0, null); assertThat((View) activity.findViewById(R.id.button_next)).isDisabled(); // with results shadowWebView.setFindCount(1); editText.setText("abc"); shadowOf(editText).getOnEditorActionListener().onEditorAction(null, 0, null); assertThat((View) activity.findViewById(R.id.button_next)).isEnabled(); activity.findViewById(R.id.button_next).performClick(); assertThat(shadowWebView.getFindIndex()).isEqualTo(1); activity.findViewById(R.id.button_clear).performClick(); assertThat(editText).isEmpty(); assertThat(controlSwitcher.getDisplayedChild()).isEqualTo(0); // with no results shadowWebView.setFindCount(0); editText.setText("abc"); shadowOf(editText).getOnEditorActionListener().onEditorAction(null, 0, null); assertThat((View) activity.findViewById(R.id.button_next)).isDisabled(); assertThat(ShadowToast.getTextOfLatestToast()).contains(activity.getString(R.string.no_matches)); }
Example #22
Source File: MapTest.java From appinventor-extensions with Apache License 2.0 | 5 votes |
@Test public void testFeatureListRemoval() { Marker marker1 = new Marker(map); Marker marker2 = new Marker(map); ((ShadowView) Shadow.extract(map.getView())).clearWasInvalidated(); map.Features(YailList.makeList(Collections.singletonList(marker1))); assertTrue(((ShadowView) Shadow.extract(map.getView())).wasInvalidated()); assertEquals(1, map.Features().size()); assertTrue(map.Features().contains(marker1)); assertFalse(map.Features().contains(marker2)); }
Example #23
Source File: FeatureCollectionTest.java From appinventor-extensions with Apache License 2.0 | 5 votes |
@Test public void testFeatureSetter() { Marker marker = new Marker(getMap()); collection.removeFeature(marker); assertEquals(0, collection.Features().size()); ShadowView view = Shadow.extract(getMap().getView()); view.clearWasInvalidated(); collection.Features(YailList.makeList(Collections.singletonList(marker))); assertTrue(view.wasInvalidated()); assertEquals(1, collection.Features().size()); assertEquals(marker, collection.Features().get(1)); }
Example #24
Source File: OfflineWebActivityTest.java From materialistic with Apache License 2.0 | 5 votes |
@Test public void testScrollToTop() { controller = Robolectric.buildActivity(OfflineWebActivity.class, new Intent() .putExtra(OfflineWebActivity.EXTRA_URL, "http://example.com")); activity = controller .create() .start() .resume() .visible() .get(); activity.findViewById(R.id.toolbar).performClick(); assertThat(((ShadowNestedScrollView) Shadow .extract(activity.findViewById(R.id.nested_scroll_view))).getSmoothScrollY()) .isEqualTo(0); }
Example #25
Source File: DrawerActivityTest.java From materialistic with Apache License 2.0 | 5 votes |
@Test public void test() { ((ShadowSupportDrawerLayout) Shadow.extract(activity.findViewById(R.id.drawer_layout))) .getDrawerListeners().get(0) .onDrawerClosed(activity.findViewById(R.id.drawer)); assertNull(shadowOf(activity).getNextStartedActivity()); activity.findViewById(drawerResId).performClick(); ((ShadowSupportDrawerLayout) Shadow.extract(activity.findViewById(R.id.drawer_layout))) .getDrawerListeners().get(0) .onDrawerClosed(activity.findViewById(R.id.drawer)); assertEquals(startedActivity.getName(), shadowOf(activity).getNextStartedActivity().getComponent().getClassName()); }
Example #26
Source File: FeatureCollectionTest.java From appinventor-extensions with Apache License 2.0 | 5 votes |
private void testFeatureListSetter(MapFeature feature) { ShadowView view = Shadow.extract(getMap().getView()); view.clearWasInvalidated(); collection.Features(YailList.makeList(Collections.singletonList(feature))); assertTrue(view.wasInvalidated()); assertEquals(1, collection.Features().size()); assertEquals(feature, collection.Features().get(1)); }
Example #27
Source File: SnackbarTest.java From material-components-android with Apache License 2.0 | 5 votes |
@Before public void createActivityAndShadow() { ApplicationProvider.getApplicationContext() .setTheme(R.style.Theme_MaterialComponents_Light_NoActionBar); activity = Robolectric.buildActivity(AppCompatActivity.class).create().get(); accessibilityManager = Shadow. extract(activity.getSystemService(Context.ACCESSIBILITY_SERVICE)); }
Example #28
Source File: WebFragmentTest.java From materialistic with Apache License 2.0 | 5 votes |
@Test public void testFullscreenScrollToTop() { activity.findViewById(R.id.toolbar_web).performClick(); assertEquals(-1, ((ShadowWebView) Shadow.extract(activity.findViewById(R.id.web_view))) .getScrollY()); }
Example #29
Source File: GlyphWarmerImplTest.java From TextLayoutBuilder with Apache License 2.0 | 5 votes |
@Before public void setup() { MockitoAnnotations.initMocks(this); mGlyphWarmerImpl = new GlyphWarmerImpl(); mShadowLooper = (ShadowLooper) Shadow.extract(mGlyphWarmerImpl.getWarmHandlerLooper()); }
Example #30
Source File: PushNotificationRegistrationTest.java From pusher-websocket-android with MIT License | 5 votes |
@Test public void testRegisterGCMStartsBroadcastManagerAndIntentService() throws ManifestValidator.InvalidManifestException { registration.registerGCM(context, "senderId", registrationListener); Intent expectedIntent = new Intent(context, GCMRegistrationIntentService.class); Intent startedIntent = shadowOf(RuntimeEnvironment.application).getNextStartedService(); assertThat(startedIntent.getComponent(), equalTo(expectedIntent.getComponent())); Bundle extras = startedIntent.getExtras(); assertEquals("senderId", extras.getString("gcm_defaultSenderId")); ShadowLocalBroadcastManager localBroadcastManager = (ShadowLocalBroadcastManager) Shadow.extract(LocalBroadcastManager.getInstance(context)); List<ShadowLocalBroadcastManager.Wrapper> receivers = localBroadcastManager.getRegisteredBroadcastReceivers(); assertEquals(1, receivers.size()); }