org.robolectric.util.Scheduler.runOneTask()方法的使用及代码示例

x33g5p2x  于2022-01-30 转载在 其他  
字(12.0k)|赞(0)|评价(0)|浏览(159)

本文整理了Java中org.robolectric.util.Scheduler.runOneTask()方法的一些代码示例,展示了Scheduler.runOneTask()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Scheduler.runOneTask()方法的具体详情如下:
包路径:org.robolectric.util.Scheduler
类名称:Scheduler
方法名:runOneTask

Scheduler.runOneTask介绍

[英]Run the next runnable in the queue.
[中]运行队列中的下一个runnable。

代码示例

代码示例来源:origin: robolectric/robolectric

/**
 * Causes only one of the next {@link Runnable}s that have been scheduled to run while advancing the scheduler's
 * clock to its start time. Only one {@link Runnable} will run even if more than one has ben scheduled to run at the
 * same time.
 */
public void runOneTask() {
 getScheduler().runOneTask();
}

代码示例来源:origin: robolectric/robolectric

/**
 * Run all runnables that are scheduled before the endTime.
 *
 * @param   endTime   Future time.
 * @return  True if a runnable was executed.
 */
public synchronized boolean advanceTo(long endTime) {
 if (endTime < currentTime || runnables.isEmpty()) {
  currentTime = endTime;
  return false;
 }
 int runCount = 0;
 while (nextTaskIsScheduledBefore(endTime)) {
  runOneTask();
  ++runCount;
 }
 currentTime = endTime;
 return runCount > 0;
}

代码示例来源:origin: robolectric/robolectric

@Test
public void postAtFrontOfQueue_addsJobAtFrontOfQueue() throws Exception {
 scheduler.post(new AddToTranscript("one"));
 scheduler.post(new AddToTranscript("two"));
 scheduler.postAtFrontOfQueue(new AddToTranscript("three"));
 scheduler.runOneTask();
 assertThat(transcript).containsExactly("three");
 transcript.clear();
 scheduler.runOneTask();
 assertThat(transcript).containsExactly("one");
 transcript.clear();
 scheduler.runOneTask();
 assertThat(transcript).containsExactly("two");
}

代码示例来源:origin: k9mail/k-9

private void runBackgroundTask() {
  boolean taskRun = Robolectric.getBackgroundThreadScheduler().runOneTask();
  assertTrue(taskRun);
}

代码示例来源:origin: robolectric/robolectric

scheduler.runOneTask();
scheduler.runOneTask();
assertThat(order).named("order:second run").containsExactly(1, 2, 3);
assertThat(scheduler.size()).named("size:second run").isEqualTo(1);
scheduler.runOneTask();
assertThat(order).named("order:third run").containsExactly(1, 2, 3, 4);
assertThat(scheduler.size()).named("size:second run").isEqualTo(0);

代码示例来源:origin: robolectric/robolectric

assertThat(s).isSameAs(shadowOf(ht.getLooper()).getScheduler());
final long startTime = s.getCurrentTime();
s.runOneTask();
assertThat(events).named("firstEvent").containsExactly("handler1");
assertThat(s.getCurrentTime()).named("firstEvent:time").isEqualTo(100 + startTime);
s.runOneTask();
assertThat(events).named("secondEvent").containsExactly("handler1", "handler2");
assertThat(s.getCurrentTime()).named("secondEvent:time").isEqualTo(200 + startTime);

代码示例来源:origin: org.robolectric/shadows-framework

/**
 * Causes only one of the next {@link Runnable}s that have been scheduled to run while advancing the scheduler's
 * clock to its start time. Only one {@link Runnable} will run even if more than one has ben scheduled to run at the
 * same time.
 */
public void runOneTask() {
 getScheduler().runOneTask();
}

代码示例来源:origin: org.robolectric/shadows-core

/**
 * Causes only one of the next {@link Runnable}s that have been scheduled to run while advancing the scheduler's
 * clock to its start time. Only one {@link Runnable} will run even if more than one has ben scheduled to run at the
 * same time.
 */
public void runOneTask() {
 getScheduler().runOneTask();
}

代码示例来源:origin: org.robolectric/framework

/**
 * Causes only one of the next {@link Runnable}s that have been scheduled to run while advancing the scheduler's
 * clock to its start time. Only one {@link Runnable} will run even if more than one has ben scheduled to run at the
 * same time.
 */
public void runOneTask() {
 getScheduler().runOneTask();
}

代码示例来源:origin: org.robolectric/shadows-core-v23

/**
 * Causes only one of the next {@link Runnable}s that have been scheduled to run while advancing the scheduler's
 * clock to its start time. Only one {@link Runnable} will run even if more than one has ben scheduled to run at the
 * same time.
 */
public void runOneTask() {
 getScheduler().runOneTask();
}

代码示例来源:origin: org.robolectric/utils

/**
 * Run all runnables that are scheduled before the endTime.
 *
 * @param   endTime   Future time.
 * @return  True if a runnable was executed.
 */
public synchronized boolean advanceTo(long endTime) {
 if (endTime < currentTime || runnables.isEmpty()) {
  currentTime = endTime;
  return false;
 }
 int runCount = 0;
 while (nextTaskIsScheduledBefore(endTime)) {
  runOneTask();
  ++runCount;
 }
 currentTime = endTime;
 return runCount > 0;
}

代码示例来源:origin: org.robolectric/robolectric-utils

/**
 * Run all runnables that are scheduled before the endTime.
 *
 * @param   endTime   Future time.
 * @return  True if a runnable was executed.
 */
public synchronized boolean advanceTo(long endTime) {
 if (endTime - currentTime < 0 || size() < 1) {
  currentTime = endTime;
  return false;
 }
 int runCount = 0;
 while (nextTaskIsScheduledBefore(endTime)) {
  runOneTask();
  ++runCount;
 }
 currentTime = endTime;
 return runCount > 0;
}

代码示例来源:origin: line/line-sdk-android

@Test
public void testNetworkErrorOfGettingOneTimePassword() throws Exception {
  doReturn(LineApiResponse.createAsError(LineApiResponseCode.NETWORK_ERROR, LineApiError.DEFAULT))
      .when(authApiClient)
      .getOneTimeIdAndPassword(CHANNEL_ID);
  target.startLineAuthentication();
  Robolectric.getBackgroundThreadScheduler().runOneTask();
  Robolectric.getForegroundThreadScheduler().runOneTask();
  verify(activity, times(1)).onAuthenticationFinished(
      new LineLoginResult(LineApiResponseCode.NETWORK_ERROR, LineApiError.DEFAULT));
}

代码示例来源:origin: line/line-sdk-android

@Test
public void testInternalErrorOfGettingOneTimePassword() throws Exception {
  doReturn(LineApiResponse.createAsError(LineApiResponseCode.INTERNAL_ERROR, LineApiError.DEFAULT))
      .when(authApiClient)
      .getOneTimeIdAndPassword(CHANNEL_ID);
  target.startLineAuthentication();
  Robolectric.getBackgroundThreadScheduler().runOneTask();
  Robolectric.getForegroundThreadScheduler().runOneTask();
  verify(activity, times(1)).onAuthenticationFinished(
      new LineLoginResult(LineApiResponseCode.INTERNAL_ERROR, LineApiError.DEFAULT));
}

代码示例来源:origin: line/line-sdk-android

@Test
  public void testCancel() throws Exception {
    doReturn(LineApiResponse.createAsSuccess(ONE_TIME_ID_AND_PASSWORD))
        .when(authApiClient)
        .getOneTimeIdAndPassword(CHANNEL_ID);

    target.startLineAuthentication();

    Robolectric.getBackgroundThreadScheduler().runOneTask();
    Robolectric.getForegroundThreadScheduler().runOneTask();

    verify(browserAuthenticationApi, times(1))
        .getRequest(activity, config, ONE_TIME_ID_AND_PASSWORD, LINE_AUTH_PARAMS);

    target.onActivityResult(3 /* requestCode */, 0 /* resultCode */, null /* data */);

    verify(activity, never()).onAuthenticationFinished(any(LineLoginResult.class));

    Robolectric.getForegroundThreadScheduler().runOneTask();

    verify(activity, times(1)).onAuthenticationFinished(LineLoginResult.CANCEL);
  }
}

代码示例来源:origin: line/line-sdk-android

@Test
public void testErrorOfRequestTokenProvider() throws Exception {
  Intent newIntentData = new Intent();
  doReturn(LineApiResponse.createAsSuccess(ONE_TIME_ID_AND_PASSWORD))
      .when(authApiClient)
      .getOneTimeIdAndPassword(CHANNEL_ID);
  doReturn(BrowserAuthenticationApi.Result.createAsInternalError("internalErrorMessage"))
      .when(browserAuthenticationApi)
      .getAuthenticationResultFrom(newIntentData);
  target.startLineAuthentication();
  Robolectric.getBackgroundThreadScheduler().runOneTask();
  Robolectric.getForegroundThreadScheduler().runOneTask();
  verify(browserAuthenticationApi, times(1))
      .getRequest(activity, config, ONE_TIME_ID_AND_PASSWORD, LINE_AUTH_PARAMS);
  target.handleIntentFromLineApp(newIntentData);
  verify(activity, times(1)).onAuthenticationFinished(
      new LineLoginResult(LineApiResponseCode.INTERNAL_ERROR, any(LineApiError.class)));
}

代码示例来源:origin: line/line-sdk-android

@Test
public void testNetworkErrorOfGettingAccessToken() throws Exception {
  Intent newIntentData = new Intent();
  doReturn(LineApiResponse.createAsSuccess(ONE_TIME_ID_AND_PASSWORD))
      .when(authApiClient)
      .getOneTimeIdAndPassword(CHANNEL_ID);
  doReturn(BrowserAuthenticationApi.Result.createAsSuccess(REQUEST_TOKEN_STR, false))
      .when(browserAuthenticationApi)
      .getAuthenticationResultFrom(newIntentData);
  doReturn(LineApiResponse.createAsError(LineApiResponseCode.NETWORK_ERROR, LineApiError.DEFAULT))
      .when(authApiClient)
      .issueAccessToken(
          CHANNEL_ID, REQUEST_TOKEN_STR, ONE_TIME_ID_AND_PASSWORD, REDIRECT_URI);
  target.startLineAuthentication();
  Robolectric.getBackgroundThreadScheduler().runOneTask();
  Robolectric.getForegroundThreadScheduler().runOneTask();
  verify(browserAuthenticationApi, times(1))
      .getRequest(activity, config, ONE_TIME_ID_AND_PASSWORD, LINE_AUTH_PARAMS);
  target.handleIntentFromLineApp(newIntentData);
  Robolectric.getBackgroundThreadScheduler().runOneTask();
  Robolectric.getForegroundThreadScheduler().runOneTask();
  verify(activity, times(1)).onAuthenticationFinished(
      new LineLoginResult(LineApiResponseCode.NETWORK_ERROR, LineApiError.DEFAULT));
}

代码示例来源:origin: line/line-sdk-android

@Test
public void testInternalErrorOfGettingAccessToken() throws Exception {
  Intent newIntentData = new Intent();
  doReturn(LineApiResponse.createAsSuccess(ONE_TIME_ID_AND_PASSWORD))
      .when(authApiClient)
      .getOneTimeIdAndPassword(CHANNEL_ID);
  doReturn(BrowserAuthenticationApi.Result.createAsSuccess(REQUEST_TOKEN_STR, null))
      .when(browserAuthenticationApi)
      .getAuthenticationResultFrom(newIntentData);
  doReturn(LineApiResponse.createAsError(LineApiResponseCode.INTERNAL_ERROR, LineApiError.DEFAULT))
      .when(authApiClient)
      .issueAccessToken(
          CHANNEL_ID, REQUEST_TOKEN_STR, ONE_TIME_ID_AND_PASSWORD, REDIRECT_URI);
  target.startLineAuthentication();
  Robolectric.getBackgroundThreadScheduler().runOneTask();
  Robolectric.getForegroundThreadScheduler().runOneTask();
  verify(browserAuthenticationApi, times(1))
      .getRequest(activity, config, ONE_TIME_ID_AND_PASSWORD, LINE_AUTH_PARAMS);
  target.handleIntentFromLineApp(newIntentData);
  Robolectric.getBackgroundThreadScheduler().runOneTask();
  Robolectric.getForegroundThreadScheduler().runOneTask();
  verify(activity, times(1)).onAuthenticationFinished(
      new LineLoginResult(LineApiResponseCode.INTERNAL_ERROR, LineApiError.DEFAULT));
}

代码示例来源:origin: line/line-sdk-android

@Test
public void testInternalErrorOfGettingAccountInfo() throws Exception {
  Intent newIntentData = new Intent();
  doReturn(LineApiResponse.createAsSuccess(ONE_TIME_ID_AND_PASSWORD))
      .when(authApiClient)
      .getOneTimeIdAndPassword(CHANNEL_ID);
  doReturn(BrowserAuthenticationApi.Result.createAsSuccess(REQUEST_TOKEN_STR, null))
      .when(browserAuthenticationApi)
      .getAuthenticationResultFrom(newIntentData);
  doReturn(LineApiResponse.createAsSuccess(ISSUE_ACCESS_TOKEN_RESULT))
      .when(authApiClient)
      .issueAccessToken(
          CHANNEL_ID, REQUEST_TOKEN_STR, ONE_TIME_ID_AND_PASSWORD, REDIRECT_URI);
  doReturn(LineApiResponse.createAsError(LineApiResponseCode.INTERNAL_ERROR, LineApiError.DEFAULT))
      .when(talkApiClient)
      .getProfile(ACCESS_TOKEN);
  target.startLineAuthentication();
  Robolectric.getBackgroundThreadScheduler().runOneTask();
  Robolectric.getForegroundThreadScheduler().runOneTask();
  verify(browserAuthenticationApi, times(1))
      .getRequest(activity, config, ONE_TIME_ID_AND_PASSWORD, LINE_AUTH_PARAMS);
  target.handleIntentFromLineApp(newIntentData);
  Robolectric.getBackgroundThreadScheduler().runOneTask();
  Robolectric.getForegroundThreadScheduler().runOneTask();
  verify(activity, times(1)).onAuthenticationFinished(
      new LineLoginResult(LineApiResponseCode.INTERNAL_ERROR, LineApiError.DEFAULT));
}

代码示例来源:origin: appnexus/mobile-sdk-android

@Test
public void testStop() {
  if (adFetcher != null) {
    // not needed, but in case AdRequest is run
    server.enqueue(new MockResponse().setResponseCode(200).setBody(TestResponsesUT.blank()));
    clearAAIDAsyncTasks();
    // start an AdFetcher normally, until an AdRequest is queued
    adFetcher.start();
    Lock.pause(1000); // added this so jenkins can have enough time to process
    assertExpectedBGTasksAfterOneAdRequest(1);
    assertNotSame(AdFetcher.STATE.STOPPED, adFetcher.getState());
    adFetcher.stop();
    // pause until a scheduler has a task in queue
    waitForTasks();
    // Run the cancel command on AdRequest
    Robolectric.flushForegroundThreadScheduler();
    // Run the pending AdRequest from start() -- should have been canceled
    while (Robolectric.getBackgroundThreadScheduler().areAnyRunnable()) {
      Robolectric.getBackgroundThreadScheduler().runOneTask();
    }
    // A normally executed AdRequest will queue onPostExecute call to the UI thread,
    // but it should be canceled, and queue nothing
    int uiTaskCount = Robolectric.getForegroundThreadScheduler().size();
    assertEquals(0, uiTaskCount);
    assertEquals(AdFetcher.STATE.STOPPED, adFetcher.getState());
  }
}

相关文章