|
@@ -10,109 +10,69 @@ import com.reactnativenavigation.mocks.SimpleViewController;
|
10
|
10
|
|
11
|
11
|
import org.junit.Test;
|
12
|
12
|
|
13
|
|
-import java.util.Arrays;
|
|
13
|
+import java.util.ArrayList;
|
14
|
14
|
import java.util.Collection;
|
15
|
|
-import java.util.Collections;
|
|
15
|
+import java.util.List;
|
16
|
16
|
|
17
|
17
|
import static org.assertj.core.api.Java6Assertions.assertThat;
|
18
|
18
|
|
19
|
19
|
public class ParentControllerTest extends BaseTest {
|
20
|
20
|
|
21
|
21
|
private Activity activity;
|
|
22
|
+ private List<ViewController> children;
|
|
23
|
+ private ParentController uut;
|
22
|
24
|
|
23
|
25
|
@Override
|
24
|
26
|
public void beforeEach() {
|
25
|
27
|
super.beforeEach();
|
26
|
28
|
activity = newActivity();
|
27
|
|
- }
|
28
|
|
-
|
29
|
|
- @Test
|
30
|
|
- public void holdsViewGroup() throws Exception {
|
31
|
|
- ParentController uut = new ParentController(activity, "uut") {
|
32
|
|
- @Override
|
33
|
|
- public Collection<ViewController> getChildControllers() {
|
34
|
|
- return Collections.emptyList();
|
35
|
|
- }
|
|
29
|
+ children = new ArrayList<>();
|
|
30
|
+ uut = new ParentController(activity, "uut") {
|
36
|
31
|
|
37
|
32
|
@NonNull
|
38
|
33
|
@Override
|
39
|
34
|
protected ViewGroup createView() {
|
40
|
35
|
return new FrameLayout(activity);
|
41
|
36
|
}
|
42
|
|
- };
|
43
|
|
-
|
44
|
|
- assertThat(uut.getView()).isInstanceOf(ViewGroup.class);
|
45
|
|
- }
|
46
|
|
-
|
47
|
|
- @Test
|
48
|
|
- public void findControllerById_ReturnsSelfIfSameId() throws Exception {
|
49
|
|
- ParentController uut = new ParentController(activity, "uut") {
|
50
|
|
- @Override
|
51
|
|
- public Collection<ViewController> getChildControllers() {
|
52
|
|
- return Collections.emptyList();
|
53
|
|
- }
|
54
|
37
|
|
55
|
38
|
@NonNull
|
56
|
39
|
@Override
|
57
|
|
- protected ViewGroup createView() {
|
58
|
|
- return new FrameLayout(activity);
|
|
40
|
+ public Collection<ViewController> getChildControllers() {
|
|
41
|
+ return children;
|
59
|
42
|
}
|
60
|
43
|
};
|
61
|
|
-
|
62
|
|
- assertThat(uut.findControllerById("123")).isNull();
|
63
|
|
- assertThat(uut.findControllerById(uut.getId())).isEqualTo(uut);
|
64
|
44
|
}
|
65
|
45
|
|
66
|
46
|
@Test
|
67
|
|
- public void findControllerById_DeeplyInOneOfTheChildren() throws Exception {
|
68
|
|
- ViewController child1 = new SimpleViewController(activity, "child1");
|
69
|
|
- ViewController child2 = new SimpleViewController(activity, "child2");
|
70
|
|
-
|
71
|
|
- final StackController someInnerStack = new StackController(activity, "stack1");
|
72
|
|
- someInnerStack.push(child1);
|
73
|
|
- someInnerStack.push(child2);
|
|
47
|
+ public void holdsViewGroup() throws Exception {
|
|
48
|
+ assertThat(uut.getView()).isInstanceOf(ViewGroup.class);
|
|
49
|
+ }
|
74
|
50
|
|
75
|
|
- ParentController uut = new ParentController(activity, "uut") {
|
76
|
|
- @Override
|
77
|
|
- public Collection<ViewController> getChildControllers() {
|
78
|
|
- return Arrays.<ViewController>asList(someInnerStack);
|
79
|
|
- }
|
|
51
|
+ @Test
|
|
52
|
+ public void mustHaveChildControllers() throws Exception {
|
|
53
|
+ assertThat(uut.getChildControllers()).isNotNull();
|
|
54
|
+ }
|
80
|
55
|
|
81
|
|
- @NonNull
|
82
|
|
- @Override
|
83
|
|
- protected ViewGroup createView() {
|
84
|
|
- return new FrameLayout(activity);
|
85
|
|
- }
|
86
|
|
- };
|
|
56
|
+ @Test
|
|
57
|
+ public void findControllerById_ChildById() throws Exception {
|
|
58
|
+ SimpleViewController child1 = new SimpleViewController(activity, "child1");
|
|
59
|
+ SimpleViewController child2 = new SimpleViewController(activity, "child2");
|
|
60
|
+ children.add(child1);
|
|
61
|
+ children.add(child2);
|
87
|
62
|
|
88
|
|
- assertThat(uut.findControllerById("stack1")).isEqualTo(someInnerStack);
|
|
63
|
+ assertThat(uut.findControllerById("uut")).isEqualTo(uut);
|
89
|
64
|
assertThat(uut.findControllerById("child1")).isEqualTo(child1);
|
90
|
|
- assertThat(uut.findControllerById("child2")).isEqualTo(child2);
|
91
|
65
|
}
|
92
|
66
|
|
93
|
67
|
@Test
|
94
|
|
- public void findParentStackControllerForChildId() throws Exception {
|
95
|
|
- ViewController child1 = new SimpleViewController(activity, "child1");
|
96
|
|
- ViewController child2 = new SimpleViewController(activity, "child2");
|
97
|
|
-
|
98
|
|
- final StackController someInnerStack = new StackController(activity, "stack1");
|
99
|
|
- someInnerStack.push(child1);
|
100
|
|
- someInnerStack.push(child2);
|
|
68
|
+ public void findControllerById_Recursive() throws Exception {
|
|
69
|
+ StackController stackController = new StackController(activity, "stack");
|
|
70
|
+ SimpleViewController child1 = new SimpleViewController(activity, "child1");
|
|
71
|
+ SimpleViewController child2 = new SimpleViewController(activity, "child2");
|
|
72
|
+ stackController.push(child1);
|
|
73
|
+ stackController.push(child2);
|
|
74
|
+ children.add(stackController);
|
101
|
75
|
|
102
|
|
- ParentController uut = new ParentController(activity, "uut") {
|
103
|
|
- @Override
|
104
|
|
- public Collection<ViewController> getChildControllers() {
|
105
|
|
- return Arrays.<ViewController>asList(someInnerStack);
|
106
|
|
- }
|
107
|
|
-
|
108
|
|
- @NonNull
|
109
|
|
- @Override
|
110
|
|
- protected ViewGroup createView() {
|
111
|
|
- return new FrameLayout(activity);
|
112
|
|
- }
|
113
|
|
- };
|
114
|
|
-
|
115
|
|
- assertThat(uut.findParentStackControllerForChildId("not existing child")).isNull();
|
116
|
|
- assertThat(uut.findParentStackControllerForChildId("child2")).isEqualTo(someInnerStack);
|
|
76
|
+ assertThat(uut.findControllerById("child2")).isEqualTo(child2);
|
117
|
77
|
}
|
118
|
78
|
}
|