|
|
@@ -16,18 +16,15 @@ import com.reactnativenavigation.layout.bottomtabs.BottomTabsCreator;
|
|
16
|
16
|
import org.junit.Before;
|
|
17
|
17
|
import org.junit.Test;
|
|
18
|
18
|
import org.junit.runner.RunWith;
|
|
19
|
|
-import org.mockito.ArgumentCaptor;
|
|
20
|
19
|
import org.robolectric.Robolectric;
|
|
21
|
20
|
import org.robolectric.RobolectricTestRunner;
|
|
22
|
21
|
|
|
23
|
|
-import java.util.ArrayList;
|
|
24
|
22
|
import java.util.Arrays;
|
|
25
|
23
|
import java.util.Collections;
|
|
26
|
24
|
import java.util.HashMap;
|
|
27
|
25
|
import java.util.List;
|
|
28
|
26
|
|
|
29
|
27
|
import static org.assertj.core.api.Java6Assertions.assertThat;
|
|
30
|
|
-import static org.mockito.ArgumentMatchers.any;
|
|
31
|
28
|
import static org.mockito.ArgumentMatchers.eq;
|
|
32
|
29
|
import static org.mockito.Mockito.mock;
|
|
33
|
30
|
import static org.mockito.Mockito.verify;
|
|
|
@@ -63,7 +60,7 @@ public class LayoutFactoryTest {
|
|
63
|
60
|
final ViewGroup result = (ViewGroup) createLayoutFactory().create(node);
|
|
64
|
61
|
|
|
65
|
62
|
assertThat(result).isInstanceOf(Container.class);
|
|
66
|
|
- assertViewChildren(result, mockView);
|
|
|
63
|
+ TestUtils.assertViewChildren(result, mockView);
|
|
67
|
64
|
}
|
|
68
|
65
|
|
|
69
|
66
|
@Test
|
|
|
@@ -75,8 +72,8 @@ public class LayoutFactoryTest {
|
|
75
|
72
|
final ViewGroup result = (ViewGroup) createLayoutFactory().create(stackNode);
|
|
76
|
73
|
|
|
77
|
74
|
assertThat(result).isInstanceOf(ContainerStack.class);
|
|
78
|
|
- ViewGroup container = (ViewGroup) assertViewChildrenCount(result, 1).get(0);
|
|
79
|
|
- assertViewChildren(container, mockView);
|
|
|
75
|
+ ViewGroup container = (ViewGroup) TestUtils.assertViewChildrenCount(result, 1).get(0);
|
|
|
76
|
+ TestUtils.assertViewChildren(container, mockView);
|
|
80
|
77
|
}
|
|
81
|
78
|
|
|
82
|
79
|
@Test
|
|
|
@@ -93,11 +90,11 @@ public class LayoutFactoryTest {
|
|
93
|
90
|
final ViewGroup result = (ViewGroup) createLayoutFactory().create(stackNode);
|
|
94
|
91
|
|
|
95
|
92
|
assertThat(result).isInstanceOf(ContainerStack.class);
|
|
96
|
|
- List<View> containers = assertViewChildrenCount(result, 2);
|
|
|
93
|
+ List<View> containers = TestUtils.assertViewChildrenCount(result, 2);
|
|
97
|
94
|
ViewGroup container1 = (ViewGroup) containers.get(0);
|
|
98
|
95
|
ViewGroup container2 = (ViewGroup) containers.get(1);
|
|
99
|
|
- assertViewChildren(container1, mockView1);
|
|
100
|
|
- assertViewChildren(container2, mockView2);
|
|
|
96
|
+ TestUtils.assertViewChildren(container1, mockView1);
|
|
|
97
|
+ TestUtils.assertViewChildren(container2, mockView2);
|
|
101
|
98
|
}
|
|
102
|
99
|
|
|
103
|
100
|
@Test
|
|
|
@@ -111,12 +108,11 @@ public class LayoutFactoryTest {
|
|
111
|
108
|
|
|
112
|
109
|
final View result = createLayoutFactory(bottomTabsMock).create(tabNode);
|
|
113
|
110
|
|
|
114
|
|
- assertThat(result).isInstanceOf(BottomTabsContainer.class);
|
|
|
111
|
+ verify(bottomTabsMock).add("#0");
|
|
115
|
112
|
|
|
116
|
|
- ArgumentCaptor<Container> containerCaptor = ArgumentCaptor.forClass(Container.class);
|
|
117
|
|
- verify(bottomTabsMock).addTab(eq("#0"), containerCaptor.capture());
|
|
118
|
|
- Container container = containerCaptor.getValue();
|
|
119
|
|
- View view = assertViewChildrenCount(container, 1).get(0);
|
|
|
113
|
+ assertThat(result).isInstanceOf(BottomTabsContainer.class);
|
|
|
114
|
+ Container container = (Container) TestUtils.assertViewChildrenCount((BottomTabsContainer) result, 1).get(0);
|
|
|
115
|
+ View view = TestUtils.assertViewChildrenCount(container, 1).get(0);
|
|
120
|
116
|
assertThat(view).isEqualTo(mockView);
|
|
121
|
117
|
}
|
|
122
|
118
|
|
|
|
@@ -136,8 +132,8 @@ public class LayoutFactoryTest {
|
|
136
|
132
|
final View result = createLayoutFactory(bottomTabsMock).create(tabNode);
|
|
137
|
133
|
|
|
138
|
134
|
assertThat(result).isInstanceOf(BottomTabsContainer.class);
|
|
139
|
|
- verify(bottomTabsMock).addTab(eq("#0"), any(Container.class));
|
|
140
|
|
- verify(bottomTabsMock).addTab(eq("#1"), any(ContainerStack.class));
|
|
|
135
|
+ verify(bottomTabsMock).add(eq("#0"));
|
|
|
136
|
+ verify(bottomTabsMock).add(eq("#1"));
|
|
141
|
137
|
}
|
|
142
|
138
|
|
|
143
|
139
|
@Test(expected = IllegalArgumentException.class)
|
|
|
@@ -183,19 +179,4 @@ public class LayoutFactoryTest {
|
|
183
|
179
|
node.children = Arrays.asList(children);
|
|
184
|
180
|
return node;
|
|
185
|
181
|
}
|
|
186
|
|
-
|
|
187
|
|
- private List<View> assertViewChildrenCount(ViewGroup view, int count) {
|
|
188
|
|
- assertThat(view.getChildCount()).isEqualTo(count);
|
|
189
|
|
-
|
|
190
|
|
- final List<View> children = new ArrayList<>(count);
|
|
191
|
|
- for (int i = 0; i < count; i++) {
|
|
192
|
|
- children.add(view.getChildAt(i));
|
|
193
|
|
- }
|
|
194
|
|
- return children;
|
|
195
|
|
- }
|
|
196
|
|
-
|
|
197
|
|
- private void assertViewChildren(ViewGroup view, View... children) {
|
|
198
|
|
- final List<View> childViews = assertViewChildrenCount(view, children.length);
|
|
199
|
|
- assertThat(childViews).isEqualTo(Arrays.asList(children));
|
|
200
|
|
- }
|
|
201
|
182
|
}
|