|
@@ -13,6 +13,7 @@ import org.robolectric.Shadows;
|
13
|
13
|
|
14
|
14
|
import java.lang.reflect.Field;
|
15
|
15
|
|
|
16
|
+import static org.assertj.core.api.Assertions.fail;
|
16
|
17
|
import static org.assertj.core.api.Java6Assertions.assertThat;
|
17
|
18
|
import static org.mockito.Mockito.mock;
|
18
|
19
|
import static org.mockito.Mockito.spy;
|
|
@@ -89,13 +90,13 @@ public class ViewControllerTest extends BaseTest {
|
89
|
90
|
ViewController spy = spy(uut);
|
90
|
91
|
spy.getView().getViewTreeObserver().dispatchOnGlobalLayout();
|
91
|
92
|
Assertions.assertThat(spy.getView()).isNotShown();
|
92
|
|
- verify(spy, times(0)).onAppear();
|
|
93
|
+ verify(spy, times(0)).onViewAppeared();
|
93
|
94
|
|
94
|
95
|
Shadows.shadowOf(spy.getView()).setMyParent(mock(ViewParent.class));
|
95
|
96
|
spy.getView().getViewTreeObserver().dispatchOnGlobalLayout();
|
96
|
97
|
Assertions.assertThat(spy.getView()).isShown();
|
97
|
98
|
|
98
|
|
- verify(spy, times(1)).onAppear();
|
|
99
|
+ verify(spy, times(1)).onViewAppeared();
|
99
|
100
|
}
|
100
|
101
|
|
101
|
102
|
@Test
|
|
@@ -107,7 +108,7 @@ public class ViewControllerTest extends BaseTest {
|
107
|
108
|
spy.getView().getViewTreeObserver().dispatchOnGlobalLayout();
|
108
|
109
|
spy.getView().getViewTreeObserver().dispatchOnGlobalLayout();
|
109
|
110
|
|
110
|
|
- verify(spy, times(1)).onAppear();
|
|
111
|
+ verify(spy, times(1)).onViewAppeared();
|
111
|
112
|
}
|
112
|
113
|
|
113
|
114
|
@Test
|
|
@@ -116,13 +117,13 @@ public class ViewControllerTest extends BaseTest {
|
116
|
117
|
Shadows.shadowOf(spy.getView()).setMyParent(mock(ViewParent.class));
|
117
|
118
|
Assertions.assertThat(spy.getView()).isShown();
|
118
|
119
|
spy.getView().getViewTreeObserver().dispatchOnGlobalLayout();
|
119
|
|
- verify(spy, times(1)).onAppear();
|
120
|
|
- verify(spy, times(0)).onDisappear();
|
|
120
|
+ verify(spy, times(1)).onViewAppeared();
|
|
121
|
+ verify(spy, times(0)).onViewDisappear();
|
121
|
122
|
|
122
|
123
|
spy.getView().setVisibility(View.GONE);
|
123
|
124
|
spy.getView().getViewTreeObserver().dispatchOnGlobalLayout();
|
124
|
125
|
Assertions.assertThat(spy.getView()).isNotShown();
|
125
|
|
- verify(spy, times(1)).onDisappear();
|
|
126
|
+ verify(spy, times(1)).onViewDisappear();
|
126
|
127
|
}
|
127
|
128
|
|
128
|
129
|
@Test
|
|
@@ -135,23 +136,23 @@ public class ViewControllerTest extends BaseTest {
|
135
|
136
|
spy.getView().getViewTreeObserver().dispatchOnGlobalLayout();
|
136
|
137
|
spy.getView().getViewTreeObserver().dispatchOnGlobalLayout();
|
137
|
138
|
spy.getView().getViewTreeObserver().dispatchOnGlobalLayout();
|
138
|
|
- verify(spy, times(1)).onDisappear();
|
|
139
|
+ verify(spy, times(1)).onViewDisappear();
|
139
|
140
|
}
|
140
|
141
|
|
141
|
142
|
@Test
|
142
|
143
|
public void onDestroy_RemovesGlobalLayoutListener() throws Exception {
|
143
|
|
- new SimpleViewController(activity, "ensureNotNull").onDestroy();
|
|
144
|
+ new SimpleViewController(activity, "ensureNotNull").destroy();
|
144
|
145
|
|
145
|
146
|
ViewController spy = spy(uut);
|
146
|
147
|
View view = spy.getView();
|
147
|
148
|
Shadows.shadowOf(view).setMyParent(mock(ViewParent.class));
|
148
|
149
|
|
149
|
|
- spy.onDestroy();
|
|
150
|
+ spy.destroy();
|
150
|
151
|
|
151
|
152
|
Assertions.assertThat(view).isShown();
|
152
|
153
|
view.getViewTreeObserver().dispatchOnGlobalLayout();
|
153
|
|
- verify(spy, times(0)).onAppear();
|
154
|
|
- verify(spy, times(0)).onDisappear();
|
|
154
|
+ verify(spy, times(0)).onViewAppeared();
|
|
155
|
+ verify(spy, times(0)).onViewDisappear();
|
155
|
156
|
|
156
|
157
|
Field field = ViewController.class.getDeclaredField("view");
|
157
|
158
|
field.setAccessible(true);
|
|
@@ -164,11 +165,16 @@ public class ViewControllerTest extends BaseTest {
|
164
|
165
|
Shadows.shadowOf(spy.getView()).setMyParent(mock(ViewParent.class));
|
165
|
166
|
Assertions.assertThat(spy.getView()).isShown();
|
166
|
167
|
spy.getView().getViewTreeObserver().dispatchOnGlobalLayout();
|
167
|
|
- verify(spy, times(1)).onAppear();
|
|
168
|
+ verify(spy, times(1)).onViewAppeared();
|
168
|
169
|
|
169
|
|
- spy.onDestroy();
|
|
170
|
+ spy.destroy();
|
170
|
171
|
|
171
|
|
- verify(spy, times(1)).onDisappear();
|
|
172
|
+ verify(spy, times(1)).onViewDisappear();
|
|
173
|
+ }
|
|
174
|
+
|
|
175
|
+ @Test
|
|
176
|
+ public void onDestroy_RemovesSelfFromParentIfExists() throws Exception {
|
|
177
|
+ fail("implement");
|
172
|
178
|
}
|
173
|
179
|
}
|
174
|
180
|
|