/** * Return the background scheduler. * * @return Background scheduler. */ public static Scheduler getBackgroundThreadScheduler() { return ShadowApplication.getInstance().getBackgroundThreadScheduler(); }
public RoboExecutorService() { this.scheduler = ShadowApplication.getInstance().getBackgroundThreadScheduler(); }
/** * Runs any background tasks previously queued by {@link android.os.AsyncTask#execute(Object[])}. * * Note: calling this method does not pause or un-pause the scheduler. */ public static void runBackgroundTasks() { getInstance().getBackgroundThreadScheduler().advanceBy(0); }
@Implementation protected void onForceLoad() { FutureTask<D> future = new FutureTask<D>(worker) { @Override protected void done() { try { final D result = get(); ShadowApplication.getInstance().getForegroundThreadScheduler().post(new Runnable() { @Override public void run() { realObject.deliverResult(result); } }); } catch (InterruptedException e) { // Ignore } catch (ExecutionException e) { throw new RuntimeException(e.getCause()); } } }; ShadowApplication.getInstance().getBackgroundThreadScheduler().post(future); }
@Implementation protected AsyncTask<Params, Progress, Result> execute(final Params... params) { status = AsyncTask.Status.RUNNING; getBridge().onPreExecute(); worker.params = params; ShadowApplication.getInstance().getBackgroundThreadScheduler().post(new Runnable() { @Override public void run() { future.run(); } }); return realAsyncTask; }
@Test public void getBackgroundThreadScheduler_shouldDifferFromRuntimeEnvironment_withAdvancedScheduling() { Scheduler s = new Scheduler(); RuntimeEnvironment.setMasterScheduler(s); final ShadowApplication shadowApplication = Shadows.shadowOf(context); assertThat(shadowApplication.getBackgroundThreadScheduler()).isNotSameAs(s); }
@Test public void getThreadScheduler_shouldMatchRobolectricValue() { final ShadowApplication shadowApplication = Shadows.shadowOf(context); assertThat(shadowApplication.getForegroundThreadScheduler()).isSameAs(Robolectric.getForegroundThreadScheduler()); assertThat(shadowApplication.getBackgroundThreadScheduler()).isSameAs(Robolectric.getBackgroundThreadScheduler()); }
@Test public void setUpApplicationState_setsBackgroundScheduler_toBeDifferentToForeground_byDefault() { bootstrapWrapper.callSetUpApplicationState(); final ShadowApplication shadowApplication = Shadow.extract(ApplicationProvider.getApplicationContext()); assertThat(shadowApplication.getBackgroundThreadScheduler()) .isNotSameAs(shadowApplication.getForegroundThreadScheduler()); }
@Test public void getBackgroundThreadScheduler_shouldDifferFromRuntimeEnvironment_byDefault() { Scheduler s = new Scheduler(); RuntimeEnvironment.setMasterScheduler(s); final ShadowApplication shadowApplication = Shadows.shadowOf(context); assertThat(shadowApplication.getBackgroundThreadScheduler()).isNotSameAs(RuntimeEnvironment.getMasterScheduler()); }
@Test public void setUpApplicationState_setsBackgroundScheduler_toBeSameAsForeground_whenAdvancedScheduling() { RoboSettings.setUseGlobalScheduler(true); try { bootstrapWrapper.callSetUpApplicationState(); final ShadowApplication shadowApplication = Shadow.extract(ApplicationProvider.getApplicationContext()); assertThat(shadowApplication.getBackgroundThreadScheduler()) .isSameAs(shadowApplication.getForegroundThreadScheduler()); assertThat(RuntimeEnvironment.getMasterScheduler()) .isSameAs(RuntimeEnvironment.getMasterScheduler()); } finally { RoboSettings.setUseGlobalScheduler(false); } }
/** * Return the background scheduler. * * @return Background scheduler. */ public static Scheduler getBackgroundThreadScheduler() { return ShadowApplication.getInstance().getBackgroundThreadScheduler(); }
@Override public Scheduler getBackgroundScheduler() { return ShadowApplication.getInstance().getBackgroundThreadScheduler(); }
/** * Runs any background tasks previously queued by {@link android.os.AsyncTask#execute(Object[])}. * * Note: calling this method does not pause or un-pause the scheduler. */ public static void runBackgroundTasks() { getInstance().getBackgroundThreadScheduler().advanceBy(0); }
/** * Runs any background tasks previously queued by {@link android.os.AsyncTask#execute(Object[])}. * * <p> * Note: calling this method does not pause or un-pause the scheduler. */ public static void runBackgroundTasks() { getInstance().getBackgroundThreadScheduler().advanceBy(0); }
/** * Runs any background tasks previously queued by {@link android.os.AsyncTask#execute(Object[])}. * * <p> * Note: calling this method does not pause or un-pause the scheduler. */ public static void runBackgroundTasks() { getInstance().getBackgroundThreadScheduler().advanceBy(0); }
/** * Runs any background tasks previously queued by {@link android.os.AsyncTask#execute(Object[])}. * * Note: calling this method does not pause or un-pause the scheduler. */ public static void runBackgroundTasks() { getInstance().getBackgroundThreadScheduler().advanceBy(0); }
@Implementation public void onForceLoad() { ShadowApplication.getInstance().getBackgroundThreadScheduler().post(new Runnable() { @Override public void run() { future.run(); } }); }
@Implementation public void onForceLoad() { ShadowApplication.getInstance().getBackgroundThreadScheduler().post(new Runnable() { @Override public void run() { future.run(); } }); }
@Implementation public void onForceLoad() { ShadowApplication.getInstance().getBackgroundThreadScheduler().post(new Runnable() { @Override public void run() { future.run(); } }); }
@Implementation protected AsyncTask<Params, Progress, Result> execute(final Params... params) { status = AsyncTask.Status.RUNNING; getBridge().onPreExecute(); worker.params = params; ShadowApplication.getInstance().getBackgroundThreadScheduler().post(new Runnable() { @Override public void run() { future.run(); } }); return realAsyncTask; }