From d5e62a618fb8521faa366358aa6cab7de78a6b09 Mon Sep 17 00:00:00 2001 From: Pascal Welsch Date: Tue, 25 Oct 2016 16:54:14 +0200 Subject: [PATCH] Fix view beeing null before unsubscribing from Subscriptions --- .../java/net/grandcentrix/thirtyinch/TiPresenter.java | 2 +- .../grandcentrix/thirtyinch/TiLifecycleObserverTest.java | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/thirtyinch/src/main/java/net/grandcentrix/thirtyinch/TiPresenter.java b/thirtyinch/src/main/java/net/grandcentrix/thirtyinch/TiPresenter.java index c5709a6f..49d4fd58 100644 --- a/thirtyinch/src/main/java/net/grandcentrix/thirtyinch/TiPresenter.java +++ b/thirtyinch/src/main/java/net/grandcentrix/thirtyinch/TiPresenter.java @@ -265,8 +265,8 @@ public final void detachView() { + " did not call through to super.onDetachView()"); } - mView = null; moveToState(State.VIEW_DETACHED, true); + mView = null; } /** diff --git a/thirtyinch/src/test/java/net/grandcentrix/thirtyinch/TiLifecycleObserverTest.java b/thirtyinch/src/test/java/net/grandcentrix/thirtyinch/TiLifecycleObserverTest.java index 8492a9a8..80deaa38 100644 --- a/thirtyinch/src/test/java/net/grandcentrix/thirtyinch/TiLifecycleObserverTest.java +++ b/thirtyinch/src/test/java/net/grandcentrix/thirtyinch/TiLifecycleObserverTest.java @@ -22,6 +22,7 @@ import java.util.ArrayList; import java.util.List; +import static junit.framework.Assert.assertNotNull; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotEquals; import static org.mockito.Mockito.mock; @@ -161,7 +162,7 @@ public void testSleep() throws Exception { @Override public void onChange(final TiPresenter.State state, final boolean beforeLifecycleEvent) { - states.add(new Object[]{state, beforeLifecycleEvent}); + states.add(new Object[]{state, beforeLifecycleEvent, mPresenter.getView()}); } }); @@ -172,10 +173,12 @@ public void onChange(final TiPresenter.State state, final Object[] beforeLast = states.get(states.size() - 2); assertEquals(beforeLast[0], TiPresenter.State.VIEW_DETACHED); assertEquals(beforeLast[1], false); + assertNotNull(beforeLast[2]); final Object[] last = states.get(states.size() - 1); assertEquals(last[0], TiPresenter.State.VIEW_DETACHED); assertEquals(last[1], true); + assertNotNull(last[2]); } @Test @@ -185,7 +188,7 @@ public void testWakeup() throws Exception { @Override public void onChange(final TiPresenter.State state, final boolean beforeLifecycleEvent) { - states.add(new Object[]{state, beforeLifecycleEvent}); + states.add(new Object[]{state, beforeLifecycleEvent, mPresenter.getView()}); } }); @@ -195,9 +198,11 @@ public void onChange(final TiPresenter.State state, final Object[] beforeLast = states.get(states.size() - 2); assertEquals(beforeLast[0], TiPresenter.State.VIEW_ATTACHED); assertEquals(beforeLast[1], false); + assertNotNull(beforeLast[2]); final Object[] last = states.get(states.size() - 1); assertEquals(last[0], TiPresenter.State.VIEW_ATTACHED); assertEquals(last[1], true); + assertNotNull(last[2]); } }