Java Code Examples for org.robolectric.Robolectric#getBackgroundThreadScheduler()
The following examples show how to use
org.robolectric.Robolectric#getBackgroundThreadScheduler() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BaseSetup.java From prebid-mobile-android with Apache License 2.0 | 6 votes |
@Before public void setup() { activity = Robolectric.buildActivity(MockMainActivity.class).create().get(); shadowOf(activity).grantPermissions("android.permission.INTERNET"); shadowOf(activity).grantPermissions("android.permission.CHANGE_NETWORK_STATE"); shadowOf(activity).grantPermissions("android.permission.MODIFY_PHONE_STATE"); shadowOf(activity).grantPermissions("android.permission.ACCESS_NETWORK_STATE"); server = new MockWebServer(); try { server.start(); } catch (IOException e) { fail(e.getMessage()); } FakeHttp.getFakeHttpLayer().interceptHttpRequests(true); FakeHttp.getFakeHttpLayer().interceptResponseContent(true); bgScheduler = Robolectric.getBackgroundThreadScheduler(); uiScheduler = Robolectric.getForegroundThreadScheduler(); Robolectric.flushBackgroundThreadScheduler(); Robolectric.flushForegroundThreadScheduler(); bgScheduler.pause(); uiScheduler.pause(); }
Example 2
Source File: BaseRoboTest.java From mobile-sdk-android with Apache License 2.0 | 6 votes |
@Before public void setup() { Robolectric.getBackgroundThreadScheduler().reset(); Robolectric.getForegroundThreadScheduler().reset(); ShadowLog.stream = System.out; activity = Robolectric.buildActivity(MockMainActivity.class).create().start().resume().visible().get(); shadowOf(activity).grantPermissions("android.permission.INTERNET"); server= new MockWebServer(); try { server.start(); HttpUrl url= server.url("/"); UTConstants.REQUEST_BASE_URL_UT = url.toString(); System.out.println(UTConstants.REQUEST_BASE_URL_UT); ShadowSettings.setTestURL(url.toString()); } catch (IOException e) { System.out.print("IOException"); } bgScheduler = Robolectric.getBackgroundThreadScheduler(); uiScheduler = Robolectric.getForegroundThreadScheduler(); Robolectric.flushBackgroundThreadScheduler(); Robolectric.flushForegroundThreadScheduler(); bgScheduler.pause(); uiScheduler.pause(); }
Example 3
Source File: BaseRoboTest.java From mobile-sdk-android with Apache License 2.0 | 6 votes |
@Before public void setup() { SDKSettings.setExternalExecutor(null); Robolectric.getBackgroundThreadScheduler().reset(); Robolectric.getForegroundThreadScheduler().reset(); ShadowLog.stream = System.out; activity = Robolectric.buildActivity(MockMainActivity.class).create().start().resume().visible().get(); shadowOf(activity).grantPermissions("android.permission.INTERNET"); server= new MockWebServer(); try { server.start(); HttpUrl url= server.url("/"); UTConstants.REQUEST_BASE_URL_UT = url.toString(); System.out.println(UTConstants.REQUEST_BASE_URL_UT); ShadowSettings.setTestURL(url.toString()); TestResponsesUT.setTestURL(url.toString()); } catch (IOException e) { System.out.print("IOException"); } bgScheduler = Robolectric.getBackgroundThreadScheduler(); uiScheduler = Robolectric.getForegroundThreadScheduler(); Robolectric.flushBackgroundThreadScheduler(); Robolectric.flushForegroundThreadScheduler(); bgScheduler.pause(); uiScheduler.pause(); }
Example 4
Source File: TestUtil.java From BlueSTSDK_Android with BSD 3-Clause "New" or "Revised" License | 5 votes |
static public void execAllAsyncTask(){ Scheduler bgTask = Robolectric.getBackgroundThreadScheduler(); Scheduler fgTask = Robolectric.getForegroundThreadScheduler(); while (fgTask.size()!=0 || bgTask.size()!=0){ Robolectric.flushBackgroundThreadScheduler(); Robolectric.flushForegroundThreadScheduler(); try { Thread.sleep(500); } catch (InterruptedException e) { e.printStackTrace(); } } }