Search in sources :

Example 6 with UiThreadTest

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

the class RxSearchBarTest method searchQueryChangeEventsKeyboardDismissed.

@Test
@UiThreadTest
public void searchQueryChangeEventsKeyboardDismissed() {
    RecordingObserver<SearchBarSearchQueryEvent> o = new RecordingObserver<>();
    RxSearchBar.searchQueryChangeEvents(searchBar).subscribe(o);
    o.assertNoMoreEvents();
    KeyEvent keyEvent = new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_BACK);
    searchBar.setSearchQuery("q");
    searchEditText.onKeyPreIme(KeyEvent.KEYCODE_BACK, keyEvent);
    assertEquals(SearchBarSearchQueryChangedEvent.create(searchBar, "q"), o.takeNext());
    assertEquals(SearchBarSearchQueryKeyboardDismissedEvent.create(searchBar, "q"), o.takeNext());
    o.dispose();
    searchEditText.onKeyPreIme(KeyEvent.KEYCODE_BACK, keyEvent);
    o.assertNoMoreEvents();
}
Also used : KeyEvent(android.view.KeyEvent) RecordingObserver(com.jakewharton.rxbinding2.RecordingObserver) UiThreadTest(android.support.test.annotation.UiThreadTest) Test(org.junit.Test) UiThreadTest(android.support.test.annotation.UiThreadTest)

Example 7 with UiThreadTest

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

the class RxToolbarTest method itemClicks.

@Test
@UiThreadTest
public void itemClicks() {
    Menu menu = view.getMenu();
    MenuItem item1 = menu.add(0, 1, 0, "Hi");
    MenuItem item2 = menu.add(0, 2, 0, "Hey");
    RecordingObserver<MenuItem> o = new RecordingObserver<>();
    RxToolbar.itemClicks(view).subscribe(o);
    o.assertNoMoreEvents();
    menu.performIdentifierAction(2, 0);
    assertSame(item2, o.takeNext());
    menu.performIdentifierAction(1, 0);
    assertSame(item1, o.takeNext());
    o.dispose();
    menu.performIdentifierAction(2, 0);
    o.assertNoMoreEvents();
}
Also used : MenuItem(android.view.MenuItem) RecordingObserver(com.jakewharton.rxbinding2.RecordingObserver) Menu(android.view.Menu) Test(org.junit.Test) UiThreadTest(android.support.test.annotation.UiThreadTest) UiThreadTest(android.support.test.annotation.UiThreadTest)

Example 8 with UiThreadTest

use of android.support.test.annotation.UiThreadTest in project material-components-android by material-components.

the class TextInputLayoutTest method testDrawableStateChanged.

/** Regression test for b/31663756. */
@UiThreadTest
@Test
public void testDrawableStateChanged() {
    final Activity activity = activityTestRule.getActivity();
    final TextInputLayout layout = (TextInputLayout) activity.findViewById(R.id.textinput);
    // Force a drawable state change.
    layout.drawableStateChanged();
}
Also used : TextInputLayoutActivity(android.support.design.testapp.TextInputLayoutActivity) Activity(android.app.Activity) UiThreadTest(android.support.test.annotation.UiThreadTest) MediumTest(android.support.test.filters.MediumTest) Test(org.junit.Test) UiThreadTest(android.support.test.annotation.UiThreadTest)

Example 9 with UiThreadTest

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

the class RxJavaTests method realmList_closeInDoOnUnsubscribe.

@Test
@UiThreadTest
public void realmList_closeInDoOnUnsubscribe() {
    realm.beginTransaction();
    RealmList<Dog> list = realm.createObject(AllTypes.class).getColumnRealmList();
    realm.commitTransaction();
    Observable<RealmList<Dog>> observable = list.asObservable().doOnUnsubscribe(new Action0() {

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

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

Example 10 with UiThreadTest

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

the class RxJavaTests method unsubscribe_sameThread.

@Test
@UiThreadTest
public void unsubscribe_sameThread() {
    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);
        }
    });
    assertEquals(1, realm.sharedRealm.realmNotifier.getListenersListSize());
    subscription.unsubscribe();
    assertEquals(0, realm.sharedRealm.realmNotifier.getListenersListSize());
}
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)

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