use of com.jakewharton.rxbinding4.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();
}
use of com.jakewharton.rxbinding4.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();
}
use of com.jakewharton.rxbinding4.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();
}
use of com.jakewharton.rxbinding4.RecordingObserver in project RxBinding by JakeWharton.
the class RxDrawerLayoutTest method drawerOpen.
@Test
public void drawerOpen() {
RecordingObserver<Boolean> o = new RecordingObserver<>();
//
RxDrawerLayout.drawerOpen(view, RIGHT).subscribeOn(//
AndroidSchedulers.mainThread()).subscribe(o);
assertFalse(o.takeNext());
instrumentation.runOnMainSync(new Runnable() {
@Override
public void run() {
view.openDrawer(RIGHT);
}
});
assertTrue(o.takeNext());
instrumentation.runOnMainSync(new Runnable() {
@Override
public void run() {
view.closeDrawer(RIGHT);
}
});
assertFalse(o.takeNext());
o.dispose();
instrumentation.runOnMainSync(new Runnable() {
@Override
public void run() {
view.openDrawer(RIGHT);
}
});
o.assertNoMoreEvents();
}
use of com.jakewharton.rxbinding4.RecordingObserver in project RxBinding by JakeWharton.
the class RxSearchEditTextTest method keyboardDismisses.
@Test
@UiThreadTest
public void keyboardDismisses() {
RecordingObserver<Object> o = new RecordingObserver<>();
RxSearchEditText.keyboardDismisses(view).subscribe(o);
o.assertNoMoreEvents();
KeyEvent event = new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_BACK);
view.onKeyPreIme(KeyEvent.KEYCODE_BACK, event);
assertNotNull(o.takeNext());
o.dispose();
view.onKeyPreIme(KeyEvent.KEYCODE_BACK, event);
o.assertNoMoreEvents();
}
Aggregations