|
@@ -9,19 +9,20 @@ import org.junit.Test;
|
9
|
9
|
import org.robolectric.Shadows;
|
10
|
10
|
|
11
|
11
|
import static org.assertj.core.api.Java6Assertions.assertThat;
|
12
|
|
-import static org.mockito.Mockito.spy;
|
13
|
12
|
|
14
|
13
|
public class NavigatorTest extends BaseTest {
|
15
|
14
|
private Activity activity;
|
16
|
15
|
private Navigator uut;
|
17
|
|
- private SimpleViewController viewController;
|
|
16
|
+ private ViewController child1;
|
|
17
|
+ private ViewController child2;
|
18
|
18
|
|
19
|
19
|
@Override
|
20
|
20
|
public void beforeEach() {
|
21
|
21
|
super.beforeEach();
|
22
|
22
|
activity = newActivity();
|
23
|
|
- viewController = spy(new SimpleViewController(activity, "simpleViewController"));
|
24
|
23
|
uut = new Navigator(activity);
|
|
24
|
+ child1 = new SimpleViewController(activity, "child1");
|
|
25
|
+ child2 = new SimpleViewController(activity, "child2");
|
25
|
26
|
}
|
26
|
27
|
|
27
|
28
|
|
|
@@ -42,4 +43,24 @@ public class NavigatorTest extends BaseTest {
|
42
|
43
|
uut.onActivityCreated();
|
43
|
44
|
assertThat(Shadows.shadowOf(activity).getContentView()).isNotNull().isEqualTo(uut.getView());
|
44
|
45
|
}
|
|
46
|
+
|
|
47
|
+ @Test
|
|
48
|
+ public void setRoot_AddsChildControllerView() throws Exception {
|
|
49
|
+ assertThat(uut.getView().getChildCount()).isZero();
|
|
50
|
+ uut.setRoot(child1);
|
|
51
|
+ assertHasSingleChildViewOf(child1);
|
|
52
|
+ }
|
|
53
|
+
|
|
54
|
+ @Test
|
|
55
|
+ public void setRoot_ReplacesExistingChildControllerView() throws Exception {
|
|
56
|
+ uut.setRoot(child1);
|
|
57
|
+ uut.setRoot(child2);
|
|
58
|
+ assertHasSingleChildViewOf(child2);
|
|
59
|
+ }
|
|
60
|
+
|
|
61
|
+ private void assertHasSingleChildViewOf(ViewController vc) {
|
|
62
|
+ assertThat(uut.getView().getChildCount()).isEqualTo(1);
|
|
63
|
+ assertThat(uut.getView().getChildAt(0)).isEqualTo(vc.getView()).isNotNull();
|
|
64
|
+ }
|
|
65
|
+
|
45
|
66
|
}
|