Search in sources :

Example 16 with UiThreadTest

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

the class RxJavaTests method dynamicRealmResults_emittedOnSubscribe.

@Test
@UiThreadTest
public void dynamicRealmResults_emittedOnSubscribe() {
    final DynamicRealm dynamicRealm = DynamicRealm.getInstance(realm.getConfiguration());
    final AtomicBoolean subscribedNotified = new AtomicBoolean(false);
    final RealmResults<DynamicRealmObject> results = dynamicRealm.where(AllTypes.CLASS_NAME).findAll();
    subscription = results.asObservable().subscribe(new Action1<RealmResults<DynamicRealmObject>>() {

        @Override
        public void call(RealmResults<DynamicRealmObject> rxResults) {
            assertTrue(rxResults == results);
            subscribedNotified.set(true);
        }
    });
    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 17 with UiThreadTest

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

the class RxJavaTests method realmResults_emittedOnSubscribe.

@Test
@UiThreadTest
public void realmResults_emittedOnSubscribe() {
    final AtomicBoolean subscribedNotified = new AtomicBoolean(false);
    final RealmResults<AllTypes> results = realm.where(AllTypes.class).findAll();
    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)

Example 18 with UiThreadTest

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

the class RxJavaTests method findFirst_emittedOnSubscribe.

@Test
@UiThreadTest
public void findFirst_emittedOnSubscribe() {
    realm.beginTransaction();
    realm.createObject(AllTypes.class).setColumnLong(42);
    realm.commitTransaction();
    final AtomicBoolean subscribedNotified = new AtomicBoolean(false);
    subscription = realm.where(AllTypes.class).equalTo(AllTypes.FIELD_LONG, 42).findFirst().<AllTypes>asObservable().subscribe(new Action1<AllTypes>() {

        @Override
        public void call(AllTypes rxObject) {
            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)

Example 19 with UiThreadTest

use of android.support.test.annotation.UiThreadTest in project RxBinding by JakeWharton.

the class RxViewTest method longClicks.

@Test
@UiThreadTest
public void longClicks() {
    // We need a parent because long presses delegate to the parent.
    LinearLayout parent = new LinearLayout(context) {

        @Override
        public boolean showContextMenuForChild(View originalView) {
            return true;
        }
    };
    parent.addView(view);
    RecordingObserver<Object> o = new RecordingObserver<>();
    RxView.longClicks(view).subscribe(o);
    // No initial value.
    o.assertNoMoreEvents();
    view.performLongClick();
    assertNotNull(o.takeNext());
    view.performLongClick();
    assertNotNull(o.takeNext());
    o.dispose();
    view.performLongClick();
    o.assertNoMoreEvents();
}
Also used : RecordingObserver(com.jakewharton.rxbinding2.RecordingObserver) View(android.view.View) LinearLayout(android.widget.LinearLayout) UiThreadTest(android.support.test.annotation.UiThreadTest) Test(org.junit.Test) UiThreadTest(android.support.test.annotation.UiThreadTest)

Example 20 with UiThreadTest

use of android.support.test.annotation.UiThreadTest in project xDrip by NightscoutFoundation.

the class HomeEspressoTest method setUp.

@UiThreadTest
@Before
public synchronized void setUp() throws Exception {
    if (!onetime) {
        onetime = true;
        clearAllPrefs();
    }
    final Activity activity = mActivityRule.getActivity();
    activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD | WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON | WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON | WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON);
}
Also used : Activity(android.app.Activity) Before(org.junit.Before) 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