use of android.os.HandlerThread in project robolectric by robolectric.
the class ShadowLooperTest method differentThreads_getDifferentLoopers.
@Test
public void differentThreads_getDifferentLoopers() {
HandlerThread ht = getHandlerThread();
assertThat(ht.getLooper()).isNotSameAs(Looper.getMainLooper());
}
use of android.os.HandlerThread in project realm-java by realm.
the class RealmTests method closeRealmInChangeListener.
// Tests if close can be called from Realm change listener when there is no other listeners.
@Test
public void closeRealmInChangeListener() {
realm.close();
final CountDownLatch signalTestFinished = new CountDownLatch(1);
HandlerThread handlerThread = new HandlerThread("background");
handlerThread.start();
final Handler handler = new Handler(handlerThread.getLooper());
handler.post(new Runnable() {
@Override
public void run() {
final Realm realm = Realm.getInstance(realmConfig);
final RealmChangeListener<Realm> listener = new RealmChangeListener<Realm>() {
@Override
public void onChange(Realm object) {
if (realm.where(AllTypes.class).count() == 1) {
realm.removeChangeListener(this);
realm.close();
signalTestFinished.countDown();
}
}
};
realm.addChangeListener(listener);
realm.executeTransactionAsync(new Realm.Transaction() {
@Override
public void execute(Realm realm) {
realm.createObject(AllTypes.class);
}
});
}
});
TestHelper.awaitOrFail(signalTestFinished);
}
use of android.os.HandlerThread in project robolectric by robolectric.
the class ShadowHandlerThreadTest method shouldReturnNullIfThreadHasNotBeenStarted.
@Test
public void shouldReturnNullIfThreadHasNotBeenStarted() throws Exception {
handlerThread = new HandlerThread("test");
assertNull(handlerThread.getLooper());
}
use of android.os.HandlerThread in project robolectric by robolectric.
the class ShadowHandlerThreadTest method shouldQuitLooperAndThread.
@Test
public void shouldQuitLooperAndThread() throws Exception {
handlerThread = new HandlerThread("test");
Thread.setDefaultUncaughtExceptionHandler(new MyUncaughtExceptionHandler());
handlerThread.setUncaughtExceptionHandler(new MyUncaughtExceptionHandler());
handlerThread.start();
assertTrue(handlerThread.isAlive());
assertTrue(handlerThread.quit());
handlerThread.join();
assertFalse(handlerThread.isAlive());
handlerThread = null;
}
use of android.os.HandlerThread in project robolectric by robolectric.
the class ShadowHandlerThreadTest method shouldCallOnLooperPrepared.
@Test
public void shouldCallOnLooperPrepared() throws Exception {
final Boolean[] wasCalled = new Boolean[] { false };
final CountDownLatch latch = new CountDownLatch(1);
handlerThread = new HandlerThread("test") {
@Override
protected void onLooperPrepared() {
wasCalled[0] = true;
latch.countDown();
}
};
handlerThread.start();
try {
assertNotNull(handlerThread.getLooper());
latch.await(1, TimeUnit.SECONDS);
assertTrue(wasCalled[0]);
} finally {
handlerThread.quit();
}
}
Aggregations