use of io.reactivex.subjects.PublishSubject in project RxJava by ReactiveX.
the class ObservableDelayTest method testDelayWithObservableNormal1.
@Test
public void testDelayWithObservableNormal1() {
PublishSubject<Integer> source = PublishSubject.create();
final List<PublishSubject<Integer>> delays = new ArrayList<PublishSubject<Integer>>();
final int n = 10;
for (int i = 0; i < n; i++) {
PublishSubject<Integer> delay = PublishSubject.create();
delays.add(delay);
}
Function<Integer, Observable<Integer>> delayFunc = new Function<Integer, Observable<Integer>>() {
@Override
public Observable<Integer> apply(Integer t1) {
return delays.get(t1);
}
};
Observer<Object> o = TestHelper.mockObserver();
InOrder inOrder = inOrder(o);
source.delay(delayFunc).subscribe(o);
for (int i = 0; i < n; i++) {
source.onNext(i);
delays.get(i).onNext(i);
inOrder.verify(o).onNext(i);
}
source.onComplete();
inOrder.verify(o).onComplete();
inOrder.verifyNoMoreInteractions();
verify(o, never()).onError(any(Throwable.class));
}
use of io.reactivex.subjects.PublishSubject in project RxJava by ReactiveX.
the class ObservableDelayTest method testDelayWithObservableReorder.
@Test
public void testDelayWithObservableReorder() {
int n = 3;
PublishSubject<Integer> source = PublishSubject.create();
final List<PublishSubject<Integer>> subjects = new ArrayList<PublishSubject<Integer>>();
for (int i = 0; i < n; i++) {
subjects.add(PublishSubject.<Integer>create());
}
Observable<Integer> result = source.delay(new Function<Integer, Observable<Integer>>() {
@Override
public Observable<Integer> apply(Integer t1) {
return subjects.get(t1);
}
});
Observer<Object> o = TestHelper.mockObserver();
InOrder inOrder = inOrder(o);
result.subscribe(o);
for (int i = 0; i < n; i++) {
source.onNext(i);
}
source.onComplete();
inOrder.verify(o, never()).onNext(anyInt());
inOrder.verify(o, never()).onComplete();
for (int i = n - 1; i >= 0; i--) {
subjects.get(i).onComplete();
inOrder.verify(o).onNext(i);
}
inOrder.verify(o).onComplete();
verify(o, never()).onError(any(Throwable.class));
}
use of io.reactivex.subjects.PublishSubject in project mosby by sockeqwe.
the class DisposableIntentObserverTest method error.
@Test
public void error() {
PublishSubject subject = PublishSubject.create();
TestObserver sub = new TestObserver<>();
subject.subscribeWith(sub);
Exception originalException = new RuntimeException("I am the original Exception");
Exception expectedException = new IllegalStateException("View intents must not throw errors", originalException);
try {
Observable.error(originalException).subscribe(new DisposableIntentObserver(subject));
Assert.fail("Exception expected");
} catch (Exception e) {
Throwable cause = e.getCause();
Assert.assertEquals(expectedException.getMessage(), cause.getMessage());
Assert.assertEquals(originalException, cause.getCause());
}
sub.assertNotComplete().assertNoValues();
}
use of io.reactivex.subjects.PublishSubject in project RxJava by ReactiveX.
the class ObservableHideTest method testHidingError.
@Test
public void testHidingError() {
PublishSubject<Integer> src = PublishSubject.create();
Observable<Integer> dst = src.hide();
assertFalse(dst instanceof PublishSubject);
Observer<Object> o = TestHelper.mockObserver();
dst.subscribe(o);
src.onError(new TestException());
verify(o, never()).onNext(any());
verify(o, never()).onComplete();
verify(o).onError(any(TestException.class));
}
use of io.reactivex.subjects.PublishSubject in project mosby by sockeqwe.
the class MviBasePresenter method bindIntentActually.
@MainThread
private <I> Observable<I> bindIntentActually(@NonNull V view, @NonNull IntentRelayBinderPair<?> relayBinderPair) {
if (view == null) {
throw new NullPointerException("View is null. This is a Mosby internal bug. Please file an issue at https://github.com/sockeqwe/mosby/issues");
}
if (relayBinderPair == null) {
throw new NullPointerException("IntentRelayBinderPair is null. This is a Mosby internal bug. Please file an issue at https://github.com/sockeqwe/mosby/issues");
}
PublishSubject<I> intentRelay = (PublishSubject<I>) relayBinderPair.intentRelaySubject;
if (intentRelay == null) {
throw new NullPointerException("IntentRelay from binderPair is null. This is a Mosby internal bug. Please file an issue at https://github.com/sockeqwe/mosby/issues");
}
ViewIntentBinder<V, I> intentBinder = (ViewIntentBinder<V, I>) relayBinderPair.intentBinder;
if (intentBinder == null) {
throw new NullPointerException(ViewIntentBinder.class.getSimpleName() + " is null. This is a Mosby internal bug. Please file an issue at https://github.com/sockeqwe/mosby/issues");
}
Observable<I> intent = intentBinder.bind(view);
if (intent == null) {
throw new NullPointerException("Intent Observable returned from Binder " + intentBinder + " is null");
}
if (intentDisposals == null) {
intentDisposals = new CompositeDisposable();
}
intentDisposals.add(intent.subscribeWith(new DisposableIntentObserver<I>(intentRelay)));
return intentRelay;
}
Aggregations