Search in sources :

Example 11 with UiThreadTest

use of android.support.test.annotation.UiThreadTest in project realm-java by realm.

the class RxJavaTests method realmResults_closeInDoOnUnsubscribe.

@Test
@UiThreadTest
public void realmResults_closeInDoOnUnsubscribe() {
    Observable<RealmResults<AllTypes>> observable = realm.where(AllTypes.class).findAll().asObservable().doOnUnsubscribe(new Action0() {

        @Override
        public void call() {
            realm.close();
        }
    });
    subscription = observable.subscribe(new Action1<RealmResults<AllTypes>>() {

        @Override
        public void call(RealmResults<AllTypes> allTypes) {
        }
    });
    subscription.unsubscribe();
    assertTrue(realm.isClosed());
}
Also used : Action0(rx.functions.Action0) Action1(rx.functions.Action1) AllTypes(io.realm.entities.AllTypes) UiThreadTest(android.support.test.annotation.UiThreadTest) Test(org.junit.Test) UiThreadTest(android.support.test.annotation.UiThreadTest)

Example 12 with UiThreadTest

use of android.support.test.annotation.UiThreadTest in project realm-java by realm.

the class RxJavaTests method dynamicRealm_emittedOnSubscribe.

@Test
@UiThreadTest
public void dynamicRealm_emittedOnSubscribe() {
    final DynamicRealm dynamicRealm = DynamicRealm.getInstance(realm.getConfiguration());
    final AtomicBoolean subscribedNotified = new AtomicBoolean(false);
    subscription = dynamicRealm.asObservable().subscribe(new Action1<DynamicRealm>() {

        @Override
        public void call(DynamicRealm rxRealm) {
            assertTrue(rxRealm == dynamicRealm);
            subscribedNotified.set(true);
        }
    }, new Action1<Throwable>() {

        @Override
        public void call(Throwable throwable) {
            throwable.printStackTrace();
        }
    });
    assertTrue(subscribedNotified.get());
    dynamicRealm.close();
    subscription.unsubscribe();
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Action1(rx.functions.Action1) UiThreadTest(android.support.test.annotation.UiThreadTest) Test(org.junit.Test) UiThreadTest(android.support.test.annotation.UiThreadTest)

Example 13 with UiThreadTest

use of android.support.test.annotation.UiThreadTest in project realm-java by realm.

the class RxJavaTests method realm_emittedOnSubscribe.

@Test
@UiThreadTest
public void realm_emittedOnSubscribe() {
    final AtomicBoolean subscribedNotified = new AtomicBoolean(false);
    subscription = realm.asObservable().subscribe(new Action1<Realm>() {

        @Override
        public void call(Realm rxRealm) {
            assertTrue(rxRealm == realm);
            subscribedNotified.set(true);
        }
    });
    assertTrue(subscribedNotified.get());
    subscription.unsubscribe();
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Action1(rx.functions.Action1) UiThreadTest(android.support.test.annotation.UiThreadTest) Test(org.junit.Test) UiThreadTest(android.support.test.annotation.UiThreadTest)

Example 14 with UiThreadTest

use of android.support.test.annotation.UiThreadTest in project realm-java by realm.

the class RxJavaTests method dynamicRealm_closeInDoOnUnsubscribe.

@Test
@UiThreadTest
public void dynamicRealm_closeInDoOnUnsubscribe() {
    final DynamicRealm dynamicRealm = DynamicRealm.getInstance(realm.getConfiguration());
    Observable<DynamicRealm> observable = dynamicRealm.asObservable().doOnUnsubscribe(new Action0() {

        @Override
        public void call() {
            dynamicRealm.close();
        }
    });
    subscription = observable.subscribe(new Action1<DynamicRealm>() {

        @Override
        public void call(DynamicRealm rxRealm) {
        }
    });
    subscription.unsubscribe();
    assertTrue(dynamicRealm.isClosed());
}
Also used : Action0(rx.functions.Action0) Action1(rx.functions.Action1) UiThreadTest(android.support.test.annotation.UiThreadTest) Test(org.junit.Test) UiThreadTest(android.support.test.annotation.UiThreadTest)

Example 15 with UiThreadTest

use of android.support.test.annotation.UiThreadTest in project realm-java by realm.

the class RxJavaTests method findAllAsync_emittedOnSubscribe.

@Test
@UiThreadTest
public void findAllAsync_emittedOnSubscribe() {
    final AtomicBoolean subscribedNotified = new AtomicBoolean(false);
    final RealmResults<AllTypes> results = realm.where(AllTypes.class).findAllAsync();
    subscription = results.asObservable().subscribe(new Action1<RealmResults<AllTypes>>() {

        @Override
        public void call(RealmResults<AllTypes> rxResults) {
            assertTrue(rxResults == results);
            subscribedNotified.set(true);
        }
    });
    assertTrue(subscribedNotified.get());
    subscription.unsubscribe();
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Action1(rx.functions.Action1) AllTypes(io.realm.entities.AllTypes) UiThreadTest(android.support.test.annotation.UiThreadTest) Test(org.junit.Test) UiThreadTest(android.support.test.annotation.UiThreadTest)

Aggregations

UiThreadTest (android.support.test.annotation.UiThreadTest)51 Test (org.junit.Test)48 RecordingObserver (com.jakewharton.rxbinding2.RecordingObserver)15 Action1 (rx.functions.Action1)14 Activity (android.app.Activity)9 SmallTest (android.support.test.filters.SmallTest)8 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)7 Action0 (rx.functions.Action0)7 LargeTest (android.support.test.filters.LargeTest)6 LayoutInflater (android.view.LayoutInflater)6 Menu (android.view.Menu)6 AllTypes (io.realm.entities.AllTypes)6 TextInputLayoutActivity (android.support.design.testapp.TextInputLayoutActivity)5 MediumTest (android.support.test.filters.MediumTest)5 MenuItem (android.view.MenuItem)5 TabLayoutActions.selectTab (android.support.design.testutils.TabLayoutActions.selectTab)4 Bundle (android.os.Bundle)3 KeyEvent (android.view.KeyEvent)3 Before (org.junit.Before)3 ColorDrawable (android.graphics.drawable.ColorDrawable)2