本文整理了Java中org.robolectric.util.Scheduler.unPause()
方法的一些代码示例,展示了Scheduler.unPause()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Scheduler.unPause()
方法的具体详情如下:
包路径:org.robolectric.util.Scheduler
类名称:Scheduler
方法名:unPause
[英]Un-pause the scheduler. Equivalent to setIdleState(UNPAUSED).
[中]取消暂停调度程序。相当于SetIdleEstate(未授权)。
代码示例来源:origin: robolectric/robolectric
public void unPause() {
getScheduler().unPause();
}
代码示例来源:origin: robolectric/robolectric
@Test
public void testScheduleErrorAtOffsetInPast() {
info.scheduleErrorAtOffset(200, 1, 2);
shadowMediaPlayer.setState(INITIALIZED);
shadowMediaPlayer.setCurrentPosition(400);
shadowMediaPlayer.setState(PAUSED);
mediaPlayer.start();
scheduler.unPause();
Mockito.verifyZeroInteractions(errorListener);
}
代码示例来源:origin: robolectric/robolectric
@Test
public void onPostExecute_doesNotSwallowExceptions() throws Exception {
Robolectric.getBackgroundThreadScheduler().unPause();
Robolectric.getForegroundThreadScheduler().unPause();
AsyncTask<Void, Void, Void> asyncTask = new AsyncTask<Void, Void, Void>() {
@Override
protected Void doInBackground(Void... params) {
return null;
}
@Override
protected void onPostExecute(Void aVoid) {
throw new RuntimeException("Don't swallow me!");
}
};
try {
asyncTask.execute();
fail("Task swallowed onPostExecute() exception!");
} catch (RuntimeException e) {
assertThat(e.getCause().getMessage()).isEqualTo("Don't swallow me!");
}
}
代码示例来源:origin: robolectric/robolectric
@Test
public void postAtFrontOfQueue_whenUnpaused_runsJobs() throws Exception {
scheduler.unPause();
scheduler.postAtFrontOfQueue(new AddToTranscript("three"));
assertThat(transcript).containsExactly("three");
}
代码示例来源:origin: robolectric/robolectric
@Test
public void unPause_setsIdleState() {
scheduler.setIdleState(PAUSED);
scheduler.unPause();
assertThat(scheduler.getIdleState()).isSameAs(UNPAUSED);
}
代码示例来源:origin: robolectric/robolectric
@Test
public void post_whenTheRunnableThrows_executesSubsequentRunnables() throws Exception {
final List<Integer> runnablesThatWereRun = new ArrayList<>();
scheduler.post(new Runnable() {
@Override
public void run() {
runnablesThatWereRun.add(1);
throw new RuntimeException("foo");
}
});
try {
scheduler.unPause();
} catch (RuntimeException ignored) { }
scheduler.post(new Runnable() {
@Override
public void run() {
runnablesThatWereRun.add(2);
}
});
assertThat(runnablesThatWereRun).containsExactly(1, 2);
}
代码示例来源:origin: k9mail/k-9
@Test
public void build_detachAndReattach_shouldSucceed() throws MessagingException {
MessageBuilder messageBuilder = createSimpleMessageBuilder();
Callback anotherCallback = mock(Callback.class);
Robolectric.getBackgroundThreadScheduler().pause();
messageBuilder.buildAsync(callback);
messageBuilder.detachCallback();
Robolectric.getBackgroundThreadScheduler().unPause();
messageBuilder.reattachCallback(anotherCallback);
verifyNoMoreInteractions(callback);
verify(anotherCallback).onMessageBuildSuccess(any(MimeMessage.class), eq(false));
verifyNoMoreInteractions(anotherCallback);
}
代码示例来源:origin: robolectric/robolectric
@Override
public void test(MethodSpec method) {
final State state = shadowMediaPlayer.getState();
final boolean wasPaused = scheduler.isPaused();
scheduler.pause();
try {
method.invoke();
} catch (InvocationTargetException e) {
throw new RuntimeException("Expected <" + method
+ "> to call onError rather than throw <" + e.getTargetException()
+ "> when called from <" + state + ">", e);
}
Mockito.verifyZeroInteractions(errorListener);
final State finalState = shadowMediaPlayer.getState();
assertThat(finalState).isSameAs(ERROR);
scheduler.unPause();
Mockito.verify(errorListener).onError(mediaPlayer, what, extra);
Mockito.reset(errorListener);
if (wasPaused) {
scheduler.pause();
}
}
}
代码示例来源:origin: robolectric/robolectric
@Test
public void executeReturnsAsyncTask() throws Exception {
Robolectric.getBackgroundThreadScheduler().unPause();
AsyncTask<String, String, String> asyncTask = new MyAsyncTask();
assertThat(asyncTask.execute("a", "b").get()).isEqualTo("c");
}
代码示例来源:origin: robolectric/robolectric
@Test
public void nestedPost_whileUnpaused_automaticallyExecutes3After() {
final List<Integer> order = new ArrayList<>();
scheduler.unPause();
scheduler.postDelayed(new Runnable() {
@Override
public void run() {
order.add(1);
scheduler.post(new Runnable() {
@Override
public void run() {
order.add(3);
}
});
order.add(2);
}
}, 0);
assertThat(order).named("order").containsExactly(1, 2, 3);
assertThat(scheduler.size()).named("size").isEqualTo(0);
}
代码示例来源:origin: robolectric/robolectric
@Test
public void shouldGetStatusForAsyncTask() throws Exception {
AsyncTask<String, String, String> asyncTask = new MyAsyncTask();
assertThat(asyncTask.getStatus()).isEqualTo(AsyncTask.Status.PENDING);
asyncTask.execute("a");
assertThat(asyncTask.getStatus()).isEqualTo(AsyncTask.Status.RUNNING);
Robolectric.getBackgroundThreadScheduler().unPause();
assertThat(asyncTask.getStatus()).isEqualTo(AsyncTask.Status.FINISHED);
}
代码示例来源:origin: robolectric/robolectric
@Test
public void nestedPostAtFront_whileUnpaused_runsAfter() {
final List<Integer> order = new ArrayList<>();
scheduler.unPause();
scheduler.postDelayed(new Runnable() {
@Override
public void run() {
order.add(1);
scheduler.postAtFrontOfQueue(new Runnable() {
@Override
public void run() {
order.add(3);
}
});
order.add(2);
}
}, 0);
assertThat(order).named("order").containsExactly(1, 2, 3);
assertThat(scheduler.size()).named("size").isEqualTo(0);
}
代码示例来源:origin: robolectric/robolectric
@Test
public void removeGroup_failure() {
TestActionListener testListener = new TestActionListener();
RuntimeEnvironment.getMasterScheduler().pause();
manager.removeGroup(channel, testListener);
shadowManager.setNextActionFailure(WifiP2pManager.BUSY);
RuntimeEnvironment.getMasterScheduler().unPause();
assertThat(testListener.success).isFalse();
assertThat(testListener.reason).isEqualTo(WifiP2pManager.BUSY);
}
代码示例来源:origin: robolectric/robolectric
@Test
public void addAccount_whenSchedulerPaused_shouldCallCallbackAfterSchedulerUnpaused() throws Exception {
scheduler.pause();
shadowOf(am).addAuthenticator("google.com");
TestAccountManagerCallback<Bundle> callback = new TestAccountManagerCallback<>();
am.addAccount("google.com", "auth_token_type", null, null, activity, callback, new Handler());
assertThat(callback.hasBeenCalled()).isFalse();
shadowOf(am).addAccount(new Account("thebomb@google.com", "google.com"));
scheduler.unPause();
assertThat(callback.hasBeenCalled()).isTrue();
Bundle resultBundle = callback.getResult();
assertThat(resultBundle.getString(AccountManager.KEY_ACCOUNT_TYPE)).isEqualTo("google.com");
assertThat(resultBundle.getString(AccountManager.KEY_ACCOUNT_NAME)).isEqualTo("thebomb@google.com");
}
代码示例来源:origin: k9mail/k-9
@Test
public void buildWithException_detachAndReattach_shouldThrow() throws MessagingException {
Callback anotherCallback = mock(Callback.class);
MessageBuilder messageBuilder = new SimpleMessageBuilder(messageIdGenerator, boundaryGenerator, resourceProvider) {
@Override
protected void buildMessageInternal() {
queueMessageBuildException(new MessagingException("expected error"));
}
};
Robolectric.getBackgroundThreadScheduler().pause();
messageBuilder.buildAsync(callback);
messageBuilder.detachCallback();
Robolectric.getBackgroundThreadScheduler().unPause();
messageBuilder.reattachCallback(anotherCallback);
verifyNoMoreInteractions(callback);
verify(anotherCallback).onMessageBuildException(any(MessagingException.class));
verifyNoMoreInteractions(anotherCallback);
}
代码示例来源:origin: robolectric/robolectric
@Test
public void createGroup_fail() {
TestActionListener testListener = new TestActionListener();
RuntimeEnvironment.getMasterScheduler().pause();
manager.createGroup(channel, testListener);
shadowManager.setNextActionFailure(WifiP2pManager.BUSY);
RuntimeEnvironment.getMasterScheduler().unPause();
assertThat(testListener.success).isFalse();
assertThat(testListener.reason).isEqualTo(WifiP2pManager.BUSY);
}
代码示例来源:origin: robolectric/robolectric
@Test
public void unPause_shouldRunPendingTasks() {
scheduler.postDelayed(new AddToTranscript("one"), 0);
scheduler.postDelayed(new AddToTranscript("two"), 0);
scheduler.postDelayed(new AddToTranscript("three"), 1000);
assertThat(transcript).isEmpty();
final long time = scheduler.getCurrentTime();
scheduler.unPause();
assertThat(transcript).containsExactly("one", "two");
assertThat(scheduler.getCurrentTime()).named("time").isEqualTo(time);
}
代码示例来源:origin: robolectric/robolectric
@Test
public void nestedPostDelayed_whileUnpaused_doesntAutomaticallyExecute3() {
final List<Integer> order = new ArrayList<>();
scheduler.unPause();
scheduler.postDelayed(new Runnable() {
@Override
public void run() {
order.add(1);
scheduler.postDelayed(new Runnable() {
@Override
public void run() {
order.add(3);
}
}, 1);
order.add(2);
}
}, 0);
assertThat(order).named("order:before").containsExactly(1, 2);
assertThat(scheduler.size()).named("size:before").isEqualTo(1);
scheduler.advanceToLastPostedRunnable();
assertThat(order).named("order:after").containsExactly(1, 2, 3);
assertThat(scheduler.size()).named("size:after").isEqualTo(0);
assertThat(scheduler.getCurrentTime()).named("time:after").isEqualTo(1 + startTime);
}
代码示例来源:origin: org.robolectric/shadows-core
public void unPause() {
getScheduler().unPause();
}
代码示例来源:origin: stanfy/goro
@Test
public void unbindAfterConnectionIfRequested() {
assertThat(Shadows.shadowOf(application).getUnboundServiceConnections()).isEmpty();
Robolectric.getForegroundThreadScheduler().pause();
goro.bind();
goro.unbind();
Robolectric.getForegroundThreadScheduler().unPause();
assertThat(Shadows.shadowOf(application).getUnboundServiceConnections()).hasSize(1);
}
内容来源于网络,如有侵权,请联系作者删除!