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

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

本文整理了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

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

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

  1. /**
  2. * Run all runnables that are scheduled before the endTime.
  3. *
  4. * @param endTime Future time.
  5. * @return True if a runnable was executed.
  6. */
  7. public synchronized boolean advanceTo(long endTime) {
  8. if (endTime < currentTime || runnables.isEmpty()) {
  9. currentTime = endTime;
  10. return false;
  11. }
  12. int runCount = 0;
  13. while (nextTaskIsScheduledBefore(endTime)) {
  14. runOneTask();
  15. ++runCount;
  16. }
  17. currentTime = endTime;
  18. return runCount > 0;
  19. }

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

  1. @Test
  2. public void postAtFrontOfQueue_addsJobAtFrontOfQueue() throws Exception {
  3. scheduler.post(new AddToTranscript("one"));
  4. scheduler.post(new AddToTranscript("two"));
  5. scheduler.postAtFrontOfQueue(new AddToTranscript("three"));
  6. scheduler.runOneTask();
  7. assertThat(transcript).containsExactly("three");
  8. transcript.clear();
  9. scheduler.runOneTask();
  10. assertThat(transcript).containsExactly("one");
  11. transcript.clear();
  12. scheduler.runOneTask();
  13. assertThat(transcript).containsExactly("two");
  14. }

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

  1. /**
  2. * Run all runnables that are scheduled before the endTime.
  3. *
  4. * @param endTime Future time.
  5. * @return True if a runnable was executed.
  6. */
  7. public synchronized boolean advanceTo(long endTime) {
  8. if (endTime < currentTime || runnables.isEmpty()) {
  9. currentTime = endTime;
  10. return false;
  11. }
  12. int runCount = 0;
  13. while (nextTaskIsScheduledBefore(endTime)) {
  14. runOneTask();
  15. ++runCount;
  16. }
  17. currentTime = endTime;
  18. return runCount > 0;
  19. }

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

  1. /**
  2. * Run all runnables that are scheduled before the endTime.
  3. *
  4. * @param endTime Future time.
  5. * @return True if a runnable was executed.
  6. */
  7. public synchronized boolean advanceTo(long endTime) {
  8. if (endTime - currentTime < 0 || size() < 1) {
  9. currentTime = endTime;
  10. return false;
  11. }
  12. int runCount = 0;
  13. while (nextTaskIsScheduledBefore(endTime)) {
  14. runOneTask();
  15. ++runCount;
  16. }
  17. currentTime = endTime;
  18. return runCount > 0;
  19. }

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

  1. @Test
  2. public void testNetworkErrorOfGettingOneTimePassword() throws Exception {
  3. doReturn(LineApiResponse.createAsError(LineApiResponseCode.NETWORK_ERROR, LineApiError.DEFAULT))
  4. .when(authApiClient)
  5. .getOneTimeIdAndPassword(CHANNEL_ID);
  6. target.startLineAuthentication();
  7. Robolectric.getBackgroundThreadScheduler().runOneTask();
  8. Robolectric.getForegroundThreadScheduler().runOneTask();
  9. verify(activity, times(1)).onAuthenticationFinished(
  10. new LineLoginResult(LineApiResponseCode.NETWORK_ERROR, LineApiError.DEFAULT));
  11. }

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

  1. @Test
  2. public void testInternalErrorOfGettingOneTimePassword() throws Exception {
  3. doReturn(LineApiResponse.createAsError(LineApiResponseCode.INTERNAL_ERROR, LineApiError.DEFAULT))
  4. .when(authApiClient)
  5. .getOneTimeIdAndPassword(CHANNEL_ID);
  6. target.startLineAuthentication();
  7. Robolectric.getBackgroundThreadScheduler().runOneTask();
  8. Robolectric.getForegroundThreadScheduler().runOneTask();
  9. verify(activity, times(1)).onAuthenticationFinished(
  10. new LineLoginResult(LineApiResponseCode.INTERNAL_ERROR, LineApiError.DEFAULT));
  11. }

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

  1. @Test
  2. public void testCancel() throws Exception {
  3. doReturn(LineApiResponse.createAsSuccess(ONE_TIME_ID_AND_PASSWORD))
  4. .when(authApiClient)
  5. .getOneTimeIdAndPassword(CHANNEL_ID);
  6. target.startLineAuthentication();
  7. Robolectric.getBackgroundThreadScheduler().runOneTask();
  8. Robolectric.getForegroundThreadScheduler().runOneTask();
  9. verify(browserAuthenticationApi, times(1))
  10. .getRequest(activity, config, ONE_TIME_ID_AND_PASSWORD, LINE_AUTH_PARAMS);
  11. target.onActivityResult(3 /* requestCode */, 0 /* resultCode */, null /* data */);
  12. verify(activity, never()).onAuthenticationFinished(any(LineLoginResult.class));
  13. Robolectric.getForegroundThreadScheduler().runOneTask();
  14. verify(activity, times(1)).onAuthenticationFinished(LineLoginResult.CANCEL);
  15. }
  16. }

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

  1. @Test
  2. public void testErrorOfRequestTokenProvider() throws Exception {
  3. Intent newIntentData = new Intent();
  4. doReturn(LineApiResponse.createAsSuccess(ONE_TIME_ID_AND_PASSWORD))
  5. .when(authApiClient)
  6. .getOneTimeIdAndPassword(CHANNEL_ID);
  7. doReturn(BrowserAuthenticationApi.Result.createAsInternalError("internalErrorMessage"))
  8. .when(browserAuthenticationApi)
  9. .getAuthenticationResultFrom(newIntentData);
  10. target.startLineAuthentication();
  11. Robolectric.getBackgroundThreadScheduler().runOneTask();
  12. Robolectric.getForegroundThreadScheduler().runOneTask();
  13. verify(browserAuthenticationApi, times(1))
  14. .getRequest(activity, config, ONE_TIME_ID_AND_PASSWORD, LINE_AUTH_PARAMS);
  15. target.handleIntentFromLineApp(newIntentData);
  16. verify(activity, times(1)).onAuthenticationFinished(
  17. new LineLoginResult(LineApiResponseCode.INTERNAL_ERROR, any(LineApiError.class)));
  18. }

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

  1. @Test
  2. public void testNetworkErrorOfGettingAccessToken() throws Exception {
  3. Intent newIntentData = new Intent();
  4. doReturn(LineApiResponse.createAsSuccess(ONE_TIME_ID_AND_PASSWORD))
  5. .when(authApiClient)
  6. .getOneTimeIdAndPassword(CHANNEL_ID);
  7. doReturn(BrowserAuthenticationApi.Result.createAsSuccess(REQUEST_TOKEN_STR, false))
  8. .when(browserAuthenticationApi)
  9. .getAuthenticationResultFrom(newIntentData);
  10. doReturn(LineApiResponse.createAsError(LineApiResponseCode.NETWORK_ERROR, LineApiError.DEFAULT))
  11. .when(authApiClient)
  12. .issueAccessToken(
  13. CHANNEL_ID, REQUEST_TOKEN_STR, ONE_TIME_ID_AND_PASSWORD, REDIRECT_URI);
  14. target.startLineAuthentication();
  15. Robolectric.getBackgroundThreadScheduler().runOneTask();
  16. Robolectric.getForegroundThreadScheduler().runOneTask();
  17. verify(browserAuthenticationApi, times(1))
  18. .getRequest(activity, config, ONE_TIME_ID_AND_PASSWORD, LINE_AUTH_PARAMS);
  19. target.handleIntentFromLineApp(newIntentData);
  20. Robolectric.getBackgroundThreadScheduler().runOneTask();
  21. Robolectric.getForegroundThreadScheduler().runOneTask();
  22. verify(activity, times(1)).onAuthenticationFinished(
  23. new LineLoginResult(LineApiResponseCode.NETWORK_ERROR, LineApiError.DEFAULT));
  24. }

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

  1. @Test
  2. public void testInternalErrorOfGettingAccessToken() throws Exception {
  3. Intent newIntentData = new Intent();
  4. doReturn(LineApiResponse.createAsSuccess(ONE_TIME_ID_AND_PASSWORD))
  5. .when(authApiClient)
  6. .getOneTimeIdAndPassword(CHANNEL_ID);
  7. doReturn(BrowserAuthenticationApi.Result.createAsSuccess(REQUEST_TOKEN_STR, null))
  8. .when(browserAuthenticationApi)
  9. .getAuthenticationResultFrom(newIntentData);
  10. doReturn(LineApiResponse.createAsError(LineApiResponseCode.INTERNAL_ERROR, LineApiError.DEFAULT))
  11. .when(authApiClient)
  12. .issueAccessToken(
  13. CHANNEL_ID, REQUEST_TOKEN_STR, ONE_TIME_ID_AND_PASSWORD, REDIRECT_URI);
  14. target.startLineAuthentication();
  15. Robolectric.getBackgroundThreadScheduler().runOneTask();
  16. Robolectric.getForegroundThreadScheduler().runOneTask();
  17. verify(browserAuthenticationApi, times(1))
  18. .getRequest(activity, config, ONE_TIME_ID_AND_PASSWORD, LINE_AUTH_PARAMS);
  19. target.handleIntentFromLineApp(newIntentData);
  20. Robolectric.getBackgroundThreadScheduler().runOneTask();
  21. Robolectric.getForegroundThreadScheduler().runOneTask();
  22. verify(activity, times(1)).onAuthenticationFinished(
  23. new LineLoginResult(LineApiResponseCode.INTERNAL_ERROR, LineApiError.DEFAULT));
  24. }

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

  1. @Test
  2. public void testInternalErrorOfGettingAccountInfo() throws Exception {
  3. Intent newIntentData = new Intent();
  4. doReturn(LineApiResponse.createAsSuccess(ONE_TIME_ID_AND_PASSWORD))
  5. .when(authApiClient)
  6. .getOneTimeIdAndPassword(CHANNEL_ID);
  7. doReturn(BrowserAuthenticationApi.Result.createAsSuccess(REQUEST_TOKEN_STR, null))
  8. .when(browserAuthenticationApi)
  9. .getAuthenticationResultFrom(newIntentData);
  10. doReturn(LineApiResponse.createAsSuccess(ISSUE_ACCESS_TOKEN_RESULT))
  11. .when(authApiClient)
  12. .issueAccessToken(
  13. CHANNEL_ID, REQUEST_TOKEN_STR, ONE_TIME_ID_AND_PASSWORD, REDIRECT_URI);
  14. doReturn(LineApiResponse.createAsError(LineApiResponseCode.INTERNAL_ERROR, LineApiError.DEFAULT))
  15. .when(talkApiClient)
  16. .getProfile(ACCESS_TOKEN);
  17. target.startLineAuthentication();
  18. Robolectric.getBackgroundThreadScheduler().runOneTask();
  19. Robolectric.getForegroundThreadScheduler().runOneTask();
  20. verify(browserAuthenticationApi, times(1))
  21. .getRequest(activity, config, ONE_TIME_ID_AND_PASSWORD, LINE_AUTH_PARAMS);
  22. target.handleIntentFromLineApp(newIntentData);
  23. Robolectric.getBackgroundThreadScheduler().runOneTask();
  24. Robolectric.getForegroundThreadScheduler().runOneTask();
  25. verify(activity, times(1)).onAuthenticationFinished(
  26. new LineLoginResult(LineApiResponseCode.INTERNAL_ERROR, LineApiError.DEFAULT));
  27. }

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

  1. @Test
  2. public void testStop() {
  3. if (adFetcher != null) {
  4. // not needed, but in case AdRequest is run
  5. server.enqueue(new MockResponse().setResponseCode(200).setBody(TestResponsesUT.blank()));
  6. clearAAIDAsyncTasks();
  7. // start an AdFetcher normally, until an AdRequest is queued
  8. adFetcher.start();
  9. Lock.pause(1000); // added this so jenkins can have enough time to process
  10. assertExpectedBGTasksAfterOneAdRequest(1);
  11. assertNotSame(AdFetcher.STATE.STOPPED, adFetcher.getState());
  12. adFetcher.stop();
  13. // pause until a scheduler has a task in queue
  14. waitForTasks();
  15. // Run the cancel command on AdRequest
  16. Robolectric.flushForegroundThreadScheduler();
  17. // Run the pending AdRequest from start() -- should have been canceled
  18. while (Robolectric.getBackgroundThreadScheduler().areAnyRunnable()) {
  19. Robolectric.getBackgroundThreadScheduler().runOneTask();
  20. }
  21. // A normally executed AdRequest will queue onPostExecute call to the UI thread,
  22. // but it should be canceled, and queue nothing
  23. int uiTaskCount = Robolectric.getForegroundThreadScheduler().size();
  24. assertEquals(0, uiTaskCount);
  25. assertEquals(AdFetcher.STATE.STOPPED, adFetcher.getState());
  26. }
  27. }

相关文章