Skip to content
This repository has been archived by the owner on Mar 16, 2021. It is now read-only.

Commit

Permalink
Null mUiDisposables when moving to detached state
Browse files Browse the repository at this point in the history
  • Loading branch information
Pascal Welsch committed Jan 19, 2017
1 parent 69cb50e commit ef70fe4
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,15 @@ public RxTiPresenterDisposableHandler(final TiPresenter presenter) {
public void onChange(final TiPresenter.State state,
final boolean beforeLifecycleEvent) {
if (state == TiPresenter.State.VIEW_DETACHED && beforeLifecycleEvent) {
// dispose all UI disposable created in wakeUp() and added
// dispose all UI disposable created in onAttachView(TiView) and added
// via manageViewDisposable(Disposable...)
if (mUiDisposables != null) {
mUiDisposables.dispose();
mUiDisposables = null;
}
}

if (state == TiPresenter.State.VIEW_ATTACHED) {
if (state == TiPresenter.State.VIEW_ATTACHED && beforeLifecycleEvent) {
mUiDisposables = new CompositeDisposable();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,24 @@ public void testManageVieDisposable_WithDetachSingleDispose_ShouldDispose()
}

@Test
public void testManageViewDisposable_DetachBeforeAttach_ShouldThrowIllegalStateException()
public void testManageViewDisposable_manageAfterDetach_ShouldThrowIllegalStateException()
throws Exception {
mPresenter.create();
mPresenter.attachView(mView);
mPresenter.detachView();

final TestObserver<Integer> testObserver = new TestObserver<>();

try {
mDisposableHandler.manageViewDisposable(testObserver);
fail("no exception");
} catch (Exception e) {
assertThat(e.getMessage(), containsString("when there is no view"));
}
}

@Test
public void testManageViewDisposable_manageBeforeViewAttached_ShouldThrowIllegalStateException()
throws Exception {
mPresenter.create();
final TestObserver<Integer> testObserver = new TestObserver<>();
Expand Down Expand Up @@ -130,7 +147,6 @@ public void testManageViewDisposeable_WithOneAlreadyDisposed_ShouldNotAddToDispo
assertThat(secondTestObserver.isDisposed(), is(true));
}


@Test
public void testManagerViewDisposable_WithDetach_ShouldDispose() throws Exception {
mPresenter.create();
Expand Down

0 comments on commit ef70fe4

Please sign in to comment.