use of io.reactivex.Observer in project RxJava by ReactiveX.
the class ObservableSubscriberTest method testOnStartCalledOnceViaLift.
@Test
public void testOnStartCalledOnceViaLift() {
final AtomicInteger c = new AtomicInteger();
Observable.just(1, 2, 3, 4).lift(new ObservableOperator<Integer, Integer>() {
@Override
public Observer<? super Integer> apply(final Observer<? super Integer> child) {
return new DefaultObserver<Integer>() {
@Override
public void onStart() {
c.incrementAndGet();
}
@Override
public void onComplete() {
child.onComplete();
}
@Override
public void onError(Throwable e) {
child.onError(e);
}
@Override
public void onNext(Integer t) {
child.onNext(t);
}
};
}
}).subscribe();
assertEquals(1, c.get());
}
use of io.reactivex.Observer in project RxJava by ReactiveX.
the class RxJavaPluginsTest method observableStart.
@SuppressWarnings("rawtypes")
@Test
public void observableStart() {
try {
RxJavaPlugins.setOnObservableSubscribe(new BiFunction<Observable, Observer, Observer>() {
@Override
public Observer apply(Observable o, final Observer t) {
return new Observer() {
@Override
public void onSubscribe(Disposable d) {
t.onSubscribe(d);
}
@SuppressWarnings("unchecked")
@Override
public void onNext(Object value) {
t.onNext((Integer) value - 9);
}
@Override
public void onError(Throwable e) {
t.onError(e);
}
@Override
public void onComplete() {
t.onComplete();
}
};
}
});
Observable.range(10, 3).test().assertValues(1, 2, 3).assertNoErrors().assertComplete();
} finally {
RxJavaPlugins.reset();
}
// make sure the reset worked
Observable.range(10, 3).test().assertValues(10, 11, 12).assertNoErrors().assertComplete();
}
use of io.reactivex.Observer in project SpotiQ by ZinoKader.
the class LobbyPresenter method createParty.
void createParty(String partyTitle, String partyPassword) {
Party party = new Party(partyTitle, partyPassword);
Observable.zip(partiesRepository.getParty(party.getTitle()), spotifyRepository.getMe(spotifyCommunicatorService.getWebApi()), (dbParty, spotifyUser) -> {
if (dbParty.exists()) {
throw new PartyExistsException();
} else {
User user = new User(spotifyUser.id, spotifyUser.display_name, spotifyUser.images);
party.setHostSpotifyId(user.getUserId());
return new UserPartyInformation(user, party);
}
}).flatMap(userPartyInformation -> Observable.zip(partiesRepository.createNewParty(userPartyInformation.getParty()), partiesRepository.addUserToParty(userPartyInformation.getUser(), userPartyInformation.getParty().getTitle()), (partyWasCreated, userWasAdded) -> {
if (!partyWasCreated)
throw new PartyNotCreatedException();
if (!userWasAdded)
throw new UserNotAddedException();
return userPartyInformation.getParty();
})).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new Observer<Party>() {
@Override
public void onNext(Party party) {
navigateToParty(party.getTitle());
}
@Override
public void onError(Throwable exception) {
if (exception instanceof PartyExistsException) {
getView().showMessage("Party " + partyTitle + " already exists");
} else if (exception instanceof UserNotAddedException) {
getView().showMessage("Something went wrong when adding you to the party");
} else {
getView().showMessage("Something went wrong when creating the party");
}
Log.d(LogTag.LOG_LOBBY, "Could not create party");
exception.printStackTrace();
}
@Override
public void onComplete() {
}
@Override
public void onSubscribe(Disposable d) {
}
});
}
Aggregations