|
@@ -5,12 +5,12 @@ import android.support.v7.app.AppCompatActivity;
|
5
|
5
|
import android.view.View;
|
6
|
6
|
import android.view.ViewGroup;
|
7
|
7
|
|
8
|
|
-import com.reactnativenavigation.layout.bottomtabs.BottomTabs;
|
9
|
|
-import com.reactnativenavigation.layout.bottomtabs.BottomTabsContainer;
|
10
|
8
|
import com.reactnativenavigation.layout.Container;
|
11
|
9
|
import com.reactnativenavigation.layout.ContainerStack;
|
12
|
10
|
import com.reactnativenavigation.layout.LayoutFactory;
|
13
|
11
|
import com.reactnativenavigation.layout.LayoutNode;
|
|
12
|
+import com.reactnativenavigation.layout.bottomtabs.BottomTabs;
|
|
13
|
+import com.reactnativenavigation.layout.bottomtabs.BottomTabsContainer;
|
14
|
14
|
import com.reactnativenavigation.layout.bottomtabs.BottomTabsCreator;
|
15
|
15
|
|
16
|
16
|
import org.junit.Before;
|
|
@@ -26,8 +26,11 @@ import java.util.HashMap;
|
26
|
26
|
import java.util.List;
|
27
|
27
|
|
28
|
28
|
import static org.assertj.core.api.Java6Assertions.assertThat;
|
|
29
|
+import static org.mockito.ArgumentMatchers.any;
|
|
30
|
+import static org.mockito.ArgumentMatchers.anyString;
|
29
|
31
|
import static org.mockito.ArgumentMatchers.eq;
|
30
|
32
|
import static org.mockito.Mockito.mock;
|
|
33
|
+import static org.mockito.Mockito.verify;
|
31
|
34
|
import static org.mockito.Mockito.when;
|
32
|
35
|
|
33
|
36
|
@RunWith(RobolectricTestRunner.class)
|
|
@@ -62,7 +65,7 @@ public class LayoutFactoryTest {
|
62
|
65
|
}
|
63
|
66
|
|
64
|
67
|
@Test
|
65
|
|
- public void returnsContainerStack() throws Exception {
|
|
68
|
+ public void returnsContainerStack() throws Exception {
|
66
|
69
|
when(rootViewCreator.createRootView(eq(VIEW_ID), eq(VIEW_NAME))).thenReturn(mockView);
|
67
|
70
|
final LayoutNode containerNode = createContainerNode();
|
68
|
71
|
final LayoutNode stackNode = getContainerStackNode(containerNode);
|
|
@@ -75,7 +78,7 @@ public class LayoutFactoryTest {
|
75
|
78
|
}
|
76
|
79
|
|
77
|
80
|
@Test
|
78
|
|
- public void returnsContainerStackWithMultipleViews() throws Exception {
|
|
81
|
+ public void returnsContainerStackWithMultipleViews() throws Exception {
|
79
|
82
|
final View mockView1 = mock(View.class);
|
80
|
83
|
final View mockView2 = mock(View.class);
|
81
|
84
|
when(rootViewCreator.createRootView(eq(VIEW_ID), eq(VIEW_NAME))).thenReturn(mockView1);
|
|
@@ -97,20 +100,19 @@ public class LayoutFactoryTest {
|
97
|
100
|
|
98
|
101
|
@Test
|
99
|
102
|
public void returnsSingleTabContent() throws Exception {
|
|
103
|
+ BottomTabs bottomTabsMock = mock(BottomTabs.class);
|
100
|
104
|
when(rootViewCreator.createRootView(eq(VIEW_ID), eq(VIEW_NAME))).thenReturn(mockView);
|
101
|
105
|
final LayoutNode containerNode = createContainerNode();
|
102
|
106
|
final LayoutNode tabNode = createTabNode(containerNode);
|
103
|
107
|
|
104
|
|
- final View result = createLayoutFactory().create(tabNode);
|
|
108
|
+ final View result = createLayoutFactory(bottomTabsMock).create(tabNode);
|
105
|
109
|
|
106
|
110
|
assertThat(result).isInstanceOf(BottomTabsContainer.class);
|
107
|
|
- View containerView = assertViewChildrenCount((BottomTabsContainer) result, 1).get(0);
|
108
|
|
- assertThat(containerView).isInstanceOf(Container.class);
|
109
|
|
- assertViewChildren((Container) containerView, mockView);
|
|
111
|
+ verify(bottomTabsMock).addTab(eq("#0"), any(Container.class));
|
110
|
112
|
}
|
111
|
113
|
|
112
|
114
|
@Test(expected = IllegalArgumentException.class)
|
113
|
|
- public void throwsExceptionForUnknownType() throws Exception {
|
|
115
|
+ public void throwsExceptionForUnknownType() throws Exception {
|
114
|
116
|
when(rootViewCreator.createRootView(eq(VIEW_ID), eq(VIEW_NAME))).thenReturn(mockView);
|
115
|
117
|
final LayoutNode node = new LayoutNode(VIEW_ID, "***unknownType***", Collections.<String, Object>emptyMap());
|
116
|
118
|
|
|
@@ -118,9 +120,16 @@ public class LayoutFactoryTest {
|
118
|
120
|
}
|
119
|
121
|
|
120
|
122
|
private LayoutFactory createLayoutFactory() {
|
121
|
|
- BottomTabs bottomTabs = mock(BottomTabs.class);
|
122
|
|
- BottomTabsCreator bottomTabsCreator = mock(BottomTabsCreator.class);
|
123
|
|
- when(bottomTabsCreator.create()).thenReturn(bottomTabs);
|
|
123
|
+ return createLayoutFactory(null);
|
|
124
|
+ }
|
|
125
|
+
|
|
126
|
+ private LayoutFactory createLayoutFactory(BottomTabs bottomTabs) {
|
|
127
|
+ BottomTabsCreator bottomTabsCreator = null;
|
|
128
|
+ if (bottomTabs != null) {
|
|
129
|
+ bottomTabsCreator = mock(BottomTabsCreator.class);
|
|
130
|
+ when(bottomTabsCreator.create()).thenReturn(bottomTabs);
|
|
131
|
+ }
|
|
132
|
+
|
124
|
133
|
return new LayoutFactory(activity, rootViewCreator, bottomTabsCreator);
|
125
|
134
|
}
|
126
|
135
|
|