|
@@ -38,9 +38,9 @@ public class StackControllerTest extends BaseTest {
|
38
|
38
|
@Test
|
39
|
39
|
public void holdsAStackOfViewControllers() throws Exception {
|
40
|
40
|
assertThat(uut.isEmpty()).isTrue();
|
41
|
|
- uut.push(child1);
|
42
|
|
- uut.push(child2);
|
43
|
|
- uut.push(child3);
|
|
41
|
+ uut.push(child1, new MockPromise());
|
|
42
|
+ uut.push(child2, new MockPromise());
|
|
43
|
+ uut.push(child3, new MockPromise());
|
44
|
44
|
assertThat(uut.peek()).isEqualTo(child3);
|
45
|
45
|
assertContainsOnlyId(child1.getId(), child2.getId(), child3.getId());
|
46
|
46
|
}
|
|
@@ -48,16 +48,16 @@ public class StackControllerTest extends BaseTest {
|
48
|
48
|
@Test
|
49
|
49
|
public void push() throws Exception {
|
50
|
50
|
assertThat(uut.isEmpty()).isTrue();
|
51
|
|
- uut.push(child1);
|
|
51
|
+ uut.push(child1, new MockPromise());
|
52
|
52
|
assertContainsOnlyId(child1.getId());
|
53
|
53
|
}
|
54
|
54
|
|
55
|
55
|
@Test
|
56
|
56
|
public void pop() throws Exception {
|
57
|
|
- uut.push(child1);
|
58
|
|
- uut.push(child2);
|
|
57
|
+ uut.push(child1, new MockPromise());
|
|
58
|
+ uut.push(child2, new MockPromise());
|
59
|
59
|
assertContainsOnlyId(child2.getId(), child1.getId());
|
60
|
|
- uut.pop();
|
|
60
|
+ uut.pop(new MockPromise());
|
61
|
61
|
assertContainsOnlyId(child1.getId());
|
62
|
62
|
}
|
63
|
63
|
|
|
@@ -66,7 +66,7 @@ public class StackControllerTest extends BaseTest {
|
66
|
66
|
assertThat(uut.peek()).isNull();
|
67
|
67
|
assertThat(uut.size()).isZero();
|
68
|
68
|
assertThat(uut.isEmpty()).isTrue();
|
69
|
|
- uut.push(child1);
|
|
69
|
+ uut.push(child1, new MockPromise());
|
70
|
70
|
assertThat(uut.peek()).isEqualTo(child1);
|
71
|
71
|
assertThat(uut.size()).isEqualTo(1);
|
72
|
72
|
assertThat(uut.isEmpty()).isFalse();
|
|
@@ -75,11 +75,11 @@ public class StackControllerTest extends BaseTest {
|
75
|
75
|
@Test
|
76
|
76
|
public void pushAssignsRefToSelfOnPushedController() throws Exception {
|
77
|
77
|
assertThat(child1.getParentStackController()).isNull();
|
78
|
|
- uut.push(child1);
|
|
78
|
+ uut.push(child1, new MockPromise());
|
79
|
79
|
assertThat(child1.getParentStackController()).isEqualTo(uut);
|
80
|
80
|
|
81
|
81
|
StackController anotherNavController = new StackController(activity, "another", new TestNavigationAnimator());
|
82
|
|
- anotherNavController.push(child2);
|
|
82
|
+ anotherNavController.push(child2, new MockPromise());
|
83
|
83
|
assertThat(child2.getParentStackController()).isEqualTo(anotherNavController);
|
84
|
84
|
}
|
85
|
85
|
|
|
@@ -88,11 +88,11 @@ public class StackControllerTest extends BaseTest {
|
88
|
88
|
assertThat(uut.isEmpty()).isTrue();
|
89
|
89
|
assertThat(uut.handleBack()).isFalse();
|
90
|
90
|
|
91
|
|
- uut.push(child1);
|
|
91
|
+ uut.push(child1, new MockPromise());
|
92
|
92
|
assertThat(uut.size()).isEqualTo(1);
|
93
|
93
|
assertThat(uut.handleBack()).isFalse();
|
94
|
94
|
|
95
|
|
- uut.push(child2);
|
|
95
|
+ uut.push(child2, new MockPromise());
|
96
|
96
|
assertThat(uut.size()).isEqualTo(2);
|
97
|
97
|
assertThat(uut.handleBack()).isTrue();
|
98
|
98
|
assertThat(uut.size()).isEqualTo(1);
|
|
@@ -102,11 +102,11 @@ public class StackControllerTest extends BaseTest {
|
102
|
102
|
@Test
|
103
|
103
|
public void popDoesNothingWhenZeroOrOneChild() throws Exception {
|
104
|
104
|
assertThat(uut.isEmpty()).isTrue();
|
105
|
|
- uut.pop();
|
|
105
|
+ uut.pop(new MockPromise());
|
106
|
106
|
assertThat(uut.isEmpty()).isTrue();
|
107
|
107
|
|
108
|
|
- uut.push(child1);
|
109
|
|
- uut.pop();
|
|
108
|
+ uut.push(child1, new MockPromise());
|
|
109
|
+ uut.pop(new MockPromise());
|
110
|
110
|
assertContainsOnlyId(child1.getId());
|
111
|
111
|
}
|
112
|
112
|
|
|
@@ -114,10 +114,10 @@ public class StackControllerTest extends BaseTest {
|
114
|
114
|
public void canPopWhenSizeIsMoreThanOne() throws Exception {
|
115
|
115
|
assertThat(uut.isEmpty()).isTrue();
|
116
|
116
|
assertThat(uut.canPop()).isFalse();
|
117
|
|
- uut.push(child1);
|
|
117
|
+ uut.push(child1, new MockPromise());
|
118
|
118
|
assertContainsOnlyId(child1.getId());
|
119
|
119
|
assertThat(uut.canPop()).isFalse();
|
120
|
|
- uut.push(child2);
|
|
120
|
+ uut.push(child2, new MockPromise());
|
121
|
121
|
assertContainsOnlyId(child1.getId(), child2.getId());
|
122
|
122
|
assertThat(uut.canPop()).isTrue();
|
123
|
123
|
}
|
|
@@ -125,37 +125,37 @@ public class StackControllerTest extends BaseTest {
|
125
|
125
|
@Test
|
126
|
126
|
public void pushAddsToViewTree() throws Exception {
|
127
|
127
|
assertThat(uut.getView().findViewById(child1.getView().getId())).isNull();
|
128
|
|
- uut.push(child1);
|
|
128
|
+ uut.push(child1, new MockPromise());
|
129
|
129
|
assertThat(uut.getView().findViewById(child1.getView().getId())).isNotNull();
|
130
|
130
|
}
|
131
|
131
|
|
132
|
132
|
@Test
|
133
|
133
|
public void pushRemovesPreviousFromTree() throws Exception {
|
134
|
134
|
assertThat(uut.getView().findViewById(child1.getView().getId())).isNull();
|
135
|
|
- uut.push(child1);
|
|
135
|
+ uut.push(child1, new MockPromise());
|
136
|
136
|
assertThat(uut.getView().findViewById(child1.getView().getId())).isNotNull();
|
137
|
|
- uut.push(child2);
|
|
137
|
+ uut.push(child2, new MockPromise());
|
138
|
138
|
assertThat(uut.getView().findViewById(child1.getView().getId())).isNull();
|
139
|
139
|
assertThat(uut.getView().findViewById(child2.getView().getId())).isNotNull();
|
140
|
140
|
}
|
141
|
141
|
|
142
|
142
|
@Test
|
143
|
143
|
public void popReplacesViewWithPrevious() throws Exception {
|
144
|
|
- uut.push(child1);
|
145
|
|
- uut.push(child2);
|
|
144
|
+ uut.push(child1, new MockPromise());
|
|
145
|
+ uut.push(child2, new MockPromise());
|
146
|
146
|
final View child2View = child2.getView();
|
147
|
147
|
final View child1View = child1.getView();
|
148
|
148
|
assertIsChildById(uut.getView(), child2View);
|
149
|
149
|
assertNotChildOf(uut.getView(), child1View);
|
150
|
|
- uut.pop();
|
|
150
|
+ uut.pop(new MockPromise());
|
151
|
151
|
assertNotChildOf(uut.getView(), child2View);
|
152
|
152
|
assertIsChildById(uut.getView(), child1View);
|
153
|
153
|
}
|
154
|
154
|
|
155
|
155
|
@Test
|
156
|
156
|
public void popSpecificWhenTopIsRegularPop() throws Exception {
|
157
|
|
- uut.push(child1);
|
158
|
|
- uut.push(child2);
|
|
157
|
+ uut.push(child1, new MockPromise());
|
|
158
|
+ uut.push(child2, new MockPromise());
|
159
|
159
|
uut.popSpecific(child2);
|
160
|
160
|
assertContainsOnlyId(child1.getId());
|
161
|
161
|
assertIsChildById(uut.getView(), child1.getView());
|
|
@@ -163,8 +163,8 @@ public class StackControllerTest extends BaseTest {
|
163
|
163
|
|
164
|
164
|
@Test
|
165
|
165
|
public void popSpecificDeepInStack() throws Exception {
|
166
|
|
- uut.push(child1);
|
167
|
|
- uut.push(child2);
|
|
166
|
+ uut.push(child1, new MockPromise());
|
|
167
|
+ uut.push(child2, new MockPromise());
|
168
|
168
|
assertIsChildById(uut.getView(), child2.getView());
|
169
|
169
|
uut.popSpecific(child1);
|
170
|
170
|
assertContainsOnlyId(child2.getId());
|
|
@@ -173,9 +173,9 @@ public class StackControllerTest extends BaseTest {
|
173
|
173
|
|
174
|
174
|
@Test
|
175
|
175
|
public void popTo_PopsTopUntilControllerIsNewTop() throws Exception {
|
176
|
|
- uut.push(child1);
|
177
|
|
- uut.push(child2);
|
178
|
|
- uut.push(child3);
|
|
176
|
+ uut.push(child1, new MockPromise());
|
|
177
|
+ uut.push(child2, new MockPromise());
|
|
178
|
+ uut.push(child3, new MockPromise());
|
179
|
179
|
|
180
|
180
|
assertThat(uut.size()).isEqualTo(3);
|
181
|
181
|
assertThat(uut.peek()).isEqualTo(child3);
|
|
@@ -188,8 +188,8 @@ public class StackControllerTest extends BaseTest {
|
188
|
188
|
|
189
|
189
|
@Test
|
190
|
190
|
public void popTo_NotAChildOfThisStack_DoesNothing() throws Exception {
|
191
|
|
- uut.push(child1);
|
192
|
|
- uut.push(child3);
|
|
191
|
+ uut.push(child1, new MockPromise());
|
|
192
|
+ uut.push(child3, new MockPromise());
|
193
|
193
|
assertThat(uut.size()).isEqualTo(2);
|
194
|
194
|
uut.popTo(child2);
|
195
|
195
|
assertThat(uut.size()).isEqualTo(2);
|
|
@@ -197,9 +197,9 @@ public class StackControllerTest extends BaseTest {
|
197
|
197
|
|
198
|
198
|
@Test
|
199
|
199
|
public void popToRoot_PopsEverythingAboveFirstController() throws Exception {
|
200
|
|
- uut.push(child1);
|
201
|
|
- uut.push(child2);
|
202
|
|
- uut.push(child3);
|
|
200
|
+ uut.push(child1, new MockPromise());
|
|
201
|
+ uut.push(child2, new MockPromise());
|
|
202
|
+ uut.push(child3, new MockPromise());
|
203
|
203
|
|
204
|
204
|
assertThat(uut.size()).isEqualTo(3);
|
205
|
205
|
assertThat(uut.peek()).isEqualTo(child3);
|
|
@@ -221,15 +221,15 @@ public class StackControllerTest extends BaseTest {
|
221
|
221
|
public void findControllerById_ReturnsSelfOrChildrenById() throws Exception {
|
222
|
222
|
assertThat(uut.findControllerById("123")).isNull();
|
223
|
223
|
assertThat(uut.findControllerById(uut.getId())).isEqualTo(uut);
|
224
|
|
- uut.push(child1);
|
|
224
|
+ uut.push(child1, new MockPromise());
|
225
|
225
|
assertThat(uut.findControllerById(child1.getId())).isEqualTo(child1);
|
226
|
226
|
}
|
227
|
227
|
|
228
|
228
|
@Test
|
229
|
229
|
public void findControllerById_Deeply() throws Exception {
|
230
|
230
|
StackController stack = new StackController(activity, "stack2", new TestNavigationAnimator());
|
231
|
|
- stack.push(child2);
|
232
|
|
- uut.push(stack);
|
|
231
|
+ stack.push(child2, new MockPromise());
|
|
232
|
+ uut.push(stack, new MockPromise());
|
233
|
233
|
assertThat(uut.findControllerById(child2.getId())).isEqualTo(child2);
|
234
|
234
|
}
|
235
|
235
|
|
|
@@ -238,12 +238,12 @@ public class StackControllerTest extends BaseTest {
|
238
|
238
|
child1 = spy(child1);
|
239
|
239
|
child2 = spy(child2);
|
240
|
240
|
child3 = spy(child3);
|
241
|
|
- uut.push(child1);
|
242
|
|
- uut.push(child2);
|
243
|
|
- uut.push(child3);
|
|
241
|
+ uut.push(child1, new MockPromise());
|
|
242
|
+ uut.push(child2, new MockPromise());
|
|
243
|
+ uut.push(child3, new MockPromise());
|
244
|
244
|
|
245
|
245
|
verify(child3, times(0)).destroy();
|
246
|
|
- uut.pop();
|
|
246
|
+ uut.pop(new MockPromise());
|
247
|
247
|
verify(child3, times(1)).destroy();
|
248
|
248
|
}
|
249
|
249
|
|
|
@@ -252,9 +252,9 @@ public class StackControllerTest extends BaseTest {
|
252
|
252
|
child1 = spy(child1);
|
253
|
253
|
child2 = spy(child2);
|
254
|
254
|
child3 = spy(child3);
|
255
|
|
- uut.push(child1);
|
256
|
|
- uut.push(child2);
|
257
|
|
- uut.push(child3);
|
|
255
|
+ uut.push(child1, new MockPromise());
|
|
256
|
+ uut.push(child2, new MockPromise());
|
|
257
|
+ uut.push(child3, new MockPromise());
|
258
|
258
|
|
259
|
259
|
verify(child2, times(0)).destroy();
|
260
|
260
|
uut.popSpecific(child2);
|
|
@@ -266,9 +266,9 @@ public class StackControllerTest extends BaseTest {
|
266
|
266
|
child1 = spy(child1);
|
267
|
267
|
child2 = spy(child2);
|
268
|
268
|
child3 = spy(child3);
|
269
|
|
- uut.push(child1);
|
270
|
|
- uut.push(child2);
|
271
|
|
- uut.push(child3);
|
|
269
|
+ uut.push(child1, new MockPromise());
|
|
270
|
+ uut.push(child2, new MockPromise());
|
|
271
|
+ uut.push(child3, new MockPromise());
|
272
|
272
|
|
273
|
273
|
verify(child2, times(0)).destroy();
|
274
|
274
|
verify(child3, times(0)).destroy();
|
|
@@ -279,11 +279,6 @@ public class StackControllerTest extends BaseTest {
|
279
|
279
|
|
280
|
280
|
private void assertContainsOnlyId(String... ids) {
|
281
|
281
|
assertThat(uut.size()).isEqualTo(ids.length);
|
282
|
|
- assertThat(uut.getChildControllers()).extracting(new Extractor<ViewController, String>() {
|
283
|
|
- @Override
|
284
|
|
- public String extract(final ViewController input) {
|
285
|
|
- return input.getId();
|
286
|
|
- }
|
287
|
|
- }).containsOnly(ids);
|
|
282
|
+ assertThat(uut.getChildControllers()).extracting((Extractor<ViewController, String>) ViewController::getId).containsOnly(ids);
|
288
|
283
|
}
|
289
|
284
|
}
|