本文整理汇总了Java中org.robolectric.shadows.ShadowLooper类的典型用法代码示例。如果您正苦于以下问题:Java ShadowLooper类的具体用法?Java ShadowLooper怎么用?Java ShadowLooper使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ShadowLooper类属于org.robolectric.shadows包,在下文中一共展示了ShadowLooper类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onUnsubscribePostsOffMainThread
import org.robolectric.shadows.ShadowLooper; //导入依赖的package包/类
@Test public void onUnsubscribePostsOffMainThread() throws InterruptedException {
ShadowLooper.pauseMainLooper();
final CountDownLatch latch = new CountDownLatch(1);
final AtomicBoolean called = new AtomicBoolean();
new Thread(new Runnable() {
@Override public void run() {
new MainThreadDisposable() {
@Override protected void onDispose() {
called.set(true);
}
}.dispose();
latch.countDown();
}
}).start();
assertTrue(latch.await(1, SECONDS));
assertFalse(called.get()); // Callback has not yet run.
ShadowLooper.runMainLooperOneTask();
assertTrue(called.get());
}
示例2: testServerEventDisconnected
import org.robolectric.shadows.ShadowLooper; //导入依赖的package包/类
/**
* Test that disconnection from server is properly recognized.
*/
@Test
public void testServerEventDisconnected() throws InterruptedException {
ShadowBluetoothSocket.setTransmittedString(SERVER_VERSION_SUCCESS);
final CountDownLatch messageReceived = new CountDownLatch(1);
control = new BluetoothPresenterControl(new Handler() {
@Override
public void handleMessage(Message msg) {
if (msg.what == RemoteControl.ServiceState.NONE.ordinal()) {
messageReceived.countDown();
}
}
});
BluetoothDevice bluetoothDevice = ShadowBluetoothAdapter.getDefaultAdapter()
.getRemoteDevice(DEVICE_ADDRESS);
control.connect(bluetoothDevice);
waitForServiceStateChanged(control, RemoteControl.ServiceState.CONNECTED);
ShadowBluetoothSocket.setFailReading(true);
waitForServiceStateChanged(control, RemoteControl.ServiceState.NONE);
ShadowLooper.runUiThreadTasks();
assertThat("Handler was not called",
messageReceived.await(MESSAGE_RECEIVING_TIMEOUT, TimeUnit.MILLISECONDS), is(true));
}
示例3: uiShouldNotCallActionUntilMainThreadIsPaused
import org.robolectric.shadows.ShadowLooper; //导入依赖的package包/类
@Test
public void uiShouldNotCallActionUntilMainThreadIsPaused() throws Exception {
// WHEN have UI action
Consumer<String> uiAction = mock(Consumer.class);
// AND produce binder func
Function<Observable<String>, Disposable> binderFunc = RxUi.ui(uiAction);
// AND main thread is paused
ShadowLooper.pauseMainLooper();
// AND bind Observable via binder func
binderFunc.apply(Observable.just("a", "b", "c"));
// THEN action should not be called until main thread is paused
verifyZeroInteractions(uiAction);
}
示例4: uiShouldPreventCallsToActionIfUnsubscribedBeforeExecution
import org.robolectric.shadows.ShadowLooper; //导入依赖的package包/类
@Test
public void uiShouldPreventCallsToActionIfUnsubscribedBeforeExecution() throws Exception {
// WHEN have UI action
Consumer<String> uiAction = mock(Consumer.class);
// AND produce binder func
Function<Observable<String>, Disposable> binderFunc = RxUi.ui(uiAction);
// AND pause Main Thread
ShadowLooper.pauseMainLooper();
// AND bind Observable via binder func
Disposable disposable = binderFunc.apply(Observable.just("a", "b", "c"));
// AND dispose Disposable
disposable.dispose();
// AND resume Main Thread
ShadowLooper.runUiThreadTasksIncludingDelayedTasks();
// THEN no calls to uiAction are expected
verifyZeroInteractions(uiAction);
}
示例5: testWaitForFinishedDelayed
import org.robolectric.shadows.ShadowLooper; //导入依赖的package包/类
@Test
public void testWaitForFinishedDelayed() {
CircleFlow engine = CircleFlow.getInternalInstance();
engine.injectServiceBuilder(new FlowServiceBuilderMock());
FlowExecutor executor = engine.prepareFlow(new Flow1());
executor.execute();
FlowContext context = engine.getLifecycleService().getFlowContext(executor.getFlowId());
Assert.assertEquals(FlowContext.STATUS_STARTED, context.getCurrentStatus());
DelayThread.delayRun(new Runnable() {
@Override
public void run() {
ShadowLooper.unPauseMainLooper();
}
});
context = executor.waitForFinished();
Assert.assertEquals(FlowContext.STATUS_ENDED, context.getCurrentStatus());
Assert.assertEquals(0, context.getCurrentNodes().size());
}
示例6: testLastUpdated
import org.robolectric.shadows.ShadowLooper; //导入依赖的package包/类
@Test
public void testLastUpdated() {
String expected = activity.getString(R.string.last_updated,
DateUtils.getRelativeTimeSpanString(System.currentTimeMillis(),
System.currentTimeMillis(),
DateUtils.MINUTE_IN_MILLIS,
DateUtils.FORMAT_ABBREV_ALL));
activity.onRefreshed();
assertThat(activity.getSupportActionBar()).hasSubtitle(expected);
activity.getSupportActionBar().setSubtitle(null);
ShadowLooper.runUiThreadTasksIncludingDelayedTasks();
assertThat(activity.getSupportActionBar()).hasSubtitle(expected);
activity.getSupportActionBar().setSubtitle(null);
controller.pause().resume();
assertThat(activity.getSupportActionBar()).hasSubtitle(expected);
Bundle savedState = new Bundle();
activity.onSaveInstanceState(savedState);
controller = Robolectric.buildActivity(TestListActivity.class);
activity = controller.create(savedState).postCreate(null).start().resume().visible().get();
assertThat(activity.getSupportActionBar()).hasSubtitle(expected);
}
示例7: setUp
import org.robolectric.shadows.ShadowLooper; //导入依赖的package包/类
@Before
public void setUp() {
initMocks(this);
//noinspection ConstantConditions
scheduler = ((ShadowLooper) extract(myLooper())).getScheduler();
updateDispatcherWithUpdatablesChanged = updateDispatcher(mockActivationHandler);
updateDispatcher = updateDispatcher();
firstUpdateDispatcher = updateDispatcher();
secondUpdateDispatcher = updateDispatcher();
thirdUpdateDispatcher = updateDispatcher();
trueConditionalObservable = conditionalObservable(trueCondition(), firstUpdateDispatcher);
falseConditionalObservable = conditionalObservable(falseCondition(), firstUpdateDispatcher);
compositeObservableOfMany = compositeObservable(firstUpdateDispatcher,
secondUpdateDispatcher);
chainedCompositeObservableOfOne = compositeObservable(
compositeObservable(firstUpdateDispatcher));
chainedCompositeObservable = compositeObservable(compositeObservable(firstUpdateDispatcher,
secondUpdateDispatcher), thirdUpdateDispatcher);
chainedDupeCompositeObservable = compositeObservable(firstUpdateDispatcher,
compositeObservable(firstUpdateDispatcher, secondUpdateDispatcher),
secondUpdateDispatcher, thirdUpdateDispatcher);
updatable = mockUpdatable();
secondUpdatable = mockUpdatable();
looper = getShadowMainLooper();
}
示例8: reset
import org.robolectric.shadows.ShadowLooper; //导入依赖的package包/类
public static void reset(Config config) {
Robolectric.application = null;
Robolectric.packageManager = null;
Robolectric.activityThread = null;
ShadowLooper.resetThreadLoopers();
ShadowChoreographer.resetThreadLoopers();
List<Class<?>> klasses = Lists.newArrayList();
klasses.addAll(Arrays.asList(Robolectric.DEFAULT_SHADOW_CLASSES));
klasses.addAll(Arrays.asList(config.shadows()));
for (Class<?> klass : klasses) {
if (klass.getAnnotation(Implements.class).resetStaticState()) {
staticMethod("reset").in(klass).invoke();
}
}
}
示例9: currentActivity
import org.robolectric.shadows.ShadowLooper; //导入依赖的package包/类
@Test
public void currentActivity() throws Exception {
/* now select an activity */
DiaryActivity someAct = new DiaryActivity(1, "Test", Color.BLACK);
ActivityHelper.helper.insertActivity(someAct);
assertNotNull(someAct);
ActivityHelper.helper.setCurrentActivity(someAct);
assertEquals(ActivityHelper.helper.getCurrentActivity(), someAct);
MainActivity activity = Robolectric.setupActivity(MainActivity.class);
View card = activity.findViewById(R.id.card);
TextView nameView = (TextView) card.findViewById(R.id.activity_name);
assertNotNull("Current activity Text available", nameView);
assertEquals(nameView.getText(), "Test");
FloatingActionButton fabNoteEdit = (FloatingActionButton) activity.findViewById(R.id.fab_edit_note);
FloatingActionButton fabAttachPicture = (FloatingActionButton) activity.findViewById(R.id.fab_attach_picture);
assertNotNull("we have two FABs", fabNoteEdit);
assertNotNull("we have two FABs", fabAttachPicture);
fabNoteEdit.performClick();
DialogFragment dialogFragment = (DialogFragment) activity.getSupportFragmentManager()
.findFragmentByTag("NoteEditDialogFragment");
assertNotNull(dialogFragment);
ShadowLooper.idleMainLooper(100, TimeUnit.MILLISECONDS);
assertNull(ShadowToast.getTextOfLatestToast());
fabAttachPicture.performClick();
ShadowLooper.idleMainLooper(100, TimeUnit.MILLISECONDS);
assertNull(ShadowToast.getTextOfLatestToast());
}
示例10: testOnResourceReadyPassedToCallbacks
import org.robolectric.shadows.ShadowLooper; //导入依赖的package包/类
@Test
public void testOnResourceReadyPassedToCallbacks() throws Exception {
EngineJob<Object> job = harness.getJob();
job.start(harness.decodeJob);
job.onResourceReady(harness.resource, harness.dataSource);
ShadowLooper.runUiThreadTasks();
verify(harness.cb).onResourceReady(eq(harness.engineResource), eq(harness.dataSource));
}
示例11: testListenerNotifiedJobCompleteOnOnResourceReady
import org.robolectric.shadows.ShadowLooper; //导入依赖的package包/类
@Test
public void testListenerNotifiedJobCompleteOnOnResourceReady() {
EngineJob<Object> job = harness.getJob();
job.start(harness.decodeJob);
job.onResourceReady(harness.resource, harness.dataSource);
ShadowLooper.runUiThreadTasks();
verify(harness.listener).onEngineJobComplete(eq(harness.key), eq(harness.engineResource));
}
示例12: testListenerNotifiedJobCompleteOnException
import org.robolectric.shadows.ShadowLooper; //导入依赖的package包/类
@Test
public void testListenerNotifiedJobCompleteOnException() {
harness = new EngineJobHarness();
EngineJob<Object> job = harness.getJob();
job.start(harness.decodeJob);
job.onLoadFailed(new GlideException("test"));
ShadowLooper.runUiThreadTasks();
verify(harness.listener).onEngineJobComplete(eq(harness.key), isNull(EngineResource.class));
}
示例13: testResourceIsCacheableWhenIsCacheableOnReady
import org.robolectric.shadows.ShadowLooper; //导入依赖的package包/类
@Test
public void testResourceIsCacheableWhenIsCacheableOnReady() {
harness.isCacheable = true;
EngineJob<Object> job = harness.getJob();
job.start(harness.decodeJob);
job.onResourceReady(harness.resource, harness.dataSource);
ShadowLooper.runUiThreadTasks();
verify(harness.factory).build(anyResource(), eq(harness.isCacheable));
}
示例14: testResourceIsCacheableWhenNotIsCacheableOnReady
import org.robolectric.shadows.ShadowLooper; //导入依赖的package包/类
@Test
public void testResourceIsCacheableWhenNotIsCacheableOnReady() {
harness.isCacheable = false;
EngineJob<Object> job = harness.getJob();
job.start(harness.decodeJob);
job.onResourceReady(harness.resource, harness.dataSource);
ShadowLooper.runUiThreadTasks();
verify(harness.factory).build(anyResource(), eq(harness.isCacheable));
}
示例15: testOnResourceReadyNotDeliveredAfterCancel
import org.robolectric.shadows.ShadowLooper; //导入依赖的package包/类
@Test
public void testOnResourceReadyNotDeliveredAfterCancel() {
EngineJob<Object> job = harness.getJob();
job.start(harness.decodeJob);
job.cancel();
job.onResourceReady(harness.resource, harness.dataSource);
ShadowLooper.runUiThreadTasks();
verify(harness.cb, never()).onResourceReady(anyResource(), isADataSource());
}