本文整理汇总了Java中org.robolectric.shadows.ShadowLooper.runUiThreadTasks方法的典型用法代码示例。如果您正苦于以下问题:Java ShadowLooper.runUiThreadTasks方法的具体用法?Java ShadowLooper.runUiThreadTasks怎么用?Java ShadowLooper.runUiThreadTasks使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.robolectric.shadows.ShadowLooper
的用法示例。
在下文中一共展示了ShadowLooper.runUiThreadTasks方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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));
}
示例2: 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));
}
示例3: 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));
}
示例4: 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));
}
示例5: 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));
}
示例6: 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));
}
示例7: 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());
}
示例8: testOnExceptionNotDeliveredAfterCancel
import org.robolectric.shadows.ShadowLooper; //导入方法依赖的package包/类
@Test
public void testOnExceptionNotDeliveredAfterCancel() {
harness = new EngineJobHarness();
EngineJob<Object> job = harness.getJob();
job.start(harness.decodeJob);
job.cancel();
job.onLoadFailed(new GlideException("test"));
ShadowLooper.runUiThreadTasks();
verify(harness.cb, never()).onLoadFailed(any(GlideException.class));
}
示例9: testConnectedEventSuccess
import org.robolectric.shadows.ShadowLooper; //导入方法依赖的package包/类
/**
* Test that "connecting" and "connected" event are sent successfully if the
* connection succeeded.
*/
@Test
public void testConnectedEventSuccess() throws InterruptedException {
final CountDownLatch connectingMessageReceived = new CountDownLatch(1);
final CountDownLatch connectedMessageReceived = new CountDownLatch(1);
control = new BluetoothPresenterControl(new Handler() {
@Override
public void handleMessage(Message msg) {
if (msg.what == RemoteControl.ServiceState.CONNECTING.ordinal()) {
connectingMessageReceived.countDown();
} else if (msg.what == RemoteControl.ServiceState.CONNECTED.ordinal()) {
assertThat("Got wrong connection result",
msg.getData().getBoolean(RemoteControl.RESULT_VALUES[0]),
is(true));
assertThat("Got wrong device to which we are connected",
msg.getData().getString(RemoteControl.RESULT_VALUES[1]),
is(DEVICE_NAME));
connectedMessageReceived.countDown();
}
}
});
ShadowBluetoothSocket.setTransmittedString(SERVER_VERSION_SUCCESS);
BluetoothDevice bluetoothDevice = ShadowBluetoothAdapter.getDefaultAdapter()
.getRemoteDevice(DEVICE_ADDRESS);
shadowOf(bluetoothDevice).setName(DEVICE_NAME);
control.connect(bluetoothDevice);
waitForServiceStateChanged(control, RemoteControl.ServiceState.CONNECTED);
ShadowLooper.runUiThreadTasks();
assertThat("Did not receive 'connecting' message",
connectingMessageReceived.await(MESSAGE_RECEIVING_TIMEOUT, TimeUnit.MILLISECONDS),
is(true));
assertThat("Did not receive 'connected' message",
connectedMessageReceived.await(MESSAGE_RECEIVING_TIMEOUT, TimeUnit.MILLISECONDS),
is(true));
}
示例10: testConnectedEventFailure
import org.robolectric.shadows.ShadowLooper; //导入方法依赖的package包/类
/**
* Test that the "connecting" and "connected" event are sent successfully if the
* connection fails and that the result state is correct.
*/
@Test
public void testConnectedEventFailure() throws InterruptedException {
ShadowBluetoothSocket.setConnectionSucceed(false);
final CountDownLatch connectingMessageReceived = new CountDownLatch(1);
final CountDownLatch connectedMessageReceived = new CountDownLatch(1);
control = new BluetoothPresenterControl(new Handler() {
@Override
public void handleMessage(Message msg) {
if (msg.what == RemoteControl.ServiceState.CONNECTING.ordinal()) {
connectingMessageReceived.countDown();
} else if (msg.what == RemoteControl.ServiceState.CONNECTED.ordinal()) {
assertThat("Got wrong connection result",
msg.getData().getBoolean(RemoteControl.RESULT_VALUES[0]),
is(false));
connectedMessageReceived.countDown();
}
}
});
BluetoothDevice bluetoothDevice = ShadowBluetoothAdapter.getDefaultAdapter()
.getRemoteDevice(DEVICE_ADDRESS);
control.connect(bluetoothDevice);
waitForServiceStateChanged(control, RemoteControl.ServiceState.CONNECTING);
waitForServiceStateChanged(control, RemoteControl.ServiceState.NONE);
ShadowLooper.runUiThreadTasks();
assertThat("Did not receive 'connecting' event",
connectingMessageReceived.await(MESSAGE_RECEIVING_TIMEOUT, TimeUnit.MILLISECONDS),
is(true));
assertThat("Did not receive 'connected' event",
connectedMessageReceived.await(MESSAGE_RECEIVING_TIMEOUT, TimeUnit.MILLISECONDS),
is(true));
}
示例11: testConnectedEventIncompatibleVersion
import org.robolectric.shadows.ShadowLooper; //导入方法依赖的package包/类
/**
* Test that the "error" event is sent successfully if the server sends incompatible version
* information.
*/
@Test
public void testConnectedEventIncompatibleVersion() throws InterruptedException {
ShadowBluetoothSocket.setTransmittedString(SERVER_VERSION_FAILURE);
final CountDownLatch messageReceived = new CountDownLatch(1);
control = new BluetoothPresenterControl(new Handler() {
@Override
public void handleMessage(Message msg) {
if (msg.what == RemoteControl.ServiceState.ERROR.ordinal()) {
assertThat("Got wrong error type",
msg.getData().getString(RemoteControl.RESULT_VALUES[2]),
is(RemoteControl.ERROR_TYPES.VERSION.toString()));
messageReceived.countDown();
}
}
});
BluetoothDevice bluetoothDevice = ShadowBluetoothAdapter.getDefaultAdapter()
.getRemoteDevice(DEVICE_ADDRESS);
control.connect(bluetoothDevice);
waitForServiceStateChanged(control, RemoteControl.ServiceState.CONNECTING);
waitForServiceStateChanged(control, RemoteControl.ServiceState.NONE);
ShadowLooper.runUiThreadTasks();
assertThat("Did not receive 'error' event",
messageReceived.await(MESSAGE_RECEIVING_TIMEOUT, TimeUnit.MILLISECONDS),
is(true));
}
示例12: testConnectedEventInvalidData
import org.robolectric.shadows.ShadowLooper; //导入方法依赖的package包/类
/**
* Test that the "error" event is sent successfully if the server sends invalid data.
*/
@Test
public void testConnectedEventInvalidData() throws InterruptedException {
ShadowBluetoothSocket.setTransmittedString("This is invalid json data\n\n");
final CountDownLatch messageReceived = new CountDownLatch(1);
control = new BluetoothPresenterControl(new Handler() {
@Override
public void handleMessage(Message msg) {
if (msg.what == RemoteControl.ServiceState.ERROR.ordinal()) {
assertThat("Got wrong error type",
msg.getData().getString(RemoteControl.RESULT_VALUES[2]),
is(RemoteControl.ERROR_TYPES.PARSING.toString()));
messageReceived.countDown();
}
}
});
BluetoothDevice bluetoothDevice = ShadowBluetoothAdapter.getDefaultAdapter()
.getRemoteDevice(DEVICE_ADDRESS);
control.connect(bluetoothDevice);
waitForServiceStateChanged(control, RemoteControl.ServiceState.CONNECTING);
long startTime = System.currentTimeMillis();
while (System.currentTimeMillis() < startTime + MESSAGE_RECEIVING_TIMEOUT) {
Thread.sleep(MESSAGE_CHECK_TIME);
ShadowLooper.runUiThreadTasks();
if (messageReceived.await(MESSAGE_CHECK_TIME, TimeUnit.MILLISECONDS)) {
return;
}
}
fail("Did not receive 'error' event");
}
示例13: test
import org.robolectric.shadows.ShadowLooper; //导入方法依赖的package包/类
@Test
public void test() {
final Scheduler scheduler = AndroidSchedulers.from(Looper.getMainLooper());
final AtomicInteger x = new AtomicInteger();
Observable.just(1)
.observeOn(AndroidSchedulers.mainThread())
.subscribe(x::set);
// Main looper is paused, so value should not change.
assertEquals(0, x.get());
Observable.just(2)
.observeOn(Schedulers.immediate())
.subscribe(x::set);
// Since the work used the immediate scheduler, it is unaffected by the main looper being paused.
assertEquals(2, x.get());
Observable.just(3)
.compose(observeForUI())
.subscribe(x::set);
// The main looper is paused but the code is executing on the main thread, so observeForUI() should schedule the
// work immediately rather than queueing it up.
assertEquals(3, x.get());
// Run the queued work.
ShadowLooper.runUiThreadTasks();
// Code observed using `AndroidSchedulers.mainThread()` is now run.
assertEquals(1, x.get());
}