42
42
import org .json .JSONException ;
43
43
import org .json .JSONObject ;
44
44
import org .junit .Test ;
45
- import org .mockito .*;
45
+ import org .mockito .ArgumentCaptor ;
46
+ import org .mockito .InOrder ;
47
+ import org .mockito .Mockito ;
48
+ import org .robolectric .Robolectric ;
49
+ import org .robolectric .shadows .ShadowLooper ;
46
50
47
51
import java .util .ArrayList ;
48
52
import java .util .Arrays ;
@@ -65,6 +69,7 @@ public class StackControllerTest extends BaseTest {
65
69
private ChildControllersRegistry childRegistry ;
66
70
private StackController uut ;
67
71
private ViewController child1 ;
72
+ private ViewController child1a ;
68
73
private ViewController child2 ;
69
74
private ViewController child3 ;
70
75
private ViewController child4 ;
@@ -84,6 +89,7 @@ public void beforeEach() {
84
89
renderChecker = spy (new RenderChecker ());
85
90
presenter = spy (new StackPresenter (activity , new TitleBarReactViewCreatorMock (), new TopBarBackgroundViewCreatorMock (), new TopBarButtonCreatorMock (), ImageLoaderMock .mock (), renderChecker , new Options ()));
86
91
child1 = spy (new SimpleViewController (activity , childRegistry , "child1" , new Options ()));
92
+ child1a = spy (new SimpleViewController (activity , childRegistry , "child1" , new Options ()));
87
93
child2 = spy (new SimpleViewController (activity , childRegistry , "child2" , new Options ()));
88
94
child3 = spy (new SimpleViewController (activity , childRegistry , "child3" , new Options ()));
89
95
child4 = spy (new SimpleViewController (activity , childRegistry , "child4" , new Options ()));
@@ -257,13 +263,16 @@ public void onSuccess(String childId) {
257
263
258
264
@ Test
259
265
public void setRoot_multipleChildren () {
266
+ Robolectric .getForegroundThreadScheduler ().pause ();
267
+
260
268
activity .setContentView (uut .getView ());
261
269
disablePushAnimation (child1 , child2 , child3 , child4 );
262
270
disablePopAnimation (child4 );
263
271
264
272
assertThat (uut .isEmpty ()).isTrue ();
265
273
uut .push (child1 , new CommandListenerAdapter ());
266
274
uut .push (child2 , new CommandListenerAdapter ());
275
+ ShadowLooper .idleMainLooper ();
267
276
assertThat (uut .getTopBar ().getTitleBar ().getNavigationIcon ()).isNotNull ();
268
277
uut .setRoot (Arrays .asList (child3 , child4 ), new CommandListenerAdapter () {
269
278
@ Override
@@ -275,6 +284,7 @@ public void onSuccess(String childId) {
275
284
276
285
assertThat (uut .getCurrentChild ()).isEqualTo (child4 );
277
286
uut .pop (Options .EMPTY , new CommandListenerAdapter ());
287
+ ShadowLooper .idleMainLooper ();
278
288
assertThat (uut .getTopBar ().getTitleBar ().getNavigationIcon ()).isNull ();
279
289
assertThat (uut .getCurrentChild ()).isEqualTo (child3 );
280
290
}
@@ -286,14 +296,25 @@ public void setRoot_doesNotCrashWhenCalledInQuickSuccession() {
286
296
disablePushAnimation (child1 );
287
297
uut .setRoot (Collections .singletonList (child1 ), new CommandListenerAdapter ());
288
298
299
+ ViewGroup c2View = child2 .getView ();
300
+ ViewGroup c3View = child3 .getView ();
289
301
uut .setRoot (Collections .singletonList (child2 ), new CommandListenerAdapter ());
290
302
uut .setRoot (Collections .singletonList (child3 ), new CommandListenerAdapter ());
291
- animator .endPushAnimation (child2 . getView () );
292
- animator .endPushAnimation (child3 . getView () );
303
+ animator .endPushAnimation (c2View );
304
+ animator .endPushAnimation (c3View );
293
305
294
306
assertContainsOnlyId (child3 .getId ());
295
307
}
296
308
309
+ @ Test
310
+ public void setRoot_doesNotCrashWhenCalledWithSameId () {
311
+ disablePushAnimation (child1 , child1a );
312
+ uut .setRoot (Collections .singletonList (child1 ), new CommandListenerAdapter ());
313
+ uut .setRoot (Collections .singletonList (child1a ), new CommandListenerAdapter ());
314
+
315
+ assertContainsOnlyId (child1a .getId ());
316
+ }
317
+
297
318
@ Test
298
319
public synchronized void pop () {
299
320
disablePushAnimation (child1 , child2 );
0 commit comments