本文整理了Java中org.robolectric.util.Scheduler.reset()
方法的一些代码示例,展示了Scheduler.reset()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Scheduler.reset()
方法的具体详情如下:
包路径:org.robolectric.util.Scheduler
类名称:Scheduler
方法名:reset
[英]Reset the internal state of the Scheduler.
[中]重置计划程序的内部状态。
代码示例来源:origin: robolectric/robolectric
public void quitUnchecked() {
synchronized (realObject) {
quit = true;
realObject.notifyAll();
getScheduler().reset();
shadowOf(realObject.getQueue()).reset();
}
}
代码示例来源:origin: robolectric/robolectric
@Test
public void reset_shouldClearPendingRunnables() throws Exception {
scheduler.pause();
TestRunnable runnable1 = new TestRunnable();
scheduler.post(runnable1);
assertThat(runnable1.wasRun).isFalse();
scheduler.reset();
TestRunnable runnable2 = new TestRunnable();
scheduler.post(runnable2);
assertThat(runnable1.wasRun).isFalse();
assertThat(runnable2.wasRun).isTrue();
}
代码示例来源:origin: robolectric/robolectric
@Resetter
public static synchronized void resetThreadLoopers() {
// Blech. We need to keep the main looper because somebody might refer to it in a static
// field. The other loopers need to be wrapped in WeakReferences so that they are not prevented from
// being garbage collected.
if (!isMainThread()) {
throw new IllegalStateException("you should only be calling this from the main thread!");
}
synchronized (loopingLoopers) {
for (Looper looper : loopingLoopers.values()) {
synchronized (looper) {
if (!shadowOf(looper).quit) {
looper.quit();
} else {
// Reset the schedulers of all loopers. This prevents un-run tasks queued up in static
// background handlers from leaking to subsequent tests.
shadowOf(looper).getScheduler().reset();
shadowOf(looper.getQueue()).reset();
}
}
}
}
// Because resetStaticState() is called by ParallelUniverse on startup before prepareMainLooper() is
// called, this might be null on that occasion.
if (mainLooper != null) {
shadowOf(mainLooper).reset();
}
}
代码示例来源:origin: robolectric/robolectric
@Test
public void reset_shouldUnPause() throws Exception {
scheduler.pause();
TestRunnable runnable = new TestRunnable();
scheduler.post(runnable);
assertThat(runnable.wasRun).isFalse();
scheduler.reset();
scheduler.post(runnable);
assertThat(runnable.wasRun).isTrue();
}
代码示例来源:origin: org.robolectric/shadows-core
public void quitUnchecked() {
synchronized (realObject) {
quit = true;
realObject.notifyAll();
getScheduler().reset();
}
}
代码示例来源:origin: org.robolectric/shadows-core-v23
public void quitUnchecked() {
synchronized (realObject) {
quit = true;
realObject.notifyAll();
getScheduler().reset();
}
}
代码示例来源:origin: org.robolectric/framework
public void quitUnchecked() {
synchronized (realObject) {
quit = true;
realObject.notifyAll();
getScheduler().reset();
}
}
代码示例来源:origin: appnexus/mobile-sdk-android
@After
public void tearDown() {
try {
server.shutdown();
bgScheduler.reset();
uiScheduler.reset();
} catch (IOException e) {
e.printStackTrace();
}
activity.finish();
}
代码示例来源:origin: org.robolectric/shadows-framework
public void quitUnchecked() {
synchronized (realObject) {
quit = true;
realObject.notifyAll();
getScheduler().reset();
shadowOf(realObject.getQueue()).reset();
}
}
代码示例来源:origin: appnexus/mobile-sdk-android
@After
public void tearDown() {
try {
server.shutdown();
bgScheduler.reset();
uiScheduler.reset();
} catch (IOException e) {
e.printStackTrace();
}
activity.finish();
}
代码示例来源:origin: appnexus/mobile-sdk-android
@Override
public void setup() {
super.setup();
Settings.getSettings().ua = "";
MediatedNativeSuccessful.didPass = false;
MediatedNativeSuccessful2.didPass = false;
Robolectric.getBackgroundThreadScheduler().reset();
Robolectric.getForegroundThreadScheduler().reset();
}
代码示例来源:origin: org.robolectric/framework
@Resetter
public static synchronized void resetThreadLoopers() {
// Blech. We need to keep the main looper because somebody might refer to it in a static
// field. The other loopers need to be wrapped in WeakReferences so that they are not prevented from
// being garbage collected.
if (!isMainThread()) {
throw new IllegalStateException("you should only be calling this from the main thread!");
}
synchronized (loopingLoopers) {
for (Looper looper : loopingLoopers.values()) {
synchronized (looper) {
if (!shadowOf(looper).quit) {
looper.quit();
} else {
// Reset the schedulers of all loopers. This prevents un-run tasks queued up in static
// background handlers from leaking to subsequent tests.
shadowOf(looper).getScheduler().reset();
}
}
}
}
// Because resetStaticState() is called by ParallelUniverse on startup before prepareMainLooper() is
// called, this might be null on that occasion.
if (mainLooper != null) {
shadowOf(mainLooper).reset();
}
}
代码示例来源:origin: appnexus/mobile-sdk-android
private void executeUTRequest() {
Robolectric.getBackgroundThreadScheduler().reset();
Robolectric.getForegroundThreadScheduler().reset();
adRequest.loadAd();
waitForTasks();
// execute main ad request
Robolectric.flushBackgroundThreadScheduler();
Robolectric.flushForegroundThreadScheduler();
}
代码示例来源:origin: org.robolectric/shadows-framework
@Resetter
public static synchronized void resetThreadLoopers() {
// Blech. We need to keep the main looper because somebody might refer to it in a static
// field. The other loopers need to be wrapped in WeakReferences so that they are not prevented from
// being garbage collected.
if (!isMainThread()) {
throw new IllegalStateException("you should only be calling this from the main thread!");
}
synchronized (loopingLoopers) {
for (Looper looper : loopingLoopers.values()) {
synchronized (looper) {
if (!shadowOf(looper).quit) {
looper.quit();
} else {
// Reset the schedulers of all loopers. This prevents un-run tasks queued up in static
// background handlers from leaking to subsequent tests.
shadowOf(looper).getScheduler().reset();
shadowOf(looper.getQueue()).reset();
}
}
}
}
// Because resetStaticState() is called by ParallelUniverse on startup before prepareMainLooper() is
// called, this might be null on that occasion.
if (mainLooper != null) {
shadowOf(mainLooper).reset();
}
}
代码示例来源:origin: appnexus/mobile-sdk-android
@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();
}
代码示例来源:origin: appnexus/mobile-sdk-android
@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());
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();
}
内容来源于网络,如有侵权,请联系作者删除!