use of org.robolectric.util.Scheduler in project robolectric by robolectric.
the class ShadowLegacyMessageTest method recycle_shouldRemoveMessageFromScheduler.
private void recycle_shouldRemoveMessageFromScheduler() {
ShadowLooper.pauseMainLooper();
Handler h = new Handler();
Message msg = Message.obtain(h, 234);
msg.sendToTarget();
Scheduler scheduler = Robolectric.getForegroundThreadScheduler();
assertWithMessage("before recycle").that(scheduler.size()).isEqualTo(1);
shadowOf(msg).recycleUnchecked();
assertWithMessage("after recycle").that(scheduler.size()).isEqualTo(0);
}
use of org.robolectric.util.Scheduler in project robolectric by robolectric.
the class ShadowLegacyLooperTest method shouldSetNewScheduler_whenLooperIsReset.
@Test
public void shouldSetNewScheduler_whenLooperIsReset() {
HandlerThread ht = getHandlerThread();
Looper looper = ht.getLooper();
ShadowLooper sLooper = shadowOf(looper);
Scheduler old = sLooper.getScheduler();
sLooper.reset();
assertThat(old).isNotSameInstanceAs(sLooper.getScheduler());
}
use of org.robolectric.util.Scheduler in project robolectric by robolectric.
the class ShadowLegacyLooperTest method reset_setsSchedulerToMaster_forNonMainLooper_withAdvancedScheduling.
@Test
public void reset_setsSchedulerToMaster_forNonMainLooper_withAdvancedScheduling() {
HandlerThread ht = getHandlerThread();
ShadowLooper sLooper = shadowOf(ht.getLooper());
Scheduler s = new Scheduler();
RuntimeEnvironment.setMasterScheduler(s);
setAdvancedScheduling();
sLooper.reset();
assertThat(sLooper.getScheduler()).isSameInstanceAs(s);
}
use of org.robolectric.util.Scheduler in project robolectric by robolectric.
the class ShadowLegacyLooperTest method reset_setsGlobalScheduler_forMainLooper_withAdvancedScheduling.
@Test
public void reset_setsGlobalScheduler_forMainLooper_withAdvancedScheduling() {
setAdvancedScheduling();
ShadowLooper sMainLooper = ShadowLooper.getShadowMainLooper();
Scheduler s = new Scheduler();
RuntimeEnvironment.setMasterScheduler(s);
sMainLooper.reset();
assertThat(sMainLooper.getScheduler()).isSameInstanceAs(s);
}
use of org.robolectric.util.Scheduler in project androidannotations by androidannotations.
the class SupposeThreadTest method testSupposeUiAndUi.
@Test
public void testSupposeUiAndUi() throws Exception {
Scheduler scheduler = Robolectric.getForegroundThreadScheduler();
final AtomicBoolean run = new AtomicBoolean(false);
scheduler.pause();
bean.uiSupposedAndUi(new Runnable() {
@Override
public void run() {
run.set(true);
}
});
if (run.get()) {
throw new IllegalStateException("Runnable wasn't post through handler, but was invoked");
}
scheduler.unPause();
scheduler.advanceToLastPostedRunnable();
if (!run.get()) {
throw new IllegalStateException("Runnable wasn't invoked");
}
}
Aggregations