/** * Return the foreground scheduler (e.g. the UI thread scheduler). * * @return Foreground scheduler. */ public static Scheduler getForegroundThreadScheduler() { return ShadowApplication.getInstance().getForegroundThreadScheduler(); }
@Test public void testReturnsDefaultConnectivityMonitorWhenHasPermission() { ShadowApplication.getInstance().grantPermissions("android.permission.ACCESS_NETWORK_STATE"); ConnectivityMonitor connectivityMonitor = factory.build(RuntimeEnvironment.application, mock(ConnectivityMonitor.ConnectivityListener.class)); assertThat(connectivityMonitor).isInstanceOf(DefaultConnectivityMonitor.class); }
@Test public void startActivities_shouldStartAllActivities() { final Intent view = new Intent(Intent.ACTION_VIEW).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); final Intent pick = new Intent(Intent.ACTION_PICK).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); contextWrapper.startActivities(new Intent[] {view, pick}); assertThat(ShadowApplication.getInstance().getNextStartedActivity()).isEqualTo(pick); assertThat(ShadowApplication.getInstance().getNextStartedActivity()).isEqualTo(view); }
/** * Return the background scheduler. * * @return Background scheduler. */ public static Scheduler getBackgroundThreadScheduler() { return ShadowApplication.getInstance().getBackgroundThreadScheduler(); }
@Implementation protected static LocalBroadcastManager getInstance(final Context context) { return ShadowApplication.getInstance().getSingleton(LocalBroadcastManager.class, new Provider<LocalBroadcastManager>() { @Override public LocalBroadcastManager get() { return ReflectionHelpers.callConstructor(LocalBroadcastManager.class, ClassParameter.from(Context.class, context)); } }); }
ShadowApplication.getInstance().grantPermissions(permission); ShadowApplication.getInstance().denyPermissions(permission);
@Implementation protected PowerManager.WakeLock newWakeLock(int flags, String tag) { PowerManager.WakeLock wl = Shadow.newInstanceOf(PowerManager.WakeLock.class); getInstance().addWakeLock(wl); return wl; }
private void grantPermissions(String[] perms) { shadowApp.grantPermissions(perms); }
public void denyPermissions(String... permissionNames) { ShadowApplication.getInstance().denyPermissions(permissionNames); } }
@Before public void setUp() throws RemoteException { controller = Robolectric.buildActivity(Activity.class); activity = controller.create().get(); delegate = new CustomTabsDelegate(); service = mock(ICustomTabsService.class); when(service.newSession(any(ICustomTabsCallback.class))).thenReturn(true); IBinder binder = mock(IBinder.class); when(binder.queryLocalInterface(any())).thenReturn(service); ShadowApplication.getInstance() .setComponentNameAndServiceForBindService(mock(ComponentName.class), binder); }
/** Discards the most recent {@code PowerManager.WakeLock}s */ @Resetter public static void reset() { ShadowApplication shadowApplication = ShadowApplication.getInstance(); if (shadowApplication != null) { shadowApplication.clearWakeLocks(); } }
@Test public void setUpApplicationState_setsBackgroundScheduler_toBeDifferentToForeground_byDefault() { bootstrapWrapper.callSetUpApplicationState(); final ShadowApplication shadowApplication = Shadow.extract(ApplicationProvider.getApplicationContext()); assertThat(shadowApplication.getBackgroundThreadScheduler()) .isNotSameAs(shadowApplication.getForegroundThreadScheduler()); }
@Implementation protected void invokePopup(WindowManager.LayoutParams p) { ShadowApplication.getInstance().setLatestPopupWindow(realPopupWindow); directlyOn(realPopupWindow, PopupWindow.class, "invokePopup", ReflectionHelpers.ClassParameter.from(WindowManager.LayoutParams.class, p)); } }
private List<BroadcastReceiver> getConnectivityReceivers() { Intent connectivity = new Intent(ConnectivityManager.CONNECTIVITY_ACTION); return ShadowApplication.getInstance().getReceiversForIntent(connectivity); }
@Test public void startIntentSender_activityIntent() throws IntentSender.SendIntentException { PendingIntent intent = PendingIntent.getActivity( context, 0, new Intent() .setClassName(context, "ActivityIntent") .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK), PendingIntent.FLAG_UPDATE_CURRENT); context.startIntentSender(intent.getIntentSender(), null, 0, 0, 0); assertThat(shadowOf(context).getNextStartedActivity().getComponent().getClassName()) .isEqualTo("ActivityIntent"); }
@Test @Config(minSdk = VERSION_CODES.O) public void startForegroundService() { Intent intent = new Intent(); context.startForegroundService(intent); assertThat(ShadowApplication.getInstance().getNextStartedService()).isEqualTo(intent); }
@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 getLatestPopupWindow() { PopupWindow pw = new PopupWindow(new LinearLayout(context)); pw.showAtLocation(new LinearLayout(context), Gravity.CENTER, 0, 0); PopupWindow latestPopupWindow = ShadowApplication.getInstance().getLatestPopupWindow(); assertThat(latestPopupWindow).isSameAs(pw); }
protected Context instance() { ShadowApplication shadowApp = Shadows.shadowOf(this); shadowApp.grantPermissions("android.permission.INTERNET"); return shadowApp.getApplicationContext(); }
@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(); }