/** * Create a {@link MobiusLoop.Builder} to help you configure a MobiusLoop before starting it. * * <p>Once done configuring the loop you can start the loop using {@link * MobiusLoop.Factory#startFrom(Object)}. * * @param update the {@link Update} function of the loop * @param effectHandler the {@link ObservableTransformer} effect handler of the loop * @param <M> the model type * @param <E> the event type * @param <F> the effect type * @return a {@link MobiusLoop.Builder} instance that you can further configure before starting * the loop */ public static <M, E, F> MobiusLoop.Builder<M, E, F> loop( Update<M, E, F> update, ObservableTransformer<F, E> effectHandler) { return Mobius.loop(update, RxConnectables.fromTransformer(effectHandler)); }
@Test public void shouldPropagateErrorsFromConnectable() throws Exception { TestObserver<Integer> observer = input.compose(RxConnectables.toTransformer(connectable)).test(); input.onNext("crash"); observer.awaitTerminalEvent(1, TimeUnit.SECONDS); observer.assertError(throwable -> throwable.getMessage().equals("crashing!")); }
@Test public void shouldPropagateErrorsFromUpstream() throws Exception { final Throwable expected = new RuntimeException("expected"); TestObserver<Integer> observer = input.compose(RxConnectables.toTransformer(connectable)).test(); input.onError(expected); observer.awaitTerminalEvent(1, TimeUnit.SECONDS); observer.assertError(expected); } }
@Test public void shouldPropagateCompletion() throws Exception { TestObserver<Integer> observer = input.compose(RxConnectables.toTransformer(connectable)).test(); input.onNext("hi"); input.onComplete(); observer.awaitTerminalEvent(1, TimeUnit.SECONDS); observer.assertComplete(); }