Search in sources :

Example 21 with RecordingObserver

use of com.jakewharton.rxbinding2.RecordingObserver in project RxBinding by JakeWharton.

the class RxViewTest method focusChanges.

@Test
@UiThreadTest
public void focusChanges() {
    // We need a parent which can take focus from our view when it attempts to clear.
    LinearLayout parent = new LinearLayout(context);
    parent.setFocusable(true);
    parent.addView(view);
    view.setFocusable(true);
    RecordingObserver<Boolean> o = new RecordingObserver<>();
    RxView.focusChanges(view).subscribe(o);
    assertFalse(o.takeNext());
    view.requestFocus();
    assertTrue(o.takeNext());
    view.clearFocus();
    assertFalse(o.takeNext());
    o.dispose();
    view.requestFocus();
    o.assertNoMoreEvents();
}
Also used : RecordingObserver(com.jakewharton.rxbinding2.RecordingObserver) LinearLayout(android.widget.LinearLayout) UiThreadTest(android.support.test.annotation.UiThreadTest) Test(org.junit.Test) UiThreadTest(android.support.test.annotation.UiThreadTest)

Example 22 with RecordingObserver

use of com.jakewharton.rxbinding2.RecordingObserver in project RxBinding by JakeWharton.

the class RxAdapterViewTest method itemSelections.

@Test
public void itemSelections() {
    RecordingObserver<Integer> o = new RecordingObserver<>();
    RxAdapterView.itemSelections(spinner).subscribeOn(AndroidSchedulers.mainThread()).subscribe(o);
    assertEquals(0, o.takeNext().intValue());
    instrumentation.runOnMainSync(new Runnable() {

        @Override
        public void run() {
            spinner.setSelection(2);
        }
    });
    assertEquals(2, o.takeNext().intValue());
    instrumentation.runOnMainSync(new Runnable() {

        @Override
        public void run() {
            spinner.setSelection(0);
        }
    });
    assertEquals(0, o.takeNext().intValue());
    o.dispose();
    instrumentation.runOnMainSync(new Runnable() {

        @Override
        public void run() {
            spinner.setSelection(1);
        }
    });
    o.assertNoMoreEvents();
}
Also used : UnsafeRunnable(com.jakewharton.rxbinding2.UnsafeRunnable) RecordingObserver(com.jakewharton.rxbinding2.RecordingObserver) Test(org.junit.Test)

Example 23 with RecordingObserver

use of com.jakewharton.rxbinding2.RecordingObserver in project RxBinding by JakeWharton.

the class RxAdapterViewTest method selectionEvents.

@Test
public void selectionEvents() {
    RecordingObserver<AdapterViewSelectionEvent> o = new RecordingObserver<>();
    RxAdapterView.selectionEvents(spinner).subscribeOn(AndroidSchedulers.mainThread()).subscribe(o);
    AdapterViewItemSelectionEvent event1 = (AdapterViewItemSelectionEvent) o.takeNext();
    assertSame(spinner, event1.view());
    assertNotNull(event1.selectedView());
    assertEquals(0, event1.position());
    assertEquals(0, event1.id());
    instrumentation.runOnMainSync(new Runnable() {

        @Override
        public void run() {
            spinner.setSelection(2);
        }
    });
    AdapterViewItemSelectionEvent event2 = (AdapterViewItemSelectionEvent) o.takeNext();
    assertSame(spinner, event2.view());
    assertNotNull(event2.selectedView());
    assertEquals(2, event2.position());
    assertEquals(2, event2.id());
    instrumentation.runOnMainSync(new Runnable() {

        @Override
        public void run() {
            activity.values.clear();
            activity.adapter.notifyDataSetChanged();
        }
    });
    assertEquals(AdapterViewNothingSelectionEvent.create(spinner), o.takeNext());
    o.dispose();
    instrumentation.runOnMainSync(new Runnable() {

        @Override
        public void run() {
            activity.values.add("Hello");
            activity.adapter.notifyDataSetChanged();
        }
    });
    o.assertNoMoreEvents();
}
Also used : UnsafeRunnable(com.jakewharton.rxbinding2.UnsafeRunnable) RecordingObserver(com.jakewharton.rxbinding2.RecordingObserver) Test(org.junit.Test)

Example 24 with RecordingObserver

use of com.jakewharton.rxbinding2.RecordingObserver in project RxBinding by JakeWharton.

the class RxPopupMenuTest 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<>();
    RxPopupMenu.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) PopupMenu(android.widget.PopupMenu) Menu(android.view.Menu) Test(org.junit.Test) UiThreadTest(android.support.test.annotation.UiThreadTest) UiThreadTest(android.support.test.annotation.UiThreadTest)

Aggregations

RecordingObserver (com.jakewharton.rxbinding2.RecordingObserver)24 Test (org.junit.Test)24 UiThreadTest (android.support.test.annotation.UiThreadTest)15 UnsafeRunnable (com.jakewharton.rxbinding2.UnsafeRunnable)7 Menu (android.view.Menu)5 MenuItem (android.view.MenuItem)5 KeyEvent (android.view.KeyEvent)3 TabLayout (android.support.design.widget.TabLayout)2 MotionEvent (android.view.MotionEvent)2 View (android.view.View)2 LinearLayout (android.widget.LinearLayout)2 Snackbar (android.support.design.widget.Snackbar)1 SwipeDismissBehavior (android.support.design.widget.SwipeDismissBehavior)1 Espresso.onView (android.support.test.espresso.Espresso.onView)1 PopupMenu (android.support.v7.widget.PopupMenu)1 PopupMenu (android.widget.PopupMenu)1 ViewScrollChangeEvent (com.jakewharton.rxbinding2.view.ViewScrollChangeEvent)1