use of io.reactivex.observers.TestObserver in project open-event-orga-app by fossasia.
the class EventRepositoryTest method shouldNotUpdateToggledEventOnError.
@Test
public void shouldNotUpdateToggledEventOnError() {
TestObserver testObserver = TestObserver.create();
Completable completable = Completable.complete().doOnSubscribe(testObserver::onSubscribe);
when(utilModel.isConnected()).thenReturn(true);
when(utilModel.getToken()).thenReturn(TOKEN);
when(eventService.patchEvent(EVENT.id, EVENT)).thenReturn(ObservableLift.error(Logger.TEST_ERROR));
when(databaseRepository.update(Event.class, UPDATED_EVENT)).thenReturn(completable);
eventRepository.updateEvent(EVENT).test();
testObserver.assertNotSubscribed();
}
use of io.reactivex.observers.TestObserver in project open-event-orga-app by fossasia.
the class EventRepositoryTest method shouldSaveCreatedEventToDatabaseOnSuccess.
@Test
public void shouldSaveCreatedEventToDatabaseOnSuccess() {
TestObserver testObserver = TestObserver.create();
Completable completable = Completable.complete().doOnSubscribe(testObserver::onSubscribe);
when(utilModel.isConnected()).thenReturn(true);
when(eventService.postEvent(EVENT)).thenReturn(Observable.just(EVENT));
when(databaseRepository.save(Event.class, EVENT)).thenReturn(completable);
eventRepository.createEvent(EVENT).test();
testObserver.assertSubscribed();
}
use of io.reactivex.observers.TestObserver in project open-event-orga-app by fossasia.
the class AttendeeRepositoryTest method shouldSaveAttendeesInCache.
@Test
public void shouldSaveAttendeesInCache() {
TestObserver testObserver = TestObserver.create();
Completable completable = Completable.complete().doOnSubscribe(testObserver::onSubscribe);
when(utilModel.isConnected()).thenReturn(true);
when(databaseRepository.getItems(eq(Attendee.class), any(SQLOperator.class))).thenReturn(Observable.empty());
when(databaseRepository.deleteAll(Attendee.class)).thenReturn(completable);
when(databaseRepository.saveList(Attendee.class, ATTENDEES)).thenReturn(completable);
when(eventService.getAttendees(43)).thenReturn(Observable.just(ATTENDEES));
// No force reload ensures use of cache
attendeeRepository.getAttendees(43, false).test();
testObserver.assertSubscribed();
// Verify loads from network
verify(eventService).getAttendees(43);
}
use of io.reactivex.observers.TestObserver in project open-event-orga-app by fossasia.
the class AttendeeRepositoryTest method shouldSaveToggledAttendeeCheck.
@Test
public void shouldSaveToggledAttendeeCheck() {
Attendee attendee = Attendee.builder().id(89).build();
attendee.setCheckedIn(true);
TestObserver testObserver = TestObserver.create();
Completable completable = Completable.complete().doOnSubscribe(testObserver::onSubscribe);
when(utilModel.isConnected()).thenReturn(true);
when(databaseRepository.getItems(eq(Attendee.class), any())).thenReturn(Observable.just(attendee));
when(databaseRepository.update(Attendee.class, attendee)).thenReturn(completable);
when(eventService.patchAttendee(89, attendee)).thenReturn(Observable.just(attendee));
Observable<Attendee> attendeeObservable = attendeeRepository.toggleAttendeeCheckStatus(attendee);
attendeeObservable.test();
testObserver.assertSubscribed();
}
use of io.reactivex.observers.TestObserver in project retrofit by square.
the class AsyncTest method bodyThrowingInOnErrorDeliveredToPlugin.
@Test
public void bodyThrowingInOnErrorDeliveredToPlugin() throws InterruptedException {
server.enqueue(new MockResponse().setResponseCode(404));
final CountDownLatch latch = new CountDownLatch(1);
final AtomicReference<Throwable> pluginRef = new AtomicReference<>();
RxJavaPlugins.setErrorHandler(new Consumer<Throwable>() {
@Override
public void accept(Throwable throwable) throws Exception {
if (!pluginRef.compareAndSet(null, throwable)) {
// Don't swallow secondary errors!
throw Exceptions.propagate(throwable);
}
latch.countDown();
}
});
TestObserver<Void> observer = new TestObserver<>();
final RuntimeException e = new RuntimeException();
final AtomicReference<Throwable> errorRef = new AtomicReference<>();
service.completable().subscribe(new ForwardingCompletableObserver(observer) {
@Override
public void onError(Throwable throwable) {
errorRef.set(throwable);
throw e;
}
});
latch.await(1, SECONDS);
// noinspection ThrowableResultOfMethodCallIgnored
CompositeException composite = (CompositeException) pluginRef.get();
assertThat(composite.getExceptions()).containsExactly(errorRef.get(), e);
}
Aggregations