Browse Source

Initial TopBar refactor

Guy Carmeli 6 years ago
parent
commit
6d25438628
17 changed files with 203 additions and 132 deletions
  1. 4
    2
      lib/android/app/src/main/java/com/reactnativenavigation/parse/LayoutFactory.java
  2. 12
    3
      lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/StackController.java
  3. 2
    2
      lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/ViewController.java
  4. 42
    0
      lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/topbar/TopBarController.java
  5. 9
    14
      lib/android/app/src/main/java/com/reactnativenavigation/views/StackLayout.java
  6. 12
    11
      lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/BottomTabsControllerTest.java
  7. 7
    6
      lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/ComponentViewControllerTest.java
  8. 7
    6
      lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/FloatingActionButtonTest.java
  9. 24
    22
      lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/NavigatorTest.java
  10. 12
    11
      lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/OptionsApplyingTest.java
  11. 11
    10
      lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/ParentControllerTest.java
  12. 16
    5
      lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/StackControllerTest.java
  13. 4
    3
      lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/TopBarButtonControllerTest.java
  14. 12
    11
      lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/TopTabsViewControllerTest.java
  15. 18
    17
      lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/ViewControllerTest.java
  16. 5
    4
      lib/android/app/src/test/java/com/reactnativenavigation/views/TopBarBackgroundComponentTest.java
  17. 6
    5
      lib/android/app/src/test/java/com/reactnativenavigation/views/TopBarTest.java

+ 4
- 2
lib/android/app/src/main/java/com/reactnativenavigation/parse/LayoutFactory.java View File

@@ -13,12 +13,13 @@ import com.reactnativenavigation.viewcontrollers.ViewController;
13 13
 import com.reactnativenavigation.viewcontrollers.bottomtabs.BottomTabsController;
14 14
 import com.reactnativenavigation.viewcontrollers.externalcomponent.ExternalComponentCreator;
15 15
 import com.reactnativenavigation.viewcontrollers.externalcomponent.ExternalComponentViewController;
16
+import com.reactnativenavigation.viewcontrollers.topbar.TopBarController;
16 17
 import com.reactnativenavigation.viewcontrollers.toptabs.TopTabsController;
17 18
 import com.reactnativenavigation.views.ComponentViewCreator;
18
-import com.reactnativenavigation.views.titlebar.TitleBarReactViewCreator;
19 19
 import com.reactnativenavigation.views.titlebar.TitleBarButtonCreator;
20
-import com.reactnativenavigation.views.toptabs.TopTabsLayoutCreator;
20
+import com.reactnativenavigation.views.titlebar.TitleBarReactViewCreator;
21 21
 import com.reactnativenavigation.views.topbar.TopBarBackgroundViewCreator;
22
+import com.reactnativenavigation.views.toptabs.TopTabsLayoutCreator;
22 23
 
23 24
 import java.util.ArrayList;
24 25
 import java.util.List;
@@ -124,6 +125,7 @@ public class LayoutFactory {
124 125
                 new TitleBarButtonCreator(reactInstanceManager),
125 126
                 new TitleBarReactViewCreator(reactInstanceManager),
126 127
                 new TopBarBackgroundViewCreator(reactInstanceManager),
128
+                new TopBarController(),
127 129
                 node.id,
128 130
                 getOptions(node)
129 131
         );

+ 12
- 3
lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/StackController.java View File

@@ -10,6 +10,7 @@ import com.facebook.react.bridge.Promise;
10 10
 import com.reactnativenavigation.anim.NavigationAnimator;
11 11
 import com.reactnativenavigation.parse.Options;
12 12
 import com.reactnativenavigation.utils.NoOpPromise;
13
+import com.reactnativenavigation.viewcontrollers.topbar.TopBarController;
13 14
 import com.reactnativenavigation.views.Component;
14 15
 import com.reactnativenavigation.views.ReactComponent;
15 16
 import com.reactnativenavigation.views.StackLayout;
@@ -30,9 +31,11 @@ public class StackController extends ParentController<StackLayout> {
30 31
     private final ReactViewCreator topBarButtonCreator;
31 32
     private final TitleBarReactViewCreator titleBarReactViewCreator;
32 33
     private TopBarBackgroundViewCreator topBarBackgroundViewCreator;
34
+    private TopBarController topBarController;
33 35
 
34
-    public StackController(final Activity activity, ReactViewCreator topBarButtonCreator, TitleBarReactViewCreator titleBarReactViewCreator, TopBarBackgroundViewCreator topBarBackgroundViewCreator, String id, Options initialOptions) {
36
+    public StackController(final Activity activity, ReactViewCreator topBarButtonCreator, TitleBarReactViewCreator titleBarReactViewCreator, TopBarBackgroundViewCreator topBarBackgroundViewCreator, TopBarController topBarController, String id, Options initialOptions) {
35 37
         super(activity, id, initialOptions);
38
+        this.topBarController = topBarController;
36 39
         animator = createAnimator();
37 40
         this.topBarButtonCreator = topBarButtonCreator;
38 41
         this.titleBarReactViewCreator = titleBarReactViewCreator;
@@ -76,10 +79,16 @@ public class StackController extends ParentController<StackLayout> {
76 79
         );
77 80
     }
78 81
 
82
+    @Override
83
+    public void destroy() {
84
+        topBarController.clear();
85
+        super.destroy();
86
+    }
87
+
79 88
     @Override
80 89
     void clearOptions() {
81 90
         super.clearOptions();
82
-        getView().clearOptions();
91
+        topBarController.clear();
83 92
     }
84 93
 
85 94
     public void push(ViewController child, final Promise promise) {
@@ -229,7 +238,7 @@ public class StackController extends ParentController<StackLayout> {
229 238
     @NonNull
230 239
     @Override
231 240
     protected StackLayout createView() {
232
-        return new StackLayout(getActivity(), topBarButtonCreator, titleBarReactViewCreator, topBarBackgroundViewCreator, this::sendOnNavigationButtonPressed, getId());
241
+        return new StackLayout(getActivity(), topBarButtonCreator, titleBarReactViewCreator, topBarBackgroundViewCreator, topBarController, this::sendOnNavigationButtonPressed, getId());
233 242
     }
234 243
 
235 244
     @NonNull

+ 2
- 2
lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/ViewController.java View File

@@ -112,7 +112,7 @@ public abstract class ViewController<T extends ViewGroup> implements ViewTreeObs
112 112
                 throw new RuntimeException("Tried to create view after it has already been destroyed");
113 113
             }
114 114
             view = createView();
115
-            if (view.getId() < 0) {
115
+            if (view.getId() != 0) {
116 116
                 view.setId(CompatUtils.generateViewId());
117 117
             }
118 118
             view.getViewTreeObserver().addOnGlobalLayoutListener(this);
@@ -200,7 +200,7 @@ public abstract class ViewController<T extends ViewGroup> implements ViewTreeObs
200 200
         }
201 201
     }
202 202
 
203
-    public void runOnPreDraw(Task<T> task) {
203
+    void runOnPreDraw(Task<T> task) {
204 204
         UiUtils.runOnPreDrawOnce(getView(), () -> task.run(getView()));
205 205
     }
206 206
 

+ 42
- 0
lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/topbar/TopBarController.java View File

@@ -0,0 +1,42 @@
1
+package com.reactnativenavigation.viewcontrollers.topbar;
2
+
3
+import android.content.Context;
4
+import android.support.v4.view.ViewPager;
5
+import android.view.View;
6
+
7
+import com.reactnativenavigation.utils.CompatUtils;
8
+import com.reactnativenavigation.viewcontrollers.ReactViewCreator;
9
+import com.reactnativenavigation.viewcontrollers.TopBarButtonController;
10
+import com.reactnativenavigation.views.StackLayout;
11
+import com.reactnativenavigation.views.titlebar.TitleBarReactViewCreator;
12
+import com.reactnativenavigation.views.topbar.TopBar;
13
+import com.reactnativenavigation.views.topbar.TopBarBackgroundViewCreator;
14
+
15
+
16
+public class TopBarController {
17
+    private TopBar topBar;
18
+
19
+    public View createTopBar(Context context, ReactViewCreator buttonCreator, TitleBarReactViewCreator titleBarReactViewCreator, TopBarBackgroundViewCreator backgroundViewCreator, TopBarButtonController.OnClickListener topBarButtonClickListener, StackLayout stackLayout) {
20
+        if (topBar == null) {
21
+            topBar = new TopBar(context, buttonCreator, titleBarReactViewCreator, backgroundViewCreator, topBarButtonClickListener, stackLayout);
22
+            topBar.setId(CompatUtils.generateViewId());
23
+        }
24
+        return topBar;
25
+    }
26
+
27
+    public void clear() {
28
+        topBar.clear();
29
+    }
30
+
31
+    public TopBar getTopBar() {
32
+        return topBar;
33
+    }
34
+
35
+    public void initTopTabs(ViewPager viewPager) {
36
+        topBar.initTopTabs(viewPager);
37
+    }
38
+
39
+    public void clearTopTabs() {
40
+        topBar.clearTopTabs();
41
+    }
42
+}

+ 9
- 14
lib/android/app/src/main/java/com/reactnativenavigation/views/StackLayout.java View File

@@ -9,9 +9,9 @@ import android.widget.RelativeLayout;
9 9
 import com.reactnativenavigation.interfaces.ChildDisappearListener;
10 10
 import com.reactnativenavigation.parse.Options;
11 11
 import com.reactnativenavigation.presentation.OptionsPresenter;
12
-import com.reactnativenavigation.utils.CompatUtils;
13 12
 import com.reactnativenavigation.viewcontrollers.ReactViewCreator;
14 13
 import com.reactnativenavigation.viewcontrollers.TopBarButtonController;
14
+import com.reactnativenavigation.viewcontrollers.topbar.TopBarController;
15 15
 import com.reactnativenavigation.views.titlebar.TitleBarReactViewCreator;
16 16
 import com.reactnativenavigation.views.topbar.TopBar;
17 17
 import com.reactnativenavigation.views.topbar.TopBarBackgroundViewCreator;
@@ -21,22 +21,21 @@ import static android.view.ViewGroup.LayoutParams.WRAP_CONTENT;
21 21
 
22 22
 @SuppressLint("ViewConstructor")
23 23
 public class StackLayout extends RelativeLayout {
24
-    private TopBar topBar;
24
+    private TopBarController topBarController;
25 25
     private String stackId;
26 26
     private final OptionsPresenter optionsPresenter;
27 27
 
28
-    public StackLayout(Context context, ReactViewCreator topBarButtonCreator, TitleBarReactViewCreator titleBarReactViewCreator, TopBarBackgroundViewCreator topBarBackgroundViewCreator, TopBarButtonController.OnClickListener topBarButtonClickListener, String stackId) {
28
+    public StackLayout(Context context, ReactViewCreator topBarButtonCreator, TitleBarReactViewCreator titleBarReactViewCreator, TopBarBackgroundViewCreator topBarBackgroundViewCreator, TopBarController topBarController, TopBarButtonController.OnClickListener topBarButtonClickListener, String stackId) {
29 29
         super(context);
30
+        this.topBarController = topBarController;
30 31
         this.stackId = stackId;
31 32
         createLayout(topBarButtonCreator, titleBarReactViewCreator, topBarBackgroundViewCreator, topBarButtonClickListener);
32
-        optionsPresenter = new OptionsPresenter(topBar);
33
+        optionsPresenter = new OptionsPresenter(topBarController.getTopBar());
33 34
         setContentDescription("StackLayout");
34 35
     }
35 36
 
36 37
     private void createLayout(ReactViewCreator buttonCreator, TitleBarReactViewCreator titleBarReactViewCreator, TopBarBackgroundViewCreator BackgroundViewCreator, TopBarButtonController.OnClickListener topBarButtonClickListener) {
37
-        topBar = new TopBar(getContext(), buttonCreator, titleBarReactViewCreator, BackgroundViewCreator, topBarButtonClickListener, this);
38
-        topBar.setId(CompatUtils.generateViewId());
39
-        addView(topBar, MATCH_PARENT, WRAP_CONTENT);
38
+        addView(topBarController.createTopBar(getContext(), buttonCreator, titleBarReactViewCreator, BackgroundViewCreator, topBarButtonClickListener, this), MATCH_PARENT, WRAP_CONTENT);
40 39
     }
41 40
 
42 41
     public void applyChildOptions(Options options) {
@@ -51,21 +50,17 @@ public class StackLayout extends RelativeLayout {
51 50
         optionsPresenter.onChildWillDisappear(disappearing, appearing, childDisappearListener);
52 51
     }
53 52
 
54
-    public void clearOptions() {
55
-        topBar.clear();
56
-    }
57
-
58 53
     public void initTopTabs(ViewPager viewPager) {
59
-        topBar.initTopTabs(viewPager);
54
+        topBarController.initTopTabs(viewPager);
60 55
     }
61 56
 
62 57
     public void clearTopTabs() {
63
-        topBar.clearTopTabs();
58
+        topBarController.clearTopTabs();
64 59
     }
65 60
 
66 61
     @RestrictTo(RestrictTo.Scope.TESTS)
67 62
     public TopBar getTopBar() {
68
-        return topBar;
63
+        return topBarController.getTopBar();
69 64
     }
70 65
 
71 66
     public void mergeChildOptions(Options options, Component child) {

+ 12
- 11
lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/BottomTabsControllerTest.java View File

@@ -17,6 +17,7 @@ import com.reactnativenavigation.parse.params.Number;
17 17
 import com.reactnativenavigation.utils.ImageLoader;
18 18
 import com.reactnativenavigation.utils.OptionHelper;
19 19
 import com.reactnativenavigation.viewcontrollers.bottomtabs.BottomTabsController;
20
+import com.reactnativenavigation.viewcontrollers.topbar.TopBarController;
20 21
 import com.reactnativenavigation.views.BottomTabs;
21 22
 import com.reactnativenavigation.views.ReactComponent;
22 23
 
@@ -58,20 +59,20 @@ public class BottomTabsControllerTest extends BaseTest {
58 59
     }
59 60
 
60 61
     @Test
61
-    public void containsRelativeLayoutView() throws Exception {
62
+    public void containsRelativeLayoutView() {
62 63
         assertThat(uut.getView()).isInstanceOf(RelativeLayout.class);
63 64
         assertThat(uut.getView().getChildAt(0)).isInstanceOf(BottomTabs.class);
64 65
     }
65 66
 
66 67
     @Test(expected = RuntimeException.class)
67
-    public void setTabs_ThrowWhenMoreThan5() throws Exception {
68
+    public void setTabs_ThrowWhenMoreThan5() {
68 69
         List<ViewController> tabs = createTabs();
69 70
         tabs.add(new SimpleViewController(activity, "6", tabOptions));
70 71
         uut.setTabs(tabs);
71 72
     }
72 73
 
73 74
     @Test
74
-    public void setTab_controllerIsSetAsParent() throws Exception {
75
+    public void setTab_controllerIsSetAsParent() {
75 76
         List<ViewController> tabs = createTabs();
76 77
         uut.setTabs(tabs);
77 78
         for (ViewController tab : tabs) {
@@ -80,7 +81,7 @@ public class BottomTabsControllerTest extends BaseTest {
80 81
     }
81 82
 
82 83
     @Test
83
-    public void setTabs_AddAllViews() throws Exception {
84
+    public void setTabs_AddAllViews() {
84 85
         List<ViewController> tabs = createTabs();
85 86
         uut.setTabs(tabs);
86 87
         assertThat(uut.getView().getChildCount()).isEqualTo(2);
@@ -88,7 +89,7 @@ public class BottomTabsControllerTest extends BaseTest {
88 89
     }
89 90
 
90 91
     @Test
91
-    public void selectTabAtIndex() throws Exception {
92
+    public void selectTabAtIndex() {
92 93
         uut.setTabs(createTabs());
93 94
         assertThat(uut.getSelectedIndex()).isZero();
94 95
 
@@ -99,7 +100,7 @@ public class BottomTabsControllerTest extends BaseTest {
99 100
     }
100 101
 
101 102
     @Test
102
-    public void findControllerById_ReturnsSelfOrChildren() throws Exception {
103
+    public void findControllerById_ReturnsSelfOrChildren() {
103 104
         assertThat(uut.findControllerById("123")).isNull();
104 105
         assertThat(uut.findControllerById(uut.getId())).isEqualTo(uut);
105 106
         StackController inner = createStack("inner");
@@ -110,7 +111,7 @@ public class BottomTabsControllerTest extends BaseTest {
110 111
     }
111 112
 
112 113
     @Test
113
-    public void handleBack_DelegatesToSelectedChild() throws Exception {
114
+    public void handleBack_DelegatesToSelectedChild() {
114 115
         assertThat(uut.handleBack()).isFalse();
115 116
 
116 117
         List<ViewController> tabs = createTabs();
@@ -127,7 +128,7 @@ public class BottomTabsControllerTest extends BaseTest {
127 128
     }
128 129
 
129 130
     @Test
130
-    public void applyOptions_bottomTabsOptionsAreClearedAfterApply() throws Exception {
131
+    public void applyOptions_bottomTabsOptionsAreClearedAfterApply() {
131 132
         List<ViewController> tabs = createTabs();
132 133
         child1.options.bottomTabsOptions.tabColor = new Color(android.graphics.Color.RED);
133 134
         uut.setTabs(tabs);
@@ -146,7 +147,7 @@ public class BottomTabsControllerTest extends BaseTest {
146 147
     }
147 148
 
148 149
     @Test
149
-    public void mergeOptions_currentTabIndex() throws Exception {
150
+    public void mergeOptions_currentTabIndex() {
150 151
         List<ViewController> tabs = createTabs();
151 152
         uut.setTabs(tabs);
152 153
         uut.ensureViewIsCreated();
@@ -158,7 +159,7 @@ public class BottomTabsControllerTest extends BaseTest {
158 159
     }
159 160
 
160 161
     @Test
161
-    public void buttonPressInvokedOnCurrentTab() throws Exception {
162
+    public void buttonPressInvokedOnCurrentTab() {
162 163
         uut.setTabs(createTabs());
163 164
         uut.ensureViewIsCreated();
164 165
         uut.selectTabAtIndex(1);
@@ -173,6 +174,6 @@ public class BottomTabsControllerTest extends BaseTest {
173 174
     }
174 175
 
175 176
     private StackController createStack(String id) {
176
-        return new StackController(activity, new TopBarButtonCreatorMock(), new TitleBarReactViewCreatorMock(), new TopBarBackgroundViewCreatorMock(), id, tabOptions);
177
+        return new StackController(activity, new TopBarButtonCreatorMock(), new TitleBarReactViewCreatorMock(), new TopBarBackgroundViewCreatorMock(), new TopBarController(), id, tabOptions);
177 178
     }
178 179
 }

+ 7
- 6
lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/ComponentViewControllerTest.java View File

@@ -9,6 +9,7 @@ import com.reactnativenavigation.mocks.TitleBarReactViewCreatorMock;
9 9
 import com.reactnativenavigation.mocks.TopBarBackgroundViewCreatorMock;
10 10
 import com.reactnativenavigation.mocks.TopBarButtonCreatorMock;
11 11
 import com.reactnativenavigation.parse.Options;
12
+import com.reactnativenavigation.viewcontrollers.topbar.TopBarController;
12 13
 import com.reactnativenavigation.views.StackLayout;
13 14
 
14 15
 import org.junit.Test;
@@ -28,19 +29,19 @@ public class ComponentViewControllerTest extends BaseTest {
28 29
         super.beforeEach();
29 30
         Activity activity = newActivity();
30 31
         view = spy(new TestComponentLayout(activity, new TestReactView(activity)));
31
-        ParentController<StackLayout> parentController = new StackController(activity, new TopBarButtonCreatorMock(), new TitleBarReactViewCreatorMock(), new TopBarBackgroundViewCreatorMock(), "stack", new Options());
32
+        ParentController<StackLayout> parentController = new StackController(activity, new TopBarButtonCreatorMock(), new TitleBarReactViewCreatorMock(), new TopBarBackgroundViewCreatorMock(), new TopBarController(), "stack", new Options());
32 33
         uut = new ComponentViewController(activity, "componentId1", "componentName", (activity1, componentId, componentName) -> view, new Options());
33 34
         uut.setParentController(parentController);
34 35
         parentController.ensureViewIsCreated();
35 36
     }
36 37
 
37 38
     @Test
38
-    public void createsViewFromComponentViewCreator() throws Exception {
39
+    public void createsViewFromComponentViewCreator() {
39 40
         assertThat(uut.getView()).isSameAs(view);
40 41
     }
41 42
 
42 43
     @Test
43
-    public void componentViewDestroyedOnDestroy() throws Exception {
44
+    public void componentViewDestroyedOnDestroy() {
44 45
         uut.ensureViewIsCreated();
45 46
         verify(view, times(0)).destroy();
46 47
         uut.onViewAppeared();
@@ -49,7 +50,7 @@ public class ComponentViewControllerTest extends BaseTest {
49 50
     }
50 51
 
51 52
     @Test
52
-    public void lifecycleMethodsSentToComponentView() throws Exception {
53
+    public void lifecycleMethodsSentToComponentView() {
53 54
         uut.ensureViewIsCreated();
54 55
         verify(view, times(0)).sendComponentStart();
55 56
         verify(view, times(0)).sendComponentStop();
@@ -62,7 +63,7 @@ public class ComponentViewControllerTest extends BaseTest {
62 63
     }
63 64
 
64 65
     @Test
65
-    public void isViewShownOnlyIfComponentViewIsReady() throws Exception {
66
+    public void isViewShownOnlyIfComponentViewIsReady() {
66 67
         assertThat(uut.isViewShown()).isFalse();
67 68
         uut.ensureViewIsCreated();
68 69
         when(view.asView().isShown()).thenReturn(true);
@@ -72,7 +73,7 @@ public class ComponentViewControllerTest extends BaseTest {
72 73
     }
73 74
 
74 75
     @Test
75
-    public void onNavigationButtonPressInvokedOnReactComponent() throws Exception {
76
+    public void onNavigationButtonPressInvokedOnReactComponent() {
76 77
         uut.ensureViewIsCreated();
77 78
         uut.sendOnNavigationButtonPressed("btn1");
78 79
         verify(view, times(1)).sendOnNavigationButtonPressed("btn1");

+ 7
- 6
lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/FloatingActionButtonTest.java View File

@@ -14,6 +14,7 @@ import com.reactnativenavigation.mocks.TopBarButtonCreatorMock;
14 14
 import com.reactnativenavigation.parse.FabOptions;
15 15
 import com.reactnativenavigation.parse.Options;
16 16
 import com.reactnativenavigation.parse.params.Text;
17
+import com.reactnativenavigation.viewcontrollers.topbar.TopBarController;
17 18
 import com.reactnativenavigation.views.Fab;
18 19
 import com.reactnativenavigation.views.FabMenu;
19 20
 import com.reactnativenavigation.views.StackLayout;
@@ -35,7 +36,7 @@ public class FloatingActionButtonTest extends BaseTest {
35 36
     public void beforeEach() {
36 37
         super.beforeEach();
37 38
         activity = newActivity();
38
-        stackController = new StackController(activity, new TopBarButtonCreatorMock(), new TitleBarReactViewCreatorMock(), new TopBarBackgroundViewCreatorMock(),"stackController", new Options());
39
+        stackController = new StackController(activity, new TopBarButtonCreatorMock(), new TitleBarReactViewCreatorMock(), new TopBarBackgroundViewCreatorMock(), new TopBarController(), "stackController", new Options());
39 40
         Options options = getOptionsWithFab();
40 41
         childFab = new SimpleViewController(activity, "child1", options);
41 42
         childNoFab = new SimpleViewController(activity, "child2", new Options());
@@ -78,14 +79,14 @@ public class FloatingActionButtonTest extends BaseTest {
78 79
     }
79 80
 
80 81
     @Test
81
-    public void showOnPush() throws Exception {
82
+    public void showOnPush() {
82 83
         stackController.push(childFab, new MockPromise());
83 84
         childFab.onViewAppeared();
84 85
         assertThat(hasFab()).isTrue();
85 86
     }
86 87
 
87 88
     @Test
88
-    public void hideOnPush() throws Exception {
89
+    public void hideOnPush() {
89 90
         stackController.push(childFab, new MockPromise());
90 91
         childFab.onViewAppeared();
91 92
         assertThat(hasFab()).isTrue();
@@ -95,7 +96,7 @@ public class FloatingActionButtonTest extends BaseTest {
95 96
     }
96 97
 
97 98
     @Test
98
-    public void hideOnPop() throws Exception {
99
+    public void hideOnPop() {
99 100
         stackController.push(childNoFab, new MockPromise());
100 101
         stackController.push(childFab, new MockPromise());
101 102
         childFab.onViewAppeared();
@@ -106,7 +107,7 @@ public class FloatingActionButtonTest extends BaseTest {
106 107
     }
107 108
 
108 109
     @Test
109
-    public void showOnPop() throws Exception {
110
+    public void showOnPop() {
110 111
         stackController.push(childFab, new MockPromise());
111 112
         stackController.push(childNoFab, new MockPromise());
112 113
         childNoFab.onViewAppeared();
@@ -117,7 +118,7 @@ public class FloatingActionButtonTest extends BaseTest {
117 118
     }
118 119
 
119 120
     @Test
120
-    public void hasChildren() throws Exception {
121
+    public void hasChildren() {
121 122
         childFab = new SimpleViewController(activity, "child1", getOptionsWithFabActions());
122 123
         stackController.push(childFab, new MockPromise());
123 124
         childFab.onViewAppeared();

+ 24
- 22
lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/NavigatorTest.java View File

@@ -17,6 +17,7 @@ import com.reactnativenavigation.utils.CompatUtils;
17 17
 import com.reactnativenavigation.utils.ImageLoader;
18 18
 import com.reactnativenavigation.utils.OptionHelper;
19 19
 import com.reactnativenavigation.viewcontrollers.bottomtabs.BottomTabsController;
20
+import com.reactnativenavigation.viewcontrollers.topbar.TopBarController;
20 21
 
21 22
 import org.junit.Test;
22 23
 
@@ -58,27 +59,27 @@ public class NavigatorTest extends BaseTest {
58 59
     }
59 60
 
60 61
     @Test
61
-    public void setRoot_AddsChildControllerView() throws Exception {
62
+    public void setRoot_AddsChildControllerView() {
62 63
         assertThat(uut.getView().getChildCount()).isZero();
63 64
         uut.setRoot(child1, new MockPromise());
64 65
         assertIsChildById(uut.getView(), child1.getView());
65 66
     }
66 67
 
67 68
     @Test
68
-    public void setRoot_ReplacesExistingChildControllerViews() throws Exception {
69
+    public void setRoot_ReplacesExistingChildControllerViews() {
69 70
         uut.setRoot(child1, new MockPromise());
70 71
         uut.setRoot(child2, new MockPromise());
71 72
         assertIsChildById(uut.getView(), child2.getView());
72 73
     }
73 74
 
74 75
     @Test
75
-    public void hasUniqueId() throws Exception {
76
+    public void hasUniqueId() {
76 77
         assertThat(uut.getId()).startsWith("navigator");
77 78
         assertThat(new Navigator(activity).getId()).isNotEqualTo(uut.getId());
78 79
     }
79 80
 
80 81
     @Test
81
-    public void push() throws Exception {
82
+    public void push() {
82 83
         StackController stackController = newStack();
83 84
         stackController.animatePush(child1, new MockPromise());
84 85
         uut.setRoot(stackController, new MockPromise());
@@ -93,14 +94,14 @@ public class NavigatorTest extends BaseTest {
93 94
     }
94 95
 
95 96
     @Test
96
-    public void push_InvalidPushWithoutAStack_DoesNothing() throws Exception {
97
+    public void push_InvalidPushWithoutAStack_DoesNothing() {
97 98
         uut.setRoot(child1, new MockPromise());
98 99
         uut.push(child1.getId(), child2, new MockPromise());
99 100
         assertIsChildById(uut.getView(), child1.getView());
100 101
     }
101 102
 
102 103
     @Test
103
-    public void push_OnCorrectStackByFindingChildId() throws Exception {
104
+    public void push_OnCorrectStackByFindingChildId() {
104 105
         BottomTabsController bottomTabsController = newTabs();
105 106
         StackController stack1 = newStack();
106 107
         StackController stack2 = newStack();
@@ -117,7 +118,7 @@ public class NavigatorTest extends BaseTest {
117 118
     }
118 119
 
119 120
     @Test
120
-    public void pop_InvalidDoesNothing() throws Exception {
121
+    public void pop_InvalidDoesNothing() {
121 122
         uut.pop("123", new MockPromise());
122 123
         uut.setRoot(child1, new MockPromise());
123 124
         uut.pop(child1.getId(), new MockPromise());
@@ -125,7 +126,7 @@ public class NavigatorTest extends BaseTest {
125 126
     }
126 127
 
127 128
     @Test
128
-    public void pop_FromCorrectStackByFindingChildId() throws Exception {
129
+    public void pop_FromCorrectStackByFindingChildId() {
129 130
         BottomTabsController bottomTabsController = newTabs();
130 131
         StackController stack1 = newStack();
131 132
         StackController stack2 = newStack();
@@ -148,7 +149,7 @@ public class NavigatorTest extends BaseTest {
148 149
     }
149 150
 
150 151
     @Test
151
-    public void popSpecific() throws Exception {
152
+    public void popSpecific() {
152 153
         BottomTabsController bottomTabsController = newTabs();
153 154
         StackController stack1 = newStack();
154 155
         StackController stack2 = newStack();
@@ -165,7 +166,7 @@ public class NavigatorTest extends BaseTest {
165 166
     }
166 167
 
167 168
     @Test
168
-    public void popTo_FromCorrectStackUpToChild() throws Exception {
169
+    public void popTo_FromCorrectStackUpToChild() {
169 170
         BottomTabsController bottomTabsController = newTabs();
170 171
         StackController stack1 = newStack();
171 172
         StackController stack2 = newStack();
@@ -186,7 +187,7 @@ public class NavigatorTest extends BaseTest {
186 187
     }
187 188
 
188 189
     @Test
189
-    public void popToRoot() throws Exception {
190
+    public void popToRoot() {
190 191
         BottomTabsController bottomTabsController = newTabs();
191 192
         StackController stack1 = newStack();
192 193
         StackController stack2 = newStack();
@@ -208,7 +209,7 @@ public class NavigatorTest extends BaseTest {
208 209
     }
209 210
 
210 211
     @Test
211
-    public void handleBack_DelegatesToRoot() throws Exception {
212
+    public void handleBack_DelegatesToRoot() {
212 213
         ViewController root = spy(child1);
213 214
         uut.setRoot(root, new MockPromise());
214 215
         when(root.handleBack()).thenReturn(true);
@@ -217,7 +218,7 @@ public class NavigatorTest extends BaseTest {
217 218
     }
218 219
 
219 220
     @Test
220
-    public void handleBack_modalTakePrecedenceOverRoot() throws Exception {
221
+    public void handleBack_modalTakePrecedenceOverRoot() {
221 222
         ViewController root = spy(child1);
222 223
         uut.setRoot(root, new MockPromise());
223 224
         uut.showModal(child2, new MockPromise());
@@ -250,11 +251,12 @@ public class NavigatorTest extends BaseTest {
250 251
 
251 252
     @NonNull
252 253
     private StackController newStack() {
253
-        return new StackController(activity, new TopBarButtonCreatorMock(), new TitleBarReactViewCreatorMock(), new TopBarBackgroundViewCreatorMock(), "stack" + CompatUtils.generateViewId(), tabOptions);
254
+        return new StackController(activity, new TopBarButtonCreatorMock(), new TitleBarReactViewCreatorMock(), new TopBarBackgroundViewCreatorMock(), new TopBarController(),
255
+                "stack" + CompatUtils.generateViewId(), tabOptions);
254 256
     }
255 257
 
256 258
     @Test
257
-    public void push_Promise() throws Exception {
259
+    public void push_Promise() {
258 260
         final StackController stackController = newStack();
259 261
         stackController.animatePush(child1, new MockPromise());
260 262
         uut.setRoot(stackController, new MockPromise());
@@ -272,7 +274,7 @@ public class NavigatorTest extends BaseTest {
272 274
     }
273 275
 
274 276
     @Test
275
-    public void push_InvalidPushWithoutAStack_DoesNothing_Promise() throws Exception {
277
+    public void push_InvalidPushWithoutAStack_DoesNothing_Promise() {
276 278
         uut.setRoot(child1, new MockPromise());
277 279
         uut.push(child1.getId(), child2, new MockPromise() {
278 280
             @Override
@@ -284,7 +286,7 @@ public class NavigatorTest extends BaseTest {
284 286
     }
285 287
 
286 288
     @Test
287
-    public void pop_InvalidDoesNothing_Promise() throws Exception {
289
+    public void pop_InvalidDoesNothing_Promise() {
288 290
         uut.pop("123", new MockPromise());
289 291
         uut.setRoot(child1, new MockPromise());
290 292
         uut.pop(child1.getId(), new MockPromise() {
@@ -296,7 +298,7 @@ public class NavigatorTest extends BaseTest {
296 298
     }
297 299
 
298 300
     @Test
299
-    public void pop_FromCorrectStackByFindingChildId_Promise() throws Exception {
301
+    public void pop_FromCorrectStackByFindingChildId_Promise() {
300 302
         BottomTabsController bottomTabsController = newTabs();
301 303
         StackController stack1 = newStack();
302 304
         final StackController stack2 = newStack();
@@ -316,7 +318,7 @@ public class NavigatorTest extends BaseTest {
316 318
     }
317 319
 
318 320
     @Test
319
-    public void pushIntoModal() throws Exception {
321
+    public void pushIntoModal() {
320 322
         uut.setRoot(parentController, new MockPromise());
321 323
         StackController stackController = newStack();
322 324
         stackController.push(child1, new MockPromise());
@@ -326,7 +328,7 @@ public class NavigatorTest extends BaseTest {
326 328
     }
327 329
 
328 330
     @Test
329
-    public void pushedStackCanBePopped() throws Exception {
331
+    public void pushedStackCanBePopped() {
330 332
         StackController parent = newStack();
331 333
         parent.ensureViewIsCreated();
332 334
         uut.setRoot(parent, new MockPromise());
@@ -349,7 +351,7 @@ public class NavigatorTest extends BaseTest {
349 351
     }
350 352
 
351 353
     @Test
352
-    public void showModal_onViewDisappearIsInvokedOnRoot() throws Exception {
354
+    public void showModal_onViewDisappearIsInvokedOnRoot() {
353 355
         uut.setRoot(parentController, new MockPromise());
354 356
         uut.showModal(child1, new MockPromise() {
355 357
             @Override
@@ -360,7 +362,7 @@ public class NavigatorTest extends BaseTest {
360 362
     }
361 363
 
362 364
     @Test
363
-    public void dismissModal_onViewAppearedInvokedOnRoot() throws Exception {
365
+    public void dismissModal_onViewAppearedInvokedOnRoot() {
364 366
         uut.setRoot(parentController, new MockPromise());
365 367
         uut.showModal(child1, new MockPromise() {
366 368
             @Override

+ 12
- 11
lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/OptionsApplyingTest.java View File

@@ -19,6 +19,7 @@ import com.reactnativenavigation.parse.params.Bool;
19 19
 import com.reactnativenavigation.parse.params.Fraction;
20 20
 import com.reactnativenavigation.parse.params.Text;
21 21
 import com.reactnativenavigation.utils.ViewUtils;
22
+import com.reactnativenavigation.viewcontrollers.topbar.TopBarController;
22 23
 import com.reactnativenavigation.views.topbar.TopBarBackgroundView;
23 24
 
24 25
 import org.json.JSONObject;
@@ -51,13 +52,13 @@ public class OptionsApplyingTest extends BaseTest {
51 52
                 (activity1, componentId, componentName) -> view,
52 53
                 initialNavigationOptions
53 54
         );
54
-        stackController = new StackController(activity, new TopBarButtonCreatorMock(), new TitleBarReactViewCreatorMock(), new TopBarBackgroundViewCreatorMock(), "stack", new Options());
55
+        stackController = new StackController(activity, new TopBarButtonCreatorMock(), new TitleBarReactViewCreatorMock(), new TopBarBackgroundViewCreatorMock(), new TopBarController(), "stack", new Options());
55 56
         stackController.ensureViewIsCreated();
56 57
         uut.setParentController(stackController);
57 58
     }
58 59
 
59 60
     @Test
60
-    public void applyNavigationOptionsHandlesNoParentStack() throws Exception {
61
+    public void applyNavigationOptionsHandlesNoParentStack() {
61 62
         uut.setParentController(null);
62 63
         assertThat(uut.getParentController()).isNull();
63 64
         uut.ensureViewIsCreated();
@@ -66,9 +67,9 @@ public class OptionsApplyingTest extends BaseTest {
66 67
     }
67 68
 
68 69
     @Test
69
-    public void initialOptionsAppliedOnAppear() throws Exception {
70
+    public void initialOptionsAppliedOnAppear() {
70 71
         uut.options.topBarOptions.title.text = new Text("the title");
71
-        StackController stackController = new StackController(activity, new TopBarButtonCreatorMock(), new TitleBarReactViewCreatorMock(), new TopBarBackgroundViewCreatorMock(), "stackId", new Options());
72
+        StackController stackController = new StackController(activity, new TopBarButtonCreatorMock(), new TitleBarReactViewCreatorMock(), new TopBarBackgroundViewCreatorMock(), new TopBarController(), "stackId", new Options());
72 73
         stackController.animatePush(uut, new MockPromise() {});
73 74
         assertThat(stackController.getTopBar().getTitle()).isEmpty();
74 75
 
@@ -77,7 +78,7 @@ public class OptionsApplyingTest extends BaseTest {
77 78
     }
78 79
 
79 80
     @Test
80
-    public void mergeNavigationOptionsUpdatesCurrentOptions() throws Exception {
81
+    public void mergeNavigationOptionsUpdatesCurrentOptions() {
81 82
         uut.ensureViewIsCreated();
82 83
         assertThat(uut.options.topBarOptions.title.text.get("")).isEmpty();
83 84
         Options options = new Options();
@@ -87,7 +88,7 @@ public class OptionsApplyingTest extends BaseTest {
87 88
     }
88 89
 
89 90
     @Test
90
-    public void reappliesOptionsOnMerge() throws Exception {
91
+    public void reappliesOptionsOnMerge() {
91 92
         uut.ensureViewIsCreated();
92 93
         uut.onViewAppeared();
93 94
         assertThat(stackController.getTopBar().getTitle()).isEmpty();
@@ -100,7 +101,7 @@ public class OptionsApplyingTest extends BaseTest {
100 101
     }
101 102
 
102 103
     @Test
103
-    public void appliesTopBackBackgroundColor() throws Exception {
104
+    public void appliesTopBackBackgroundColor() {
104 105
         uut.ensureViewIsCreated();
105 106
         uut.onViewAppeared();
106 107
 
@@ -112,7 +113,7 @@ public class OptionsApplyingTest extends BaseTest {
112 113
     }
113 114
 
114 115
     @Test
115
-    public void appliesTopBarTextColor() throws Exception {
116
+    public void appliesTopBarTextColor() {
116 117
         assertThat(uut.initialOptions).isSameAs(initialNavigationOptions);
117 118
         stackController.animatePush(uut, new MockPromise() {
118 119
             @Override
@@ -129,7 +130,7 @@ public class OptionsApplyingTest extends BaseTest {
129 130
     }
130 131
 
131 132
     @Test
132
-    public void appliesTopBarTextSize() throws Exception {
133
+    public void appliesTopBarTextSize() {
133 134
         assertThat(uut.initialOptions).isSameAs(initialNavigationOptions);
134 135
         initialNavigationOptions.topBarOptions.title.text = new Text("the title");
135 136
         uut.ensureViewIsCreated();
@@ -145,7 +146,7 @@ public class OptionsApplyingTest extends BaseTest {
145 146
     }
146 147
 
147 148
     @Test
148
-    public void appliesTopBarVisible() throws Exception {
149
+    public void appliesTopBarVisible() {
149 150
         assertThat(uut.initialOptions).isSameAs(initialNavigationOptions);
150 151
         initialNavigationOptions.topBarOptions.title.text = new Text("the title");
151 152
         uut.ensureViewIsCreated();
@@ -161,7 +162,7 @@ public class OptionsApplyingTest extends BaseTest {
161 162
     }
162 163
 
163 164
     @Test
164
-    public void appliesDrawUnder() throws Exception {
165
+    public void appliesDrawUnder() {
165 166
         uut.options.topBarOptions.title.text = new Text("the title");
166 167
         uut.options.topBarOptions.drawBehind = new Bool(false);
167 168
         uut.ensureViewIsCreated();

+ 11
- 10
lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/ParentControllerTest.java View File

@@ -13,6 +13,7 @@ import com.reactnativenavigation.mocks.TopBarBackgroundViewCreatorMock;
13 13
 import com.reactnativenavigation.mocks.TopBarButtonCreatorMock;
14 14
 import com.reactnativenavigation.parse.Options;
15 15
 import com.reactnativenavigation.parse.params.Text;
16
+import com.reactnativenavigation.viewcontrollers.topbar.TopBarController;
16 17
 import com.reactnativenavigation.views.ReactComponent;
17 18
 
18 19
 import org.junit.Test;
@@ -29,7 +30,7 @@ import static org.mockito.Mockito.verify;
29 30
 
30 31
 public class ParentControllerTest extends BaseTest {
31 32
 
32
-    public static final String INITIAL_TITLE = "initial title";
33
+    private static final String INITIAL_TITLE = "initial title";
33 34
     private Activity activity;
34 35
     private List<ViewController> children;
35 36
     private ParentController uut;
@@ -68,17 +69,17 @@ public class ParentControllerTest extends BaseTest {
68 69
     }
69 70
 
70 71
     @Test
71
-    public void holdsViewGroup() throws Exception {
72
+    public void holdsViewGroup() {
72 73
         assertThat(uut.getView()).isInstanceOf(ViewGroup.class);
73 74
     }
74 75
 
75 76
     @Test
76
-    public void mustHaveChildControllers() throws Exception {
77
+    public void mustHaveChildControllers() {
77 78
         assertThat(uut.getChildControllers()).isNotNull();
78 79
     }
79 80
 
80 81
     @Test
81
-    public void findControllerById_ChildById() throws Exception {
82
+    public void findControllerById_ChildById() {
82 83
         SimpleViewController child1 = new SimpleViewController(activity, "child1", new Options());
83 84
         SimpleViewController child2 = new SimpleViewController(activity, "child2", new Options());
84 85
         children.add(child1);
@@ -89,7 +90,7 @@ public class ParentControllerTest extends BaseTest {
89 90
     }
90 91
 
91 92
     @Test
92
-    public void findControllerById_Recursive() throws Exception {
93
+    public void findControllerById_Recursive() {
93 94
         StackController stackController = createStack();
94 95
         SimpleViewController child1 = new SimpleViewController(activity, "child1", new Options());
95 96
         SimpleViewController child2 = new SimpleViewController(activity, "child2", new Options());
@@ -101,7 +102,7 @@ public class ParentControllerTest extends BaseTest {
101 102
     }
102 103
 
103 104
     @Test
104
-    public void destroy_DestroysChildren() throws Exception {
105
+    public void destroy_DestroysChildren() {
105 106
         ViewController child1 = spy(new SimpleViewController(activity, "child1", new Options()));
106 107
         children.add(child1);
107 108
 
@@ -111,7 +112,7 @@ public class ParentControllerTest extends BaseTest {
111 112
     }
112 113
 
113 114
     @Test
114
-    public void optionsAreClearedWhenChildIsAppeared() throws Exception {
115
+    public void optionsAreClearedWhenChildIsAppeared() {
115 116
         StackController stackController = spy(createStack());
116 117
         SimpleViewController child1 = new SimpleViewController(activity, "child1", new Options());
117 118
         stackController.animatePush(child1, new MockPromise());
@@ -121,7 +122,7 @@ public class ParentControllerTest extends BaseTest {
121 122
     }
122 123
 
123 124
     @Test
124
-    public void mergeOptions_optionsAreMergedWhenChildAppears() throws Exception {
125
+    public void mergeOptions_optionsAreMergedWhenChildAppears() {
125 126
         Options options = new Options();
126 127
         options.topBarOptions.title.text = new Text("new title");
127 128
         ViewController child1 = spy(new SimpleViewController(activity, "child1", options));
@@ -139,7 +140,7 @@ public class ParentControllerTest extends BaseTest {
139 140
     }
140 141
 
141 142
     @Test
142
-    public void mergeOptions_initialParentOptionsAreNotMutatedWhenChildAppears() throws Exception {
143
+    public void mergeOptions_initialParentOptionsAreNotMutatedWhenChildAppears() {
143 144
         Options options = new Options();
144 145
         options.topBarOptions.title.text = new Text("new title");
145 146
         ViewController child1 = spy(new SimpleViewController(activity, "child1", options));
@@ -153,6 +154,6 @@ public class ParentControllerTest extends BaseTest {
153 154
     }
154 155
 
155 156
     private StackController createStack() {
156
-        return new StackController(activity, new TopBarButtonCreatorMock(), new TitleBarReactViewCreatorMock(), new TopBarBackgroundViewCreatorMock(),"stack", new Options());
157
+        return new StackController(activity, new TopBarButtonCreatorMock(), new TitleBarReactViewCreatorMock(), new TopBarBackgroundViewCreatorMock(), new TopBarController(), "stack", new Options());
157 158
     }
158 159
 }

+ 16
- 5
lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/StackControllerTest.java View File

@@ -16,13 +16,13 @@ import com.reactnativenavigation.parse.Options;
16 16
 import com.reactnativenavigation.parse.params.Bool;
17 17
 import com.reactnativenavigation.parse.params.Text;
18 18
 import com.reactnativenavigation.utils.ViewHelper;
19
+import com.reactnativenavigation.viewcontrollers.topbar.TopBarController;
19 20
 import com.reactnativenavigation.views.Component;
20 21
 import com.reactnativenavigation.views.ReactComponent;
21 22
 import com.reactnativenavigation.views.StackLayout;
22 23
 
23 24
 import org.assertj.core.api.iterable.Extractor;
24 25
 import org.json.JSONObject;
25
-import org.junit.Ignore;
26 26
 import org.junit.Test;
27 27
 import org.mockito.ArgumentCaptor;
28 28
 import org.mockito.Mockito;
@@ -44,6 +44,7 @@ public class StackControllerTest extends BaseTest {
44 44
     private ViewController child2;
45 45
     private ViewController child3;
46 46
     private NavigationAnimator animator;
47
+    private TopBarController topBarController;
47 48
 
48 49
     @Override
49 50
     public void beforeEach() {
@@ -105,7 +106,7 @@ public class StackControllerTest extends BaseTest {
105 106
     @Test
106 107
     public void pop_layoutHandlesChildWillDisappear() {
107 108
         final StackLayout[] stackLayout = new StackLayout[1];
108
-        uut = new StackController(activity, new TopBarButtonCreatorMock(), new TitleBarReactViewCreatorMock(), new TopBarBackgroundViewCreatorMock(), "uut", new Options()) {
109
+        uut = new StackController(activity, new TopBarButtonCreatorMock(), new TitleBarReactViewCreatorMock(), new TopBarBackgroundViewCreatorMock(), new TopBarController(), "uut", new Options()) {
109 110
             @NonNull
110 111
             @Override
111 112
             protected StackLayout createView() {
@@ -465,7 +466,7 @@ public class StackControllerTest extends BaseTest {
465 466
     @Test
466 467
     public void mergeChildOptions_updatesViewWithNewOptions() {
467 468
         final StackLayout[] stackLayout = new StackLayout[1];
468
-        StackController uut = new StackController(activity, new TopBarButtonCreatorMock(), new TitleBarReactViewCreatorMock(), new TopBarBackgroundViewCreatorMock(), "stack", new Options()) {
469
+        StackController uut = new StackController(activity, new TopBarButtonCreatorMock(), new TitleBarReactViewCreatorMock(), new TopBarBackgroundViewCreatorMock(), new TopBarController(), "stack", new Options()) {
469 470
             @NonNull
470 471
             @Override
471 472
             protected StackLayout createView() {
@@ -482,7 +483,7 @@ public class StackControllerTest extends BaseTest {
482 483
     @Test
483 484
     public void mergeChildOptions_updatesParentControllerWithNewOptions() {
484 485
         final StackLayout[] stackLayout = new StackLayout[1];
485
-        StackController uut = new StackController(activity, new TopBarButtonCreatorMock(), new TitleBarReactViewCreatorMock(), new TopBarBackgroundViewCreatorMock(), "stack", new Options()) {
486
+        StackController uut = new StackController(activity, new TopBarButtonCreatorMock(), new TitleBarReactViewCreatorMock(), new TopBarBackgroundViewCreatorMock(), new TopBarController(), "stack", new Options()) {
486 487
             @NonNull
487 488
             @Override
488 489
             protected StackLayout createView() {
@@ -533,6 +534,13 @@ public class StackControllerTest extends BaseTest {
533 534
         assertThat(captor.getValue().fabOptions.hasValue()).isFalse();
534 535
     }
535 536
 
537
+    @Test
538
+    public void destroy() {
539
+        uut.ensureViewIsCreated();
540
+        uut.destroy();
541
+        verify(topBarController, times(1)).clear();
542
+    }
543
+
536 544
     private void assertContainsOnlyId(String... ids) {
537 545
         assertThat(uut.size()).isEqualTo(ids.length);
538 546
         assertThat(uut.getChildControllers()).extracting((Extractor<ViewController, String>) ViewController::getId).containsOnly(ids);
@@ -543,7 +551,10 @@ public class StackControllerTest extends BaseTest {
543 551
     }
544 552
 
545 553
     private StackController createStackController(String id) {
546
-        return new StackController(activity, new TopBarButtonCreatorMock(), new TitleBarReactViewCreatorMock(), new TopBarBackgroundViewCreatorMock(), id, new Options()) {
554
+        topBarController = spy(new TopBarController());
555
+        return new StackController(activity,
556
+                new TopBarButtonCreatorMock(), new TitleBarReactViewCreatorMock(), new TopBarBackgroundViewCreatorMock(),
557
+                topBarController, id, new Options()) {
547 558
             @Override
548 559
             NavigationAnimator createAnimator() {
549 560
                 animator = Mockito.mock(NavigationAnimator.class);

+ 4
- 3
lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/TopBarButtonControllerTest.java View File

@@ -10,6 +10,7 @@ import com.reactnativenavigation.mocks.TopBarButtonCreatorMock;
10 10
 import com.reactnativenavigation.parse.Options;
11 11
 import com.reactnativenavigation.parse.params.Button;
12 12
 import com.reactnativenavigation.parse.params.Text;
13
+import com.reactnativenavigation.viewcontrollers.topbar.TopBarController;
13 14
 
14 15
 import org.junit.Ignore;
15 16
 import org.junit.Test;
@@ -30,19 +31,19 @@ public class TopBarButtonControllerTest extends BaseTest {
30 31
 
31 32
         TopBarButtonCreatorMock buttonCreatorMock = new TopBarButtonCreatorMock();
32 33
         uut = spy(new TopBarButtonController(activity, button, buttonCreatorMock, (buttonId) -> {}));
33
-        stackController = spy(new StackController(activity, buttonCreatorMock, new TitleBarReactViewCreatorMock(), new TopBarBackgroundViewCreatorMock(), "stack", new Options()));
34
+        stackController = spy(new StackController(activity, buttonCreatorMock, new TitleBarReactViewCreatorMock(), new TopBarBackgroundViewCreatorMock(), new TopBarController(), "stack", new Options()));
34 35
 
35 36
     }
36 37
 
37 38
     @Test
38
-    public void buttonDoesNotClearStackOptionsOnAppear() throws Exception {
39
+    public void buttonDoesNotClearStackOptionsOnAppear() {
39 40
         uut.ensureViewIsCreated();
40 41
         uut.onViewAppeared();
41 42
         verify(stackController, times(0)).clearOptions();
42 43
     }
43 44
 
44 45
     @Test @Ignore
45
-    public void destroy_buttonIsDestroyedWhenStackIsDestroyed() throws Exception {
46
+    public void destroy_buttonIsDestroyedWhenStackIsDestroyed() {
46 47
         uut.ensureViewIsCreated();
47 48
         uut.onViewAppeared();
48 49
         stackController.destroy();

+ 12
- 11
lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/TopTabsViewControllerTest.java View File

@@ -14,6 +14,7 @@ import com.reactnativenavigation.mocks.TopBarButtonCreatorMock;
14 14
 import com.reactnativenavigation.parse.Options;
15 15
 import com.reactnativenavigation.parse.params.Text;
16 16
 import com.reactnativenavigation.utils.ViewHelper;
17
+import com.reactnativenavigation.viewcontrollers.topbar.TopBarController;
17 18
 import com.reactnativenavigation.viewcontrollers.toptabs.TopTabsAdapter;
18 19
 import com.reactnativenavigation.viewcontrollers.toptabs.TopTabsController;
19 20
 import com.reactnativenavigation.views.ReactComponent;
@@ -69,7 +70,7 @@ public class TopTabsViewControllerTest extends BaseTest {
69 70
 
70 71
     @NonNull
71 72
     private StackController createStackController(String id) {
72
-        return new StackController(activity, new TopBarButtonCreatorMock(), new TitleBarReactViewCreatorMock(), new TopBarBackgroundViewCreatorMock(), id, new Options());
73
+        return new StackController(activity, new TopBarButtonCreatorMock(), new TitleBarReactViewCreatorMock(), new TopBarBackgroundViewCreatorMock(), new TopBarController(), id, new Options());
73 74
     }
74 75
 
75 76
     @NonNull
@@ -104,7 +105,7 @@ public class TopTabsViewControllerTest extends BaseTest {
104 105
     }
105 106
 
106 107
     @Test
107
-    public void createsViewFromComponentViewCreator() throws Exception {
108
+    public void createsViewFromComponentViewCreator() {
108 109
         uut.ensureViewIsCreated();
109 110
         for (int i = 0; i < SIZE; i++) {
110 111
             verify(tabControllers.get(i), times(1)).createView();
@@ -112,7 +113,7 @@ public class TopTabsViewControllerTest extends BaseTest {
112 113
     }
113 114
 
114 115
     @Test
115
-    public void componentViewDestroyedOnDestroy() throws Exception {
116
+    public void componentViewDestroyedOnDestroy() {
116 117
         uut.ensureViewIsCreated();
117 118
         TopTabsViewPager topTabs = uut.getView();
118 119
         for (int i = 0; i < SIZE; i++) {
@@ -125,7 +126,7 @@ public class TopTabsViewControllerTest extends BaseTest {
125 126
     }
126 127
 
127 128
     @Test
128
-    public void lifecycleMethodsSentWhenSelectedTabChanges() throws Exception {
129
+    public void lifecycleMethodsSentWhenSelectedTabChanges() {
129 130
         parentController.ensureViewIsCreated();
130 131
         uut.ensureViewIsCreated();
131 132
         tabControllers.get(0).ensureViewIsCreated();
@@ -145,7 +146,7 @@ public class TopTabsViewControllerTest extends BaseTest {
145 146
     }
146 147
 
147 148
     @Test
148
-    public void lifecycleMethodsSentWhenSelectedPreviouslySelectedTab() throws Exception {
149
+    public void lifecycleMethodsSentWhenSelectedPreviouslySelectedTab() {
149 150
         parentController.ensureViewIsCreated();
150 151
         uut.ensureViewIsCreated();
151 152
         uut.onViewAppeared();
@@ -159,7 +160,7 @@ public class TopTabsViewControllerTest extends BaseTest {
159 160
     }
160 161
 
161 162
     @Test
162
-    public void setOptionsOfInitialTab() throws Exception {
163
+    public void setOptionsOfInitialTab() {
163 164
         parentController.ensureViewIsCreated();
164 165
         uut.ensureViewIsCreated();
165 166
         uut.onViewAppeared();
@@ -171,7 +172,7 @@ public class TopTabsViewControllerTest extends BaseTest {
171 172
     }
172 173
 
173 174
     @Test
174
-    public void setOptionsWhenTabChanges() throws Exception {
175
+    public void setOptionsWhenTabChanges() {
175 176
         parentController.ensureViewIsCreated();
176 177
         uut.ensureViewIsCreated();
177 178
         tabControllers.get(0).ensureViewIsCreated();
@@ -198,7 +199,7 @@ public class TopTabsViewControllerTest extends BaseTest {
198 199
     }
199 200
 
200 201
     @Test
201
-    public void appliesOptionsOnLayoutWhenVisible() throws Exception {
202
+    public void appliesOptionsOnLayoutWhenVisible() {
202 203
         tabControllers.get(0).ensureViewIsCreated();
203 204
         parentController.ensureViewIsCreated();
204 205
         uut.ensureViewIsCreated();
@@ -209,7 +210,7 @@ public class TopTabsViewControllerTest extends BaseTest {
209 210
     }
210 211
 
211 212
     @Test
212
-    public void applyOptions_applyOnlyOnFirstTopTabs() throws Exception {
213
+    public void applyOptions_applyOnlyOnFirstTopTabs() {
213 214
         tabOptions.get(0).topTabOptions.title = new Text("tab title");
214 215
         tabControllers.get(0).onViewAppeared();
215 216
         ArgumentCaptor<Options> optionsCaptor = ArgumentCaptor.forClass(Options.class);
@@ -219,7 +220,7 @@ public class TopTabsViewControllerTest extends BaseTest {
219 220
     }
220 221
 
221 222
     @Test
222
-    public void applyOptions_tabsAreRemovedAfterViewDisappears() throws Exception {
223
+    public void applyOptions_tabsAreRemovedAfterViewDisappears() {
223 224
         parentController.getView().removeAllViews();
224 225
 
225 226
         StackController stackController = spy(createStackController("stack"));
@@ -247,7 +248,7 @@ public class TopTabsViewControllerTest extends BaseTest {
247 248
     }
248 249
 
249 250
     @Test
250
-    public void onNavigationButtonPressInvokedOnCurrentTab() throws Exception {
251
+    public void onNavigationButtonPressInvokedOnCurrentTab() {
251 252
         uut.ensureViewIsCreated();
252 253
         uut.switchToTab(1);
253 254
         uut.sendOnNavigationButtonPressed("btn1");

+ 18
- 17
lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/ViewControllerTest.java View File

@@ -13,6 +13,7 @@ import com.reactnativenavigation.mocks.TitleBarReactViewCreatorMock;
13 13
 import com.reactnativenavigation.mocks.TopBarBackgroundViewCreatorMock;
14 14
 import com.reactnativenavigation.mocks.TopBarButtonCreatorMock;
15 15
 import com.reactnativenavigation.parse.Options;
16
+import com.reactnativenavigation.viewcontrollers.topbar.TopBarController;
16 17
 
17 18
 import org.assertj.android.api.Assertions;
18 19
 import org.junit.Test;
@@ -39,17 +40,17 @@ public class ViewControllerTest extends BaseTest {
39 40
     }
40 41
 
41 42
     @Test
42
-    public void holdsAView() throws Exception {
43
+    public void holdsAView() {
43 44
         assertThat(uut.getView()).isNotNull().isInstanceOf(View.class);
44 45
     }
45 46
 
46 47
     @Test
47
-    public void holdsARefToActivity() throws Exception {
48
+    public void holdsARefToActivity() {
48 49
         assertThat(uut.getActivity()).isNotNull().isEqualTo(activity);
49 50
     }
50 51
 
51 52
     @Test
52
-    public void canOverrideViewCreation() throws Exception {
53
+    public void canOverrideViewCreation() {
53 54
         final FrameLayout otherView = new FrameLayout(activity);
54 55
         ViewController myController = new ViewController(activity, "vc", new Options()) {
55 56
             @Override
@@ -66,38 +67,38 @@ public class ViewControllerTest extends BaseTest {
66 67
     }
67 68
 
68 69
     @Test
69
-    public void holdsAReferenceToStackControllerOrNull() throws Exception {
70
+    public void holdsAReferenceToStackControllerOrNull() {
70 71
         assertThat(uut.getParentController()).isNull();
71
-        StackController nav = new StackController(activity, new TopBarButtonCreatorMock(), new TitleBarReactViewCreatorMock(), new TopBarBackgroundViewCreatorMock(), "stack", new Options());
72
+        StackController nav = new StackController(activity, new TopBarButtonCreatorMock(), new TitleBarReactViewCreatorMock(), new TopBarBackgroundViewCreatorMock(), new TopBarController(), "stack", new Options());
72 73
         nav.animatePush(uut, new MockPromise());
73 74
         assertThat(uut.getParentController()).isEqualTo(nav);
74 75
     }
75 76
 
76 77
     @Test
77
-    public void handleBackDefaultFalse() throws Exception {
78
+    public void handleBackDefaultFalse() {
78 79
         assertThat(uut.handleBack()).isFalse();
79 80
     }
80 81
 
81 82
     @Test
82
-    public void holdsId() throws Exception {
83
+    public void holdsId() {
83 84
         assertThat(uut.getId()).isEqualTo("uut");
84 85
     }
85 86
 
86 87
     @Test
87
-    public void isSameId() throws Exception {
88
+    public void isSameId() {
88 89
         assertThat(uut.isSameId("")).isFalse();
89 90
         assertThat(uut.isSameId(null)).isFalse();
90 91
         assertThat(uut.isSameId("uut")).isTrue();
91 92
     }
92 93
 
93 94
     @Test
94
-    public void findControllerById_SelfOrNull() throws Exception {
95
+    public void findControllerById_SelfOrNull() {
95 96
         assertThat(uut.findControllerById("456")).isNull();
96 97
         assertThat(uut.findControllerById("uut")).isEqualTo(uut);
97 98
     }
98 99
 
99 100
     @Test
100
-    public void onAppear_WhenShown() throws Exception {
101
+    public void onAppear_WhenShown() {
101 102
         ViewController spy = spy(uut);
102 103
         spy.getView().getViewTreeObserver().dispatchOnGlobalLayout();
103 104
         Assertions.assertThat(spy.getView()).isNotShown();
@@ -111,7 +112,7 @@ public class ViewControllerTest extends BaseTest {
111 112
     }
112 113
 
113 114
     @Test
114
-    public void onAppear_CalledAtMostOnce() throws Exception {
115
+    public void onAppear_CalledAtMostOnce() {
115 116
         ViewController spy = spy(uut);
116 117
         Shadows.shadowOf(spy.getView()).setMyParent(mock(ViewParent.class));
117 118
         Assertions.assertThat(spy.getView()).isShown();
@@ -123,7 +124,7 @@ public class ViewControllerTest extends BaseTest {
123 124
     }
124 125
 
125 126
     @Test
126
-    public void onDisappear_WhenNotShown_AfterOnAppearWasCalled() throws Exception {
127
+    public void onDisappear_WhenNotShown_AfterOnAppearWasCalled() {
127 128
         ViewController spy = spy(uut);
128 129
         Shadows.shadowOf(spy.getView()).setMyParent(mock(ViewParent.class));
129 130
         Assertions.assertThat(spy.getView()).isShown();
@@ -138,7 +139,7 @@ public class ViewControllerTest extends BaseTest {
138 139
     }
139 140
 
140 141
     @Test
141
-    public void onDisappear_CalledAtMostOnce() throws Exception {
142
+    public void onDisappear_CalledAtMostOnce() {
142 143
         ViewController spy = spy(uut);
143 144
         Shadows.shadowOf(spy.getView()).setMyParent(mock(ViewParent.class));
144 145
         Assertions.assertThat(spy.getView()).isShown();
@@ -171,7 +172,7 @@ public class ViewControllerTest extends BaseTest {
171 172
     }
172 173
 
173 174
     @Test
174
-    public void onDestroy_CallsOnDisappearIfNeeded() throws Exception {
175
+    public void onDestroy_CallsOnDisappearIfNeeded() {
175 176
         ViewController spy = spy(uut);
176 177
         Shadows.shadowOf(spy.getView()).setMyParent(mock(ViewParent.class));
177 178
         Assertions.assertThat(spy.getView()).isShown();
@@ -184,12 +185,12 @@ public class ViewControllerTest extends BaseTest {
184 185
     }
185 186
 
186 187
     @Test
187
-    public void assignsIdToCreatedView() throws Exception {
188
+    public void assignsIdToCreatedView() {
188 189
         assertThat(uut.getView().getId()).isPositive();
189 190
     }
190 191
 
191 192
     @Test
192
-    public void onDestroy_RemovesSelfFromParentIfExists() throws Exception {
193
+    public void onDestroy_RemovesSelfFromParentIfExists() {
193 194
         LinearLayout parent = new LinearLayout(activity);
194 195
         parent.addView(uut.getView());
195 196
 
@@ -198,7 +199,7 @@ public class ViewControllerTest extends BaseTest {
198 199
     }
199 200
 
200 201
     @Test
201
-    public void ensureViewIsCreated() throws Exception {
202
+    public void ensureViewIsCreated() {
202 203
         ViewController spy = spy(uut);
203 204
         verify(spy, times(0)).getView();
204 205
         spy.ensureViewIsCreated();

+ 5
- 4
lib/android/app/src/test/java/com/reactnativenavigation/views/TopBarBackgroundComponentTest.java View File

@@ -12,6 +12,7 @@ import com.reactnativenavigation.mocks.TopBarButtonCreatorMock;
12 12
 import com.reactnativenavigation.parse.params.Text;
13 13
 import com.reactnativenavigation.utils.ViewUtils;
14 14
 import com.reactnativenavigation.viewcontrollers.TopBarButtonController;
15
+import com.reactnativenavigation.viewcontrollers.topbar.TopBarController;
15 16
 import com.reactnativenavigation.views.topbar.TopBar;
16 17
 import com.reactnativenavigation.views.topbar.TopBarBackgroundView;
17 18
 
@@ -42,13 +43,13 @@ public class TopBarBackgroundComponentTest extends BaseTest {
42 43
                 return backgroundView;
43 44
             }
44 45
         };
45
-        StackLayout parent = new StackLayout(newActivity(), new TopBarButtonCreatorMock(), new TitleBarReactViewCreatorMock(), backgroundViewCreator, onClickListener, null);
46
+        StackLayout parent = new StackLayout(newActivity(), new TopBarButtonCreatorMock(), new TitleBarReactViewCreatorMock(), backgroundViewCreator, new TopBarController(), onClickListener, null);
46 47
         uut = new TopBar(newActivity(), new TopBarButtonCreatorMock(), new TitleBarReactViewCreatorMock(), backgroundViewCreator, onClickListener, parent);
47 48
         parent.addView(uut);
48 49
     }
49 50
 
50 51
     @Test
51
-    public void setBackgroundComponent() throws Exception {
52
+    public void setBackgroundComponent() {
52 53
         uut.getLayoutParams().height = 100;
53 54
         uut.setBackgroundComponent(new Text("someComponent"));
54 55
         TopBarBackgroundView background = (TopBarBackgroundView) ViewUtils.findChildrenByClassRecursive(uut, TopBarBackgroundView.class).get(0);
@@ -58,13 +59,13 @@ public class TopBarBackgroundComponentTest extends BaseTest {
58 59
     }
59 60
 
60 61
     @Test
61
-    public void setBackgroundComponent_doesNotSetIfNoComponentIsDefined() throws Exception {
62
+    public void setBackgroundComponent_doesNotSetIfNoComponentIsDefined() {
62 63
         uut.setBackgroundComponent(new Text("someComponent"));
63 64
         assertThat(uut.findViewById(R.id.topBarBackgroundComponent)).isNull();
64 65
     }
65 66
 
66 67
     @Test
67
-    public void clear_componentIsDestroyed() throws Exception {
68
+    public void clear_componentIsDestroyed() {
68 69
         uut.setBackgroundComponent(new Text("someComponent"));
69 70
         uut.clear();
70 71
         verify(backgroundView, times(1)).destroy();

+ 6
- 5
lib/android/app/src/test/java/com/reactnativenavigation/views/TopBarTest.java View File

@@ -13,6 +13,7 @@ import com.reactnativenavigation.parse.params.Button;
13 13
 import com.reactnativenavigation.parse.params.Text;
14 14
 import com.reactnativenavigation.utils.TitleBarHelper;
15 15
 import com.reactnativenavigation.viewcontrollers.TopBarButtonController;
16
+import com.reactnativenavigation.viewcontrollers.topbar.TopBarController;
16 17
 import com.reactnativenavigation.views.topbar.TopBar;
17 18
 
18 19
 import org.junit.Test;
@@ -41,7 +42,7 @@ public class TopBarTest extends BaseTest {
41 42
                 Log.i("TopBarTest", "onPress: " + buttonId);
42 43
             }
43 44
         });
44
-        StackLayout parent = new StackLayout(newActivity(), new TopBarButtonCreatorMock(), new TitleBarReactViewCreatorMock(), new TopBarBackgroundViewCreatorMock(), this.onClickListener, null);
45
+        StackLayout parent = new StackLayout(newActivity(), new TopBarButtonCreatorMock(), new TitleBarReactViewCreatorMock(), new TopBarBackgroundViewCreatorMock(), new TopBarController(), this.onClickListener, null);
45 46
         uut = new TopBar(newActivity(), new TopBarButtonCreatorMock(), new TitleBarReactViewCreatorMock(), new TopBarBackgroundViewCreatorMock(), this.onClickListener, parent);
46 47
         animator = spy(new TopBarAnimator(uut));
47 48
         uut.setAnimator(animator);
@@ -72,21 +73,21 @@ public class TopBarTest extends BaseTest {
72 73
     }
73 74
 
74 75
     @Test
75
-    public void title() throws Exception {
76
+    public void title() {
76 77
         assertThat(uut.getTitle()).isEmpty();
77 78
         uut.setTitle("new title");
78 79
         assertThat(uut.getTitle()).isEqualTo("new title");
79 80
     }
80 81
 
81 82
     @Test
82
-    public void hide_animate() throws Exception {
83
+    public void hide_animate() {
83 84
         AnimationOptions options = new AnimationOptions();
84 85
         uut.hideAnimate(options);
85 86
         verify(animator, times(1)).hide(options, null);
86 87
     }
87 88
 
88 89
     @Test
89
-    public void show_animate() throws Exception {
90
+    public void show_animate() {
90 91
         AnimationOptions options = new AnimationOptions();
91 92
         uut.hide();
92 93
         uut.showAnimate(options);
@@ -94,7 +95,7 @@ public class TopBarTest extends BaseTest {
94 95
     }
95 96
 
96 97
     @Test
97
-    public void button_TitleBarButtonOnClickInvoked() throws Exception {
98
+    public void button_TitleBarButtonOnClickInvoked() {
98 99
         uut.setLeftButtons(new ArrayList<>());
99 100
         uut.setRightButtons(rightButtons);
100 101
         for (int i = 0; i < rightButtons.size(); i++) {