|
@@ -11,8 +11,6 @@ import org.assertj.android.api.Assertions;
|
11
|
11
|
import org.junit.Test;
|
12
|
12
|
import org.robolectric.Shadows;
|
13
|
13
|
|
14
|
|
-import java.lang.reflect.Field;
|
15
|
|
-
|
16
|
14
|
import static org.assertj.core.api.Java6Assertions.assertThat;
|
17
|
15
|
import static org.mockito.Mockito.mock;
|
18
|
16
|
import static org.mockito.Mockito.spy;
|
|
@@ -140,6 +138,8 @@ public class ViewControllerTest extends BaseTest {
|
140
|
138
|
|
141
|
139
|
@Test
|
142
|
140
|
public void onDestroy_RemovesGlobalLayoutListener() throws Exception {
|
|
141
|
+ new SimpleViewController(activity, "ensureNotNull").onDestroy();
|
|
142
|
+
|
143
|
143
|
ViewController spy = spy(uut);
|
144
|
144
|
View view = spy.getView();
|
145
|
145
|
Shadows.shadowOf(view).setMyParent(mock(ViewParent.class));
|
|
@@ -153,12 +153,16 @@ public class ViewControllerTest extends BaseTest {
|
153
|
153
|
}
|
154
|
154
|
|
155
|
155
|
@Test
|
156
|
|
- public void onDestroy_NullifiesTheView() throws Exception {
|
157
|
|
- assertThat(uut.getView()).isNotNull();
|
158
|
|
- uut.onDestroy();
|
159
|
|
- Field field = ViewController.class.getDeclaredField("view");
|
160
|
|
- field.setAccessible(true);
|
161
|
|
- assertThat(field.get(uut)).isNull();
|
|
156
|
+ public void onDestroy_CallsOnDisappearIfNeeded() throws Exception {
|
|
157
|
+ ViewController spy = spy(uut);
|
|
158
|
+ Shadows.shadowOf(spy.getView()).setMyParent(mock(ViewParent.class));
|
|
159
|
+ Assertions.assertThat(spy.getView()).isShown();
|
|
160
|
+ spy.getView().getViewTreeObserver().dispatchOnGlobalLayout();
|
|
161
|
+ verify(spy, times(1)).onAppear();
|
|
162
|
+
|
|
163
|
+ spy.onDestroy();
|
|
164
|
+
|
|
165
|
+ verify(spy, times(1)).onDisappear();
|
162
|
166
|
}
|
163
|
167
|
}
|
164
|
168
|
|