RxPresenter extends Presenter<View> { public void restartable(int restartableId, Func0<Subscription> factory) { if (workingSubscribers.containsKey(restartableId)) stop(restartableId); restartables.put(restartableId, factory); }  Observable<View> view(); void add(Subscription subscription); void remove(Subscription subscription); void restartable(int restartableId, Func0<Subscription> factory); void restartable(int restartableId, Func4<T1, T2, T3, T4, Subscription> factory); void start(int restartableId); void start(int restartableId, T1 arg1, T2 arg2, T3 arg3, T4 arg4); void stop(int restartableId); void restartableFirst(int restartableId, final Func0<Observable<T>> observableFactory,
                                     final Action2<View, T> onNext, @Nullable final Action2<View, Throwable> onError); void restartableFirst(int restartableId,
                                                     final Func4<T1, T2, T3, T4, Observable<T>> observableFactory,
                                                     final Action2<View, T> onNext,
                                                     @Nullable final Action2<View, Throwable> onError); void restartableFirst(int restartableId, final Func0<Observable<T>> observableFactory, final Action2<View, T> onNext); void restartableLatestCache(int restartableId, final Func0<Observable<T>> observableFactory,
                                           final Action2<View, T> onNext, @Nullable final Action2<View, Throwable> onError); void restartableLatestCache(int restartableId, final Func0<Observable<T>> observableFactory, final Action2<View, T> onNext); void restartableReplay(int restartableId, final Func0<Observable<T>> observableFactory,
                                      final Action2<View, T> onNext, @Nullable final Action2<View, Throwable> onError); void restartableReplay(int restartableId, final Func0<Observable<T>> observableFactory, final Action2<View, T> onNext); DeliverLatestCache<View, T> deliverLatestCache(); DeliverFirst<View, T> deliverFirst(); DeliverReplay<View, T> deliverReplay(); Action1<Delivery<View, T>> split(final Action2<View, T> onNext, @Nullable final Action2<View, Throwable> onError); Action1<Delivery<View, T>> split(Action2<View, T> onNext); Observable<Delivery<View, T>> afterTakeViewDeliverLastestCache(); Observable<View> afterTakeView(); @Override void restore(); @Deprecated @Nullable @Override View getView();  }
@Test public void testRestartable() throws Exception { RxPresenter presenter = new RxPresenter(); presenter.create(null); Func0<Subscription> restartable = mock(Func0.class); Subscription subscription = mock(Subscription.class); when(restartable.call()).thenReturn(subscription); when(subscription.isUnsubscribed()).thenReturn(false); presenter.restartable(1, restartable); verifyNoMoreInteractions(restartable); presenter.start(1); verify(restartable, times(1)).call(); verifyNoMoreInteractions(restartable); Bundle bundle = BundleMock.mock(); presenter.onSave(bundle); presenter = new RxPresenter(); presenter.create(bundle); presenter.restartable(1, restartable); verify(restartable, times(2)).call(); verifyNoMoreInteractions(restartable); }