Guy Carmeli пре 7 година
родитељ
комит
9a39716b42
14 измењених фајлова са 321 додато и 188 уклоњено
  1. 1
    4
      lib/android/app/src/main/java/com/reactnativenavigation/parse/LayoutFactory.java
  2. 28
    1
      lib/android/app/src/main/java/com/reactnativenavigation/react/NavigationModule.java
  3. 16
    0
      lib/android/app/src/main/java/com/reactnativenavigation/utils/CommandListenerAdapter.java
  4. 4
    0
      lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/ModalStack.java
  5. 17
    5
      lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/Navigator.java
  6. 38
    5
      lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/StackController.java
  7. 3
    3
      lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/BottomTabsControllerTest.java
  8. 8
    8
      lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/FloatingActionButtonTest.java
  9. 62
    49
      lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/NavigatorTest.java
  10. 14
    13
      lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/OptionsApplyingTest.java
  11. 4
    4
      lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/ParentControllerTest.java
  12. 121
    91
      lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/StackControllerTest.java
  13. 3
    3
      lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/TopTabsViewControllerTest.java
  14. 2
    2
      lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/ViewControllerTest.java

+ 1
- 4
lib/android/app/src/main/java/com/reactnativenavigation/parse/LayoutFactory.java Прегледај датотеку

4
 
4
 
5
 import com.facebook.react.ReactInstanceManager;
5
 import com.facebook.react.ReactInstanceManager;
6
 import com.reactnativenavigation.utils.ImageLoader;
6
 import com.reactnativenavigation.utils.ImageLoader;
7
-import com.reactnativenavigation.utils.NoOpPromise;
8
 import com.reactnativenavigation.utils.TypefaceLoader;
7
 import com.reactnativenavigation.utils.TypefaceLoader;
9
 import com.reactnativenavigation.viewcontrollers.ComponentViewController;
8
 import com.reactnativenavigation.viewcontrollers.ComponentViewController;
10
 import com.reactnativenavigation.viewcontrollers.SideMenuController;
9
 import com.reactnativenavigation.viewcontrollers.SideMenuController;
138
     private void addChildrenToStack(List<LayoutNode> children, StackController stackController) {
137
     private void addChildrenToStack(List<LayoutNode> children, StackController stackController) {
139
         for (int i = 0; i < children.size(); i++) {
138
         for (int i = 0; i < children.size(); i++) {
140
             if (i < children.size() - 1) {
139
             if (i < children.size() - 1) {
141
-                stackController.push(create(children.get(i)), new NoOpPromise());
142
-            } else {
143
-                stackController.animatePush(create(children.get(i)), new NoOpPromise());
140
+                stackController.push(create(children.get(i)));
144
             }
141
             }
145
         }
142
         }
146
     }
143
     }

+ 28
- 1
lib/android/app/src/main/java/com/reactnativenavigation/react/NavigationModule.java Прегледај датотеку

65
 		final LayoutNode layoutTree = LayoutNodeParser.parse(new JSONObject(rawLayoutTree.toHashMap()));
65
 		final LayoutNode layoutTree = LayoutNodeParser.parse(new JSONObject(rawLayoutTree.toHashMap()));
66
 		handle(() -> {
66
 		handle(() -> {
67
             final ViewController viewController = newLayoutFactory().create(layoutTree);
67
             final ViewController viewController = newLayoutFactory().create(layoutTree);
68
-            navigator().push(onComponentId, viewController, promise);
68
+            navigator().push(onComponentId, viewController, new CommandListenerAdapter(promise));
69
         });
69
         });
70
 	}
70
 	}
71
 
71
 
72
+    @ReactMethod
73
+    public void setStackRoot(final String onComponentId, final ReadableMap rawLayoutTree, final Promise promise) {
74
+        final LayoutNode layoutTree = LayoutNodeParser.parse(new JSONObject(rawLayoutTree.toHashMap()));
75
+        handle(() -> {
76
+            final ViewController viewController = newLayoutFactory().create(layoutTree);
77
+            navigator().setStackRoot(onComponentId, viewController, new CommandListenerAdapter(promise));
78
+        });
79
+    }
80
+
72
 	@ReactMethod
81
 	@ReactMethod
73
 	public void pop(final String onComponentId, final ReadableMap options, final Promise promise) {
82
 	public void pop(final String onComponentId, final ReadableMap options, final Promise promise) {
74
 		handle(() -> navigator().popSpecific(onComponentId, promise));
83
 		handle(() -> navigator().popSpecific(onComponentId, promise));
142
     private NavigationActivity activity() {
151
     private NavigationActivity activity() {
143
         return (NavigationActivity) getCurrentActivity();
152
         return (NavigationActivity) getCurrentActivity();
144
     }
153
     }
154
+
155
+    private class CommandListenerAdapter implements Navigator.CommandListener {
156
+        private Promise promise;
157
+
158
+        CommandListenerAdapter(Promise promise) {
159
+            this.promise = promise;
160
+        }
161
+
162
+        @Override
163
+        public void onSuccess(String childId) {
164
+            promise.resolve(childId);
165
+        }
166
+
167
+        @Override
168
+        public void onError(String message) {
169
+            promise.reject(new Throwable(message));
170
+        }
171
+    }
145
 }
172
 }

+ 16
- 0
lib/android/app/src/main/java/com/reactnativenavigation/utils/CommandListenerAdapter.java Прегледај датотеку

1
+package com.reactnativenavigation.utils;
2
+
3
+import com.reactnativenavigation.viewcontrollers.Navigator;
4
+
5
+public class CommandListenerAdapter implements Navigator.CommandListener {
6
+    @Override
7
+    public void onSuccess(String childId) {
8
+
9
+    }
10
+
11
+    @Override
12
+    public void onError(String message) {
13
+
14
+    }
15
+}
16
+

+ 4
- 0
lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/ModalStack.java Прегледај датотеку

34
         applyOnModal(componentId, (modal) -> modal.dismiss(promise), () -> Navigator.rejectPromise(promise));
34
         applyOnModal(componentId, (modal) -> modal.dismiss(promise), () -> Navigator.rejectPromise(promise));
35
     }
35
     }
36
 
36
 
37
+    void dismissAll() {
38
+        dismissAll(new NoOpPromise());
39
+    }
40
+
37
     void dismissAll(Promise promise) {
41
     void dismissAll(Promise promise) {
38
         for (Modal modal : modals) {
42
         for (Modal modal : modals) {
39
             modal.dismiss(size() == 1 ? promise : new NoOpPromise());
43
             modal.dismiss(size() == 1 ? promise : new NoOpPromise());

+ 17
- 5
lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/Navigator.java Прегледај датотеку

14
 import com.reactnativenavigation.presentation.NavigationOptionsListener;
14
 import com.reactnativenavigation.presentation.NavigationOptionsListener;
15
 import com.reactnativenavigation.presentation.OverlayManager;
15
 import com.reactnativenavigation.presentation.OverlayManager;
16
 import com.reactnativenavigation.utils.CompatUtils;
16
 import com.reactnativenavigation.utils.CompatUtils;
17
-import com.reactnativenavigation.utils.NoOpPromise;
18
 import com.reactnativenavigation.viewcontrollers.modal.Modal;
17
 import com.reactnativenavigation.viewcontrollers.modal.Modal;
19
 import com.reactnativenavigation.viewcontrollers.modal.ModalCreator;
18
 import com.reactnativenavigation.viewcontrollers.modal.ModalCreator;
20
 import com.reactnativenavigation.viewcontrollers.modal.ModalListener;
19
 import com.reactnativenavigation.viewcontrollers.modal.ModalListener;
24
 
23
 
25
 public class Navigator extends ParentController implements ModalListener {
24
 public class Navigator extends ParentController implements ModalListener {
26
 
25
 
27
-    private static final NoOpPromise NO_OP = new NoOpPromise();
26
+    public interface CommandListener {
27
+        void onSuccess(String childId);
28
+
29
+        void onError(String message);
30
+    }
31
+
28
     private final ModalStack modalStack;
32
     private final ModalStack modalStack;
29
     private ViewController root;
33
     private ViewController root;
30
     private OverlayManager overlayManager = new OverlayManager();
34
     private OverlayManager overlayManager = new OverlayManager();
54
 
58
 
55
     @Override
59
     @Override
56
     public void destroy() {
60
     public void destroy() {
57
-        modalStack.dismissAll(NO_OP);
61
+        modalStack.dismissAll();
58
         super.destroy();
62
         super.destroy();
59
     }
63
     }
60
 
64
 
100
         }
104
         }
101
     }
105
     }
102
 
106
 
103
-    public void push(final String fromId, final ViewController viewController, Promise promise) {
107
+    public void push(final String fromId, final ViewController viewController, CommandListener listener) {
108
+        ViewController from = findControllerById(fromId);
109
+        if (from != null) {
110
+            from.performOnParentStack(stack -> ((StackController) stack).animatePush(viewController, listener));
111
+        }
112
+        listener.onError("Could not push component: " + viewController.getId() + ". Stack with id " + fromId + " was not found.");
113
+    }
114
+
115
+    public void setStackRoot(String fromId, ViewController viewController, CommandListener listener) {
104
         ViewController from = findControllerById(fromId);
116
         ViewController from = findControllerById(fromId);
105
         if (from != null) {
117
         if (from != null) {
106
-            from.performOnParentStack(stack -> ((StackController) stack).animatePush(viewController, promise));
118
+            from.performOnParentStack(stack -> ((StackController) stack).setRoot(viewController, listener));
107
         }
119
         }
108
     }
120
     }
109
 
121
 

+ 38
- 5
lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/StackController.java Прегледај датотеку

9
 import com.facebook.react.bridge.Promise;
9
 import com.facebook.react.bridge.Promise;
10
 import com.reactnativenavigation.anim.NavigationAnimator;
10
 import com.reactnativenavigation.anim.NavigationAnimator;
11
 import com.reactnativenavigation.parse.Options;
11
 import com.reactnativenavigation.parse.Options;
12
+import com.reactnativenavigation.utils.CommandListenerAdapter;
12
 import com.reactnativenavigation.utils.NoOpPromise;
13
 import com.reactnativenavigation.utils.NoOpPromise;
14
+import com.reactnativenavigation.viewcontrollers.Navigator.CommandListener;
13
 import com.reactnativenavigation.viewcontrollers.topbar.TopBarBackgroundViewController;
15
 import com.reactnativenavigation.viewcontrollers.topbar.TopBarBackgroundViewController;
14
 import com.reactnativenavigation.viewcontrollers.topbar.TopBarController;
16
 import com.reactnativenavigation.viewcontrollers.topbar.TopBarController;
15
 import com.reactnativenavigation.views.Component;
17
 import com.reactnativenavigation.views.Component;
91
         topBarController.clear();
93
         topBarController.clear();
92
     }
94
     }
93
 
95
 
94
-    public void push(ViewController child, final Promise promise) {
96
+    public void push(ViewController child) {
97
+        push(child, new CommandListenerAdapter());
98
+    }
99
+
100
+    public void push(ViewController child, CommandListener listener) {
95
         final ViewController toRemove = stack.peek();
101
         final ViewController toRemove = stack.peek();
96
 
102
 
97
         child.setParentController(this);
103
         child.setParentController(this);
102
         if (toRemove != null) {
108
         if (toRemove != null) {
103
             getView().removeView(toRemove.getView());
109
             getView().removeView(toRemove.getView());
104
         }
110
         }
105
-        promise.resolve(child.getId());
111
+        listener.onSuccess(child.getId());
106
     }
112
     }
107
 
113
 
108
-    public void animatePush(final ViewController child, final Promise promise) {
114
+    public void animatePush(final ViewController child, CommandListener listener) {
109
         final ViewController toRemove = stack.peek();
115
         final ViewController toRemove = stack.peek();
110
 
116
 
111
         child.setParentController(this);
117
         child.setParentController(this);
116
         if (toRemove != null) {
122
         if (toRemove != null) {
117
             animator.animatePush(enteringView, () -> {
123
             animator.animatePush(enteringView, () -> {
118
                 getView().removeView(toRemove.getView());
124
                 getView().removeView(toRemove.getView());
119
-                promise.resolve(child.getId());
125
+                listener.onSuccess(child.getId());
120
             });
126
             });
121
         } else {
127
         } else {
122
-            promise.resolve(child.getId());
128
+            listener.onSuccess(child.getId());
129
+        }
130
+    }
131
+
132
+    public void setRoot(ViewController child, CommandListener listener) {
133
+        push(child);
134
+        removeChildrenBellowTop();
135
+        listener.onSuccess(child.getId());
136
+    }
137
+
138
+    public void animateSetRoot(ViewController child, CommandListener listener) {
139
+        animatePush(child, new CommandListenerAdapter() {
140
+            @Override
141
+            public void onSuccess(String childId) {
142
+                removeChildrenBellowTop();
143
+                listener.onSuccess(childId);
144
+            }
145
+        });
146
+    }
147
+
148
+    private void removeChildrenBellowTop() {
149
+        Iterator<String> iterator = stack.iterator();
150
+        while (stack.size() > 1) {
151
+            ViewController controller = stack.get(iterator.next());
152
+            if (!stack.isTop(controller.getId())) {
153
+                stack.remove(controller.getId());
154
+                controller.destroy();
155
+            }
123
         }
156
         }
124
     }
157
     }
125
 
158
 

+ 3
- 3
lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/BottomTabsControllerTest.java Прегледај датотеку

6
 
6
 
7
 import com.reactnativenavigation.BaseTest;
7
 import com.reactnativenavigation.BaseTest;
8
 import com.reactnativenavigation.mocks.ImageLoaderMock;
8
 import com.reactnativenavigation.mocks.ImageLoaderMock;
9
-import com.reactnativenavigation.mocks.MockPromise;
10
 import com.reactnativenavigation.mocks.SimpleViewController;
9
 import com.reactnativenavigation.mocks.SimpleViewController;
11
 import com.reactnativenavigation.mocks.TitleBarReactViewCreatorMock;
10
 import com.reactnativenavigation.mocks.TitleBarReactViewCreatorMock;
12
 import com.reactnativenavigation.mocks.TopBarBackgroundViewCreatorMock;
11
 import com.reactnativenavigation.mocks.TopBarBackgroundViewCreatorMock;
14
 import com.reactnativenavigation.parse.Options;
13
 import com.reactnativenavigation.parse.Options;
15
 import com.reactnativenavigation.parse.params.Color;
14
 import com.reactnativenavigation.parse.params.Color;
16
 import com.reactnativenavigation.parse.params.Number;
15
 import com.reactnativenavigation.parse.params.Number;
16
+import com.reactnativenavigation.utils.CommandListenerAdapter;
17
 import com.reactnativenavigation.utils.ImageLoader;
17
 import com.reactnativenavigation.utils.ImageLoader;
18
 import com.reactnativenavigation.utils.OptionHelper;
18
 import com.reactnativenavigation.utils.OptionHelper;
19
 import com.reactnativenavigation.viewcontrollers.bottomtabs.BottomTabsController;
19
 import com.reactnativenavigation.viewcontrollers.bottomtabs.BottomTabsController;
105
         assertThat(uut.findControllerById("123")).isNull();
105
         assertThat(uut.findControllerById("123")).isNull();
106
         assertThat(uut.findControllerById(uut.getId())).isEqualTo(uut);
106
         assertThat(uut.findControllerById(uut.getId())).isEqualTo(uut);
107
         StackController inner = createStack("inner");
107
         StackController inner = createStack("inner");
108
-        inner.animatePush(child1, new MockPromise());
108
+        inner.animatePush(child1, new CommandListenerAdapter());
109
         assertThat(uut.findControllerById(child1.getId())).isNull();
109
         assertThat(uut.findControllerById(child1.getId())).isNull();
110
         uut.setTabs(Collections.singletonList(inner));
110
         uut.setTabs(Collections.singletonList(inner));
111
         assertThat(uut.findControllerById(child1.getId())).isEqualTo(child1);
111
         assertThat(uut.findControllerById(child1.getId())).isEqualTo(child1);
137
 
137
 
138
         StackController stack = spy(createStack("stack"));
138
         StackController stack = spy(createStack("stack"));
139
         stack.ensureViewIsCreated();
139
         stack.ensureViewIsCreated();
140
-        stack.push(uut, new MockPromise());
140
+        stack.push(uut);
141
 
141
 
142
         child1.onViewAppeared();
142
         child1.onViewAppeared();
143
         ArgumentCaptor<Options> optionsCaptor = ArgumentCaptor.forClass(Options.class);
143
         ArgumentCaptor<Options> optionsCaptor = ArgumentCaptor.forClass(Options.class);

+ 8
- 8
lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/FloatingActionButtonTest.java Прегледај датотеку

81
 
81
 
82
     @Test
82
     @Test
83
     public void showOnPush() {
83
     public void showOnPush() {
84
-        stackController.push(childFab, new MockPromise());
84
+        stackController.push(childFab);
85
         childFab.onViewAppeared();
85
         childFab.onViewAppeared();
86
         assertThat(hasFab()).isTrue();
86
         assertThat(hasFab()).isTrue();
87
     }
87
     }
88
 
88
 
89
     @Test
89
     @Test
90
     public void hideOnPush() {
90
     public void hideOnPush() {
91
-        stackController.push(childFab, new MockPromise());
91
+        stackController.push(childFab);
92
         childFab.onViewAppeared();
92
         childFab.onViewAppeared();
93
         assertThat(hasFab()).isTrue();
93
         assertThat(hasFab()).isTrue();
94
-        stackController.push(childNoFab, new MockPromise());
94
+        stackController.push(childNoFab);
95
         childNoFab.onViewAppeared();
95
         childNoFab.onViewAppeared();
96
         assertThat(hasFab()).isFalse();
96
         assertThat(hasFab()).isFalse();
97
     }
97
     }
98
 
98
 
99
     @Test
99
     @Test
100
     public void hideOnPop() {
100
     public void hideOnPop() {
101
-        stackController.push(childNoFab, new MockPromise());
102
-        stackController.push(childFab, new MockPromise());
101
+        stackController.push(childNoFab);
102
+        stackController.push(childFab);
103
         childFab.onViewAppeared();
103
         childFab.onViewAppeared();
104
         assertThat(hasFab()).isTrue();
104
         assertThat(hasFab()).isTrue();
105
         stackController.pop(new MockPromise());
105
         stackController.pop(new MockPromise());
109
 
109
 
110
     @Test
110
     @Test
111
     public void showOnPop() {
111
     public void showOnPop() {
112
-        stackController.push(childFab, new MockPromise());
113
-        stackController.push(childNoFab, new MockPromise());
112
+        stackController.push(childFab);
113
+        stackController.push(childNoFab);
114
         childNoFab.onViewAppeared();
114
         childNoFab.onViewAppeared();
115
         assertThat(hasFab()).isFalse();
115
         assertThat(hasFab()).isFalse();
116
         stackController.pop(new MockPromise());
116
         stackController.pop(new MockPromise());
121
     @Test
121
     @Test
122
     public void hasChildren() {
122
     public void hasChildren() {
123
         childFab = new SimpleViewController(activity, "child1", getOptionsWithFabActions());
123
         childFab = new SimpleViewController(activity, "child1", getOptionsWithFabActions());
124
-        stackController.push(childFab, new MockPromise());
124
+        stackController.push(childFab);
125
         childFab.onViewAppeared();
125
         childFab.onViewAppeared();
126
         assertThat(hasFab()).isTrue();
126
         assertThat(hasFab()).isTrue();
127
         assertThat(containsActions()).isTrue();
127
         assertThat(containsActions()).isTrue();

+ 62
- 49
lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/NavigatorTest.java Прегледај датотеку

13
 import com.reactnativenavigation.mocks.TopBarButtonCreatorMock;
13
 import com.reactnativenavigation.mocks.TopBarButtonCreatorMock;
14
 import com.reactnativenavigation.parse.Options;
14
 import com.reactnativenavigation.parse.Options;
15
 import com.reactnativenavigation.parse.params.Text;
15
 import com.reactnativenavigation.parse.params.Text;
16
+import com.reactnativenavigation.utils.CommandListenerAdapter;
16
 import com.reactnativenavigation.utils.CompatUtils;
17
 import com.reactnativenavigation.utils.CompatUtils;
17
 import com.reactnativenavigation.utils.ImageLoader;
18
 import com.reactnativenavigation.utils.ImageLoader;
18
 import com.reactnativenavigation.utils.OptionHelper;
19
 import com.reactnativenavigation.utils.OptionHelper;
82
     @Test
83
     @Test
83
     public void push() {
84
     public void push() {
84
         StackController stackController = newStack();
85
         StackController stackController = newStack();
85
-        stackController.animatePush(child1, new MockPromise());
86
+        stackController.animatePush(child1, new CommandListenerAdapter());
86
         uut.setRoot(stackController, new MockPromise());
87
         uut.setRoot(stackController, new MockPromise());
87
 
88
 
88
         assertIsChildById(uut.getView(), stackController.getView());
89
         assertIsChildById(uut.getView(), stackController.getView());
89
         assertIsChildById(stackController.getView(), child1.getView());
90
         assertIsChildById(stackController.getView(), child1.getView());
90
 
91
 
91
-        uut.push(child1.getId(), child2, new MockPromise());
92
+        uut.push(child1.getId(), child2, new CommandListenerAdapter());
92
 
93
 
93
         assertIsChildById(uut.getView(), stackController.getView());
94
         assertIsChildById(uut.getView(), stackController.getView());
94
         assertIsChildById(stackController.getView(), child2.getView());
95
         assertIsChildById(stackController.getView(), child2.getView());
97
     @Test
98
     @Test
98
     public void push_InvalidPushWithoutAStack_DoesNothing() {
99
     public void push_InvalidPushWithoutAStack_DoesNothing() {
99
         uut.setRoot(child1, new MockPromise());
100
         uut.setRoot(child1, new MockPromise());
100
-        uut.push(child1.getId(), child2, new MockPromise());
101
+        uut.push(child1.getId(), child2, new CommandListenerAdapter());
101
         assertIsChildById(uut.getView(), child1.getView());
102
         assertIsChildById(uut.getView(), child1.getView());
102
     }
103
     }
103
 
104
 
106
         BottomTabsController bottomTabsController = newTabs();
107
         BottomTabsController bottomTabsController = newTabs();
107
         StackController stack1 = newStack();
108
         StackController stack1 = newStack();
108
         StackController stack2 = newStack();
109
         StackController stack2 = newStack();
109
-        stack1.animatePush(child1, new MockPromise());
110
-        stack2.animatePush(child2, new MockPromise());
110
+        stack1.animatePush(child1, new CommandListenerAdapter());
111
+        stack2.animatePush(child2, new CommandListenerAdapter());
111
         bottomTabsController.setTabs(Arrays.asList(stack1, stack2));
112
         bottomTabsController.setTabs(Arrays.asList(stack1, stack2));
112
         uut.setRoot(bottomTabsController, new MockPromise());
113
         uut.setRoot(bottomTabsController, new MockPromise());
113
 
114
 
114
         SimpleViewController newChild = new SimpleViewController(activity, "new child", tabOptions);
115
         SimpleViewController newChild = new SimpleViewController(activity, "new child", tabOptions);
115
-        uut.push(child2.getId(), newChild, new MockPromise());
116
+        uut.push(child2.getId(), newChild, new CommandListenerAdapter());
116
 
117
 
117
         assertThat(stack1.getChildControllers()).doesNotContain(newChild);
118
         assertThat(stack1.getChildControllers()).doesNotContain(newChild);
118
         assertThat(stack2.getChildControllers()).contains(newChild);
119
         assertThat(stack2.getChildControllers()).contains(newChild);
133
         StackController stack2 = newStack();
134
         StackController stack2 = newStack();
134
         bottomTabsController.setTabs(Arrays.asList(stack1, stack2));
135
         bottomTabsController.setTabs(Arrays.asList(stack1, stack2));
135
         uut.setRoot(bottomTabsController, new MockPromise());
136
         uut.setRoot(bottomTabsController, new MockPromise());
136
-        stack1.animatePush(child1, new MockPromise());
137
-        stack2.animatePush(child2, new MockPromise());
138
-        stack2.animatePush(child3, new MockPromise() {
137
+        stack1.animatePush(child1, new CommandListenerAdapter());
138
+        stack2.animatePush(child2, new CommandListenerAdapter());
139
+        stack2.animatePush(child3, new CommandListenerAdapter() {
139
             @Override
140
             @Override
140
-            public void resolve(@Nullable Object value) {
141
-                stack2.animatePush(child4, new MockPromise() {
142
-                    @Override
143
-                    public void resolve(@Nullable Object value) {
144
-                        uut.pop("child4", new MockPromise());
145
-                        assertThat(stack2.getChildControllers()).containsOnly(child2, child3);
146
-                    }
147
-                });
141
+            public void onSuccess(String childId) {
142
+                stack2.animatePush(child4, new CommandListenerAdapter() {
143
+                            @Override
144
+                            public void onSuccess(String childId) {
145
+                                uut.pop("child4", new MockPromise());
146
+                                assertThat(stack2.getChildControllers()).containsOnly(child2, child3);
147
+                            }
148
+                        }
149
+                );
148
             }
150
             }
149
         });
151
         });
150
     }
152
     }
154
         BottomTabsController bottomTabsController = newTabs();
156
         BottomTabsController bottomTabsController = newTabs();
155
         StackController stack1 = newStack();
157
         StackController stack1 = newStack();
156
         StackController stack2 = newStack();
158
         StackController stack2 = newStack();
157
-        stack1.animatePush(child1, new MockPromise());
158
-        stack2.animatePush(child2, new MockPromise());
159
-        stack2.animatePush(child3, new MockPromise());
160
-        stack2.animatePush(child4, new MockPromise());
159
+        stack1.animatePush(child1, new CommandListenerAdapter());
160
+        stack2.animatePush(child2, new CommandListenerAdapter());
161
+        stack2.animatePush(child3, new CommandListenerAdapter());
162
+        stack2.animatePush(child4, new CommandListenerAdapter());
161
         bottomTabsController.setTabs(Arrays.asList(stack1, stack2));
163
         bottomTabsController.setTabs(Arrays.asList(stack1, stack2));
162
         uut.setRoot(bottomTabsController, new MockPromise());
164
         uut.setRoot(bottomTabsController, new MockPromise());
163
 
165
 
174
         bottomTabsController.setTabs(Arrays.asList(stack1, stack2));
176
         bottomTabsController.setTabs(Arrays.asList(stack1, stack2));
175
         uut.setRoot(bottomTabsController, new MockPromise());
177
         uut.setRoot(bottomTabsController, new MockPromise());
176
 
178
 
177
-        stack1.animatePush(child1, new MockPromise());
178
-        stack2.animatePush(child2, new MockPromise());
179
-        stack2.animatePush(child3, new MockPromise());
180
-        stack2.animatePush(child4, new MockPromise());
181
-        stack2.animatePush(child5, new MockPromise() {
179
+        stack1.animatePush(child1, new CommandListenerAdapter());
180
+        stack2.animatePush(child2, new CommandListenerAdapter());
181
+        stack2.animatePush(child3, new CommandListenerAdapter());
182
+        stack2.animatePush(child4, new CommandListenerAdapter());
183
+        stack2.animatePush(child5, new CommandListenerAdapter() {
182
             @Override
184
             @Override
183
-            public void resolve(@Nullable Object value) {
185
+            public void onSuccess(String childId) {
184
                 uut.popTo(child2.getId(), new MockPromise());
186
                 uut.popTo(child2.getId(), new MockPromise());
185
                 assertThat(stack2.getChildControllers()).containsOnly(child2);
187
                 assertThat(stack2.getChildControllers()).containsOnly(child2);
186
             }
188
             }
195
         bottomTabsController.setTabs(Arrays.asList(stack1, stack2));
197
         bottomTabsController.setTabs(Arrays.asList(stack1, stack2));
196
         uut.setRoot(bottomTabsController, new MockPromise());
198
         uut.setRoot(bottomTabsController, new MockPromise());
197
 
199
 
198
-        stack1.animatePush(child1, new MockPromise());
199
-        stack2.animatePush(child2, new MockPromise());
200
-        stack2.animatePush(child3, new MockPromise());
201
-        stack2.animatePush(child4, new MockPromise());
202
-        stack2.animatePush(child5, new MockPromise() {
200
+        stack1.animatePush(child1, new CommandListenerAdapter());
201
+        stack2.animatePush(child2, new CommandListenerAdapter());
202
+        stack2.animatePush(child3, new CommandListenerAdapter());
203
+        stack2.animatePush(child4, new CommandListenerAdapter());
204
+        stack2.animatePush(child5, new CommandListenerAdapter() {
203
             @Override
205
             @Override
204
-            public void resolve(@Nullable Object value) {
206
+            public void onSuccess(String childId) {
205
                 uut.popToRoot(child3.getId(), new MockPromise());
207
                 uut.popToRoot(child3.getId(), new MockPromise());
206
-
207
                 assertThat(stack2.getChildControllers()).containsOnly(child2);
208
                 assertThat(stack2.getChildControllers()).containsOnly(child2);
208
             }
209
             }
209
         });
210
         });
210
     }
211
     }
211
 
212
 
213
+    @Test
214
+    public void setStackRoot() {
215
+        StackController stack = newStack();
216
+        uut.setRoot(stack, new MockPromise());
217
+
218
+        stack.animatePush(child1, new CommandListenerAdapter());
219
+        stack.animatePush(child2, new CommandListenerAdapter());
220
+        stack.setRoot(child3, new CommandListenerAdapter());
221
+
222
+        assertThat(stack.getChildControllers()).containsOnly(child3);
223
+    }
224
+
212
     @Test
225
     @Test
213
     public void handleBack_DelegatesToRoot() {
226
     public void handleBack_DelegatesToRoot() {
214
         ViewController root = spy(child1);
227
         ViewController root = spy(child1);
259
     @Test
272
     @Test
260
     public void push_Promise() {
273
     public void push_Promise() {
261
         final StackController stackController = newStack();
274
         final StackController stackController = newStack();
262
-        stackController.animatePush(child1, new MockPromise());
275
+        stackController.animatePush(child1, new CommandListenerAdapter());
263
         uut.setRoot(stackController, new MockPromise());
276
         uut.setRoot(stackController, new MockPromise());
264
 
277
 
265
         assertIsChildById(uut.getView(), stackController.getView());
278
         assertIsChildById(uut.getView(), stackController.getView());
266
         assertIsChildById(stackController.getView(), child1.getView());
279
         assertIsChildById(stackController.getView(), child1.getView());
267
 
280
 
268
-        uut.push(child1.getId(), child2, new MockPromise() {
281
+        uut.push(child1.getId(), child2, new CommandListenerAdapter() {
269
             @Override
282
             @Override
270
-            public void resolve(@Nullable Object value) {
283
+            public void onSuccess(String childId) {
271
                 assertIsChildById(uut.getView(), stackController.getView());
284
                 assertIsChildById(uut.getView(), stackController.getView());
272
                 assertIsChildById(stackController.getView(), child2.getView());
285
                 assertIsChildById(stackController.getView(), child2.getView());
273
             }
286
             }
277
     @Test
290
     @Test
278
     public void push_InvalidPushWithoutAStack_DoesNothing_Promise() {
291
     public void push_InvalidPushWithoutAStack_DoesNothing_Promise() {
279
         uut.setRoot(child1, new MockPromise());
292
         uut.setRoot(child1, new MockPromise());
280
-        uut.push(child1.getId(), child2, new MockPromise() {
293
+        uut.push(child1.getId(), child2, new CommandListenerAdapter() {
281
             @Override
294
             @Override
282
-            public void reject(String code, Throwable e) {
295
+            public void onError(String message) {
283
                 assertIsChildById(uut.getView(), child1.getView());
296
                 assertIsChildById(uut.getView(), child1.getView());
284
             }
297
             }
285
         });
298
         });
306
         bottomTabsController.setTabs(Arrays.asList(stack1, stack2));
319
         bottomTabsController.setTabs(Arrays.asList(stack1, stack2));
307
         uut.setRoot(bottomTabsController, new MockPromise());
320
         uut.setRoot(bottomTabsController, new MockPromise());
308
 
321
 
309
-        stack1.animatePush(child1, new MockPromise());
310
-        stack2.animatePush(child2, new MockPromise());
311
-        stack2.animatePush(child3, new MockPromise());
312
-        stack2.animatePush(child4, new MockPromise() {
322
+        stack1.animatePush(child1, new CommandListenerAdapter());
323
+        stack2.animatePush(child2, new CommandListenerAdapter());
324
+        stack2.animatePush(child3, new CommandListenerAdapter());
325
+        stack2.animatePush(child4, new CommandListenerAdapter() {
313
             @Override
326
             @Override
314
-            public void resolve(@Nullable Object value) {
327
+            public void onSuccess(String childId) {
315
                 uut.pop("child4", new MockPromise());
328
                 uut.pop("child4", new MockPromise());
316
                 assertThat(stack2.getChildControllers()).containsOnly(child2, child3);
329
                 assertThat(stack2.getChildControllers()).containsOnly(child2, child3);
317
             }
330
             }
322
     public void pushIntoModal() {
335
     public void pushIntoModal() {
323
         uut.setRoot(parentController, new MockPromise());
336
         uut.setRoot(parentController, new MockPromise());
324
         StackController stackController = newStack();
337
         StackController stackController = newStack();
325
-        stackController.push(child1, new MockPromise());
338
+        stackController.push(child1);
326
         uut.showModal(stackController, new MockPromise());
339
         uut.showModal(stackController, new MockPromise());
327
-        uut.push(stackController.getId(), child2, new MockPromise());
340
+        uut.push(stackController.getId(), child2, new CommandListenerAdapter());
328
         assertIsChildById(stackController.getView(), child2.getView());
341
         assertIsChildById(stackController.getView(), child2.getView());
329
     }
342
     }
330
 
343
 
333
         StackController parent = newStack();
346
         StackController parent = newStack();
334
         parent.ensureViewIsCreated();
347
         parent.ensureViewIsCreated();
335
         uut.setRoot(parent, new MockPromise());
348
         uut.setRoot(parent, new MockPromise());
336
-        parent.push(parentController, new MockPromise());
349
+        parent.push(parentController);
337
 
350
 
338
-        parentController.push(child1, new MockPromise());
339
-        parentController.push(child2, new MockPromise());
351
+        parentController.push(child1);
352
+        parentController.push(child2);
340
         assertThat(parentController.getChildControllers().size()).isEqualTo(2);
353
         assertThat(parentController.getChildControllers().size()).isEqualTo(2);
341
         child1.ensureViewIsCreated();
354
         child1.ensureViewIsCreated();
342
         child2.ensureViewIsCreated();
355
         child2.ensureViewIsCreated();

+ 14
- 13
lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/OptionsApplyingTest.java Прегледај датотеку

7
 import android.widget.RelativeLayout;
7
 import android.widget.RelativeLayout;
8
 
8
 
9
 import com.reactnativenavigation.BaseTest;
9
 import com.reactnativenavigation.BaseTest;
10
-import com.reactnativenavigation.mocks.MockPromise;
11
 import com.reactnativenavigation.mocks.TestComponentLayout;
10
 import com.reactnativenavigation.mocks.TestComponentLayout;
12
 import com.reactnativenavigation.mocks.TestReactView;
11
 import com.reactnativenavigation.mocks.TestReactView;
13
 import com.reactnativenavigation.mocks.TitleBarReactViewCreatorMock;
12
 import com.reactnativenavigation.mocks.TitleBarReactViewCreatorMock;
20
 import com.reactnativenavigation.parse.params.Bool;
19
 import com.reactnativenavigation.parse.params.Bool;
21
 import com.reactnativenavigation.parse.params.Fraction;
20
 import com.reactnativenavigation.parse.params.Fraction;
22
 import com.reactnativenavigation.parse.params.Text;
21
 import com.reactnativenavigation.parse.params.Text;
22
+import com.reactnativenavigation.utils.CommandListenerAdapter;
23
 import com.reactnativenavigation.utils.ViewUtils;
23
 import com.reactnativenavigation.utils.ViewUtils;
24
 import com.reactnativenavigation.viewcontrollers.topbar.TopBarBackgroundViewController;
24
 import com.reactnativenavigation.viewcontrollers.topbar.TopBarBackgroundViewController;
25
 import com.reactnativenavigation.viewcontrollers.topbar.TopBarController;
25
 import com.reactnativenavigation.viewcontrollers.topbar.TopBarController;
28
 import org.json.JSONObject;
28
 import org.json.JSONObject;
29
 import org.junit.Test;
29
 import org.junit.Test;
30
 
30
 
31
-import javax.annotation.Nullable;
32
-
33
 import static android.view.ViewGroup.LayoutParams.MATCH_PARENT;
31
 import static android.view.ViewGroup.LayoutParams.MATCH_PARENT;
34
 import static android.widget.RelativeLayout.BELOW;
32
 import static android.widget.RelativeLayout.BELOW;
35
 import static org.assertj.core.api.Java6Assertions.assertThat;
33
 import static org.assertj.core.api.Java6Assertions.assertThat;
55
                 (activity1, componentId, componentName) -> view,
53
                 (activity1, componentId, componentName) -> view,
56
                 initialNavigationOptions
54
                 initialNavigationOptions
57
         );
55
         );
58
-        stackController = new StackController(activity, new TopBarButtonCreatorMock(), new TitleBarReactViewCreatorMock(), new TopBarBackgroundViewController(activity, new TopBarBackgroundViewCreatorMock()), new TopBarController(), "stack", new Options());
56
+        stackController =
57
+                new StackController(activity, new TopBarButtonCreatorMock(), new TitleBarReactViewCreatorMock(), new TopBarBackgroundViewController(activity, new TopBarBackgroundViewCreatorMock()), new TopBarController(), "stack", new Options());
59
         stackController.ensureViewIsCreated();
58
         stackController.ensureViewIsCreated();
60
         uut.setParentController(stackController);
59
         uut.setParentController(stackController);
61
     }
60
     }
72
     @Test
71
     @Test
73
     public void initialOptionsAppliedOnAppear() {
72
     public void initialOptionsAppliedOnAppear() {
74
         uut.options.topBarOptions.title.text = new Text("the title");
73
         uut.options.topBarOptions.title.text = new Text("the title");
75
-        StackController stackController = new StackController(activity, new TopBarButtonCreatorMock(), new TitleBarReactViewCreatorMock(), new TopBarBackgroundViewController(activity, new TopBarBackgroundViewCreatorMock()), new TopBarController(), "stackId", new Options());
76
-        stackController.animatePush(uut, new MockPromise() {});
74
+        StackController stackController =
75
+                new StackController(activity, new TopBarButtonCreatorMock(), new TitleBarReactViewCreatorMock(), new TopBarBackgroundViewController(activity, new TopBarBackgroundViewCreatorMock()), new TopBarController(), "stackId", new Options());
76
+        stackController.animatePush(uut, new CommandListenerAdapter());
77
         assertThat(stackController.getTopBar().getTitle()).isEmpty();
77
         assertThat(stackController.getTopBar().getTitle()).isEmpty();
78
 
78
 
79
         uut.onViewAppeared();
79
         uut.onViewAppeared();
118
     @Test
118
     @Test
119
     public void appliesTopBarTextColor() {
119
     public void appliesTopBarTextColor() {
120
         assertThat(uut.initialOptions).isSameAs(initialNavigationOptions);
120
         assertThat(uut.initialOptions).isSameAs(initialNavigationOptions);
121
-        stackController.animatePush(uut, new MockPromise() {
121
+        stackController.animatePush(uut, new CommandListenerAdapter() {
122
             @Override
122
             @Override
123
-            public void resolve(@Nullable Object value) {
123
+            public void onSuccess(String childId) {
124
                 Options opts = new Options();
124
                 Options opts = new Options();
125
                 opts.topBarOptions.title.text = new Text("the title");
125
                 opts.topBarOptions.title.text = new Text("the title");
126
                 opts.topBarOptions.title.color = new com.reactnativenavigation.parse.params.Color(Color.RED);
126
                 opts.topBarOptions.title.color = new com.reactnativenavigation.parse.params.Color(Color.RED);
169
         uut.options.topBarOptions.title.text = new Text("the title");
169
         uut.options.topBarOptions.title.text = new Text("the title");
170
         uut.options.topBarOptions.drawBehind = new Bool(false);
170
         uut.options.topBarOptions.drawBehind = new Bool(false);
171
         uut.ensureViewIsCreated();
171
         uut.ensureViewIsCreated();
172
-        stackController.animatePush(uut, new MockPromise() {
172
+        stackController.animatePush(uut, new CommandListenerAdapter() {
173
             @Override
173
             @Override
174
-            public void resolve(@Nullable Object value) {
174
+            public void onSuccess(String childId) {
175
                 uut.onViewAppeared();
175
                 uut.onViewAppeared();
176
-                RelativeLayout.LayoutParams uutLayoutParams = (RelativeLayout.LayoutParams) uut.getComponent().asView().getLayoutParams();
176
+                RelativeLayout.LayoutParams uutLayoutParams =
177
+                        (RelativeLayout.LayoutParams) uut.getComponent().asView().getLayoutParams();
177
                 assertThat(uutLayoutParams.getRule(BELOW)).isNotEqualTo(0);
178
                 assertThat(uutLayoutParams.getRule(BELOW)).isNotEqualTo(0);
178
 
179
 
179
                 Options opts = new Options();
180
                 Options opts = new Options();
192
         json.put("component", "someComponent");
193
         json.put("component", "someComponent");
193
         uut.options.topBarOptions.background = TopBarBackgroundOptions.parse(json);
194
         uut.options.topBarOptions.background = TopBarBackgroundOptions.parse(json);
194
         uut.ensureViewIsCreated();
195
         uut.ensureViewIsCreated();
195
-        stackController.push(uut, new MockPromise());
196
+        stackController.push(uut);
196
         uut.onViewAppeared();
197
         uut.onViewAppeared();
197
 
198
 
198
         assertThat(((ColorDrawable) stackController.getTopBar().getTitleBar().getBackground()).getColor()).isEqualTo(Color.TRANSPARENT);
199
         assertThat(((ColorDrawable) stackController.getTopBar().getTitleBar().getBackground()).getColor()).isEqualTo(Color.TRANSPARENT);
205
         json.put("text", "sub");
206
         json.put("text", "sub");
206
         uut.options.topBarOptions.subtitle = SubtitleOptions.parse(new TypefaceLoaderMock(), json);
207
         uut.options.topBarOptions.subtitle = SubtitleOptions.parse(new TypefaceLoaderMock(), json);
207
         uut.ensureViewIsCreated();
208
         uut.ensureViewIsCreated();
208
-        stackController.push(uut, new MockPromise());
209
+        stackController.push(uut);
209
         uut.onViewAppeared();
210
         uut.onViewAppeared();
210
 
211
 
211
         assertThat(stackController.getTopBar().getTitleBar().getSubtitle()).isEqualTo("sub");
212
         assertThat(stackController.getTopBar().getTitleBar().getSubtitle()).isEqualTo("sub");

+ 4
- 4
lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/ParentControllerTest.java Прегледај датотеку

6
 import android.widget.FrameLayout;
6
 import android.widget.FrameLayout;
7
 
7
 
8
 import com.reactnativenavigation.BaseTest;
8
 import com.reactnativenavigation.BaseTest;
9
-import com.reactnativenavigation.mocks.MockPromise;
10
 import com.reactnativenavigation.mocks.SimpleViewController;
9
 import com.reactnativenavigation.mocks.SimpleViewController;
11
 import com.reactnativenavigation.mocks.TitleBarReactViewCreatorMock;
10
 import com.reactnativenavigation.mocks.TitleBarReactViewCreatorMock;
12
 import com.reactnativenavigation.mocks.TopBarBackgroundViewCreatorMock;
11
 import com.reactnativenavigation.mocks.TopBarBackgroundViewCreatorMock;
13
 import com.reactnativenavigation.mocks.TopBarButtonCreatorMock;
12
 import com.reactnativenavigation.mocks.TopBarButtonCreatorMock;
14
 import com.reactnativenavigation.parse.Options;
13
 import com.reactnativenavigation.parse.Options;
15
 import com.reactnativenavigation.parse.params.Text;
14
 import com.reactnativenavigation.parse.params.Text;
15
+import com.reactnativenavigation.utils.CommandListenerAdapter;
16
 import com.reactnativenavigation.viewcontrollers.topbar.TopBarBackgroundViewController;
16
 import com.reactnativenavigation.viewcontrollers.topbar.TopBarBackgroundViewController;
17
 import com.reactnativenavigation.viewcontrollers.topbar.TopBarController;
17
 import com.reactnativenavigation.viewcontrollers.topbar.TopBarController;
18
 import com.reactnativenavigation.views.ReactComponent;
18
 import com.reactnativenavigation.views.ReactComponent;
95
         StackController stackController = createStack();
95
         StackController stackController = createStack();
96
         SimpleViewController child1 = new SimpleViewController(activity, "child1", new Options());
96
         SimpleViewController child1 = new SimpleViewController(activity, "child1", new Options());
97
         SimpleViewController child2 = new SimpleViewController(activity, "child2", new Options());
97
         SimpleViewController child2 = new SimpleViewController(activity, "child2", new Options());
98
-        stackController.animatePush(child1, new MockPromise());
99
-        stackController.animatePush(child2, new MockPromise());
98
+        stackController.animatePush(child1, new CommandListenerAdapter());
99
+        stackController.animatePush(child2, new CommandListenerAdapter());
100
         children.add(stackController);
100
         children.add(stackController);
101
 
101
 
102
         assertThat(uut.findControllerById("child2")).isEqualTo(child2);
102
         assertThat(uut.findControllerById("child2")).isEqualTo(child2);
116
     public void optionsAreClearedWhenChildIsAppeared() {
116
     public void optionsAreClearedWhenChildIsAppeared() {
117
         StackController stackController = spy(createStack());
117
         StackController stackController = spy(createStack());
118
         SimpleViewController child1 = new SimpleViewController(activity, "child1", new Options());
118
         SimpleViewController child1 = new SimpleViewController(activity, "child1", new Options());
119
-        stackController.animatePush(child1, new MockPromise());
119
+        stackController.animatePush(child1, new CommandListenerAdapter());
120
 
120
 
121
         child1.onViewAppeared();
121
         child1.onViewAppeared();
122
         verify(stackController, times(1)).clearOptions();
122
         verify(stackController, times(1)).clearOptions();

+ 121
- 91
lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/StackControllerTest.java Прегледај датотеку

15
 import com.reactnativenavigation.parse.Options;
15
 import com.reactnativenavigation.parse.Options;
16
 import com.reactnativenavigation.parse.params.Bool;
16
 import com.reactnativenavigation.parse.params.Bool;
17
 import com.reactnativenavigation.parse.params.Text;
17
 import com.reactnativenavigation.parse.params.Text;
18
+import com.reactnativenavigation.utils.CommandListenerAdapter;
18
 import com.reactnativenavigation.utils.ViewHelper;
19
 import com.reactnativenavigation.utils.ViewHelper;
19
 import com.reactnativenavigation.viewcontrollers.topbar.TopBarBackgroundViewController;
20
 import com.reactnativenavigation.viewcontrollers.topbar.TopBarBackgroundViewController;
20
 import com.reactnativenavigation.viewcontrollers.topbar.TopBarController;
21
 import com.reactnativenavigation.viewcontrollers.topbar.TopBarController;
65
     @Test
66
     @Test
66
     public void holdsAStackOfViewControllers() {
67
     public void holdsAStackOfViewControllers() {
67
         assertThat(uut.isEmpty()).isTrue();
68
         assertThat(uut.isEmpty()).isTrue();
68
-        uut.animatePush(child1, new MockPromise());
69
-        uut.animatePush(child2, new MockPromise());
70
-        uut.animatePush(child3, new MockPromise());
69
+        uut.animatePush(child1, new CommandListenerAdapter());
70
+        uut.animatePush(child2, new CommandListenerAdapter());
71
+        uut.animatePush(child3, new CommandListenerAdapter());
71
         assertThat(uut.peek()).isEqualTo(child3);
72
         assertThat(uut.peek()).isEqualTo(child3);
72
         assertContainsOnlyId(child1.getId(), child2.getId(), child3.getId());
73
         assertContainsOnlyId(child1.getId(), child2.getId(), child3.getId());
73
     }
74
     }
75
     @Test
76
     @Test
76
     public void push() {
77
     public void push() {
77
         assertThat(uut.isEmpty()).isTrue();
78
         assertThat(uut.isEmpty()).isTrue();
78
-        uut.animatePush(child1, new MockPromise());
79
+        uut.animatePush(child1, new CommandListenerAdapter());
79
         assertContainsOnlyId(child1.getId());
80
         assertContainsOnlyId(child1.getId());
80
     }
81
     }
81
 
82
 
83
+    @Test
84
+    public void animateSetRoot() {
85
+        assertThat(uut.isEmpty()).isTrue();
86
+        uut.push(child1, new CommandListenerAdapter());
87
+        uut.push(child2, new CommandListenerAdapter());
88
+        uut.animateSetRoot(child3, new CommandListenerAdapter() {
89
+            @Override
90
+            public void onSuccess(String childId) {
91
+                assertContainsOnlyId(child3.getId());
92
+            }
93
+        });
94
+    }
95
+
96
+    @Test
97
+    public void setRoot() {
98
+        assertThat(uut.isEmpty()).isTrue();
99
+        uut.push(child1, new CommandListenerAdapter());
100
+        uut.push(child2, new CommandListenerAdapter());
101
+        uut.setRoot(child3, new CommandListenerAdapter() {
102
+            @Override
103
+            public void onSuccess(String childId) {
104
+                assertContainsOnlyId(child3.getId());
105
+            }
106
+        });
107
+    }
108
+
82
     @Test
109
     @Test
83
     public void pop() {
110
     public void pop() {
84
-        uut.animatePush(child1, new MockPromise());
85
-        uut.animatePush(child2, new MockPromise() {
111
+        uut.animatePush(child1, new CommandListenerAdapter());
112
+        uut.animatePush(child2, new CommandListenerAdapter() {
86
             @Override
113
             @Override
87
-            public void resolve(@Nullable Object value) {
114
+            public void onSuccess(String childId) {
88
                 assertContainsOnlyId(child2.getId(), child1.getId());
115
                 assertContainsOnlyId(child2.getId(), child1.getId());
89
                 uut.pop(new MockPromise());
116
                 uut.pop(new MockPromise());
90
                 assertContainsOnlyId(child1.getId());
117
                 assertContainsOnlyId(child1.getId());
94
 
121
 
95
     @Test
122
     @Test
96
     public void pop_appliesOptionsAfterPop() {
123
     public void pop_appliesOptionsAfterPop() {
97
-        uut.animatePush(child1, new MockPromise());
98
-        uut.animatePush(child2, new MockPromise() {
124
+        uut.animatePush(child1, new CommandListenerAdapter());
125
+        uut.animatePush(child2, new CommandListenerAdapter() {
99
             @Override
126
             @Override
100
-            public void resolve(@Nullable Object value) {
127
+            public void onSuccess(String childId) {
101
                 uut.pop(new MockPromise());
128
                 uut.pop(new MockPromise());
102
                 verify(uut, times(1)).applyChildOptions(uut.options, eq((ReactComponent) child1.getView()));
129
                 verify(uut, times(1)).applyChildOptions(uut.options, eq((ReactComponent) child1.getView()));
103
             }
130
             }
107
     @Test
134
     @Test
108
     public void pop_layoutHandlesChildWillDisappear() {
135
     public void pop_layoutHandlesChildWillDisappear() {
109
         final StackLayout[] stackLayout = new StackLayout[1];
136
         final StackLayout[] stackLayout = new StackLayout[1];
110
-        uut = new StackController(activity, new TopBarButtonCreatorMock(), new TitleBarReactViewCreatorMock(), new TopBarBackgroundViewController(activity, new TopBarBackgroundViewCreatorMock()), new TopBarController(), "uut", new Options()) {
111
-            @NonNull
112
-            @Override
113
-            protected StackLayout createView() {
114
-                stackLayout[0] = spy(super.createView());
115
-                return stackLayout[0];
116
-            }
117
-        };
118
-        uut.push(child1, new MockPromise());
119
-        uut.animatePush(child2, new MockPromise() {
137
+        uut =
138
+                new StackController(activity, new TopBarButtonCreatorMock(), new TitleBarReactViewCreatorMock(), new TopBarBackgroundViewController(activity, new TopBarBackgroundViewCreatorMock()), new TopBarController(), "uut", new Options()) {
139
+                    @NonNull
140
+                    @Override
141
+                    protected StackLayout createView() {
142
+                        stackLayout[0] = spy(super.createView());
143
+                        return stackLayout[0];
144
+                    }
145
+                };
146
+        uut.push(child1, new CommandListenerAdapter());
147
+        uut.animatePush(child2, new CommandListenerAdapter() {
120
             @Override
148
             @Override
121
-            public void resolve(@Nullable Object value) {
149
+            public void onSuccess(String childId) {
122
                 uut.animatePop(new MockPromise() {
150
                 uut.animatePop(new MockPromise() {
123
                     @Override
151
                     @Override
124
                     public void resolve(@Nullable Object value) {
152
                     public void resolve(@Nullable Object value) {
135
         assertThat(uut.peek()).isNull();
163
         assertThat(uut.peek()).isNull();
136
         assertThat(uut.size()).isZero();
164
         assertThat(uut.size()).isZero();
137
         assertThat(uut.isEmpty()).isTrue();
165
         assertThat(uut.isEmpty()).isTrue();
138
-        uut.animatePush(child1, new MockPromise());
166
+        uut.animatePush(child1, new CommandListenerAdapter());
139
         assertThat(uut.peek()).isEqualTo(child1);
167
         assertThat(uut.peek()).isEqualTo(child1);
140
         assertThat(uut.size()).isEqualTo(1);
168
         assertThat(uut.size()).isEqualTo(1);
141
         assertThat(uut.isEmpty()).isFalse();
169
         assertThat(uut.isEmpty()).isFalse();
144
     @Test
172
     @Test
145
     public void pushAssignsRefToSelfOnPushedController() {
173
     public void pushAssignsRefToSelfOnPushedController() {
146
         assertThat(child1.getParentController()).isNull();
174
         assertThat(child1.getParentController()).isNull();
147
-        uut.animatePush(child1, new MockPromise());
175
+        uut.animatePush(child1, new CommandListenerAdapter());
148
         assertThat(child1.getParentController()).isEqualTo(uut);
176
         assertThat(child1.getParentController()).isEqualTo(uut);
149
 
177
 
150
         StackController anotherNavController = createStackController("another");
178
         StackController anotherNavController = createStackController("another");
151
-        anotherNavController.animatePush(child2, new MockPromise());
179
+        anotherNavController.animatePush(child2, new CommandListenerAdapter());
152
         assertThat(child2.getParentController()).isEqualTo(anotherNavController);
180
         assertThat(child2.getParentController()).isEqualTo(anotherNavController);
153
     }
181
     }
154
 
182
 
157
         assertThat(uut.isEmpty()).isTrue();
185
         assertThat(uut.isEmpty()).isTrue();
158
         assertThat(uut.handleBack()).isFalse();
186
         assertThat(uut.handleBack()).isFalse();
159
 
187
 
160
-        uut.animatePush(child1, new MockPromise());
188
+        uut.animatePush(child1, new CommandListenerAdapter());
161
         assertThat(uut.size()).isEqualTo(1);
189
         assertThat(uut.size()).isEqualTo(1);
162
         assertThat(uut.handleBack()).isFalse();
190
         assertThat(uut.handleBack()).isFalse();
163
 
191
 
164
-        uut.animatePush(child2, new MockPromise() {
192
+        uut.animatePush(child2, new CommandListenerAdapter() {
165
             @Override
193
             @Override
166
-            public void resolve(@Nullable Object value) {
194
+            public void onSuccess(String childId) {
167
                 assertThat(uut.size()).isEqualTo(2);
195
                 assertThat(uut.size()).isEqualTo(2);
168
                 assertThat(uut.handleBack()).isTrue();
196
                 assertThat(uut.handleBack()).isTrue();
169
 
197
 
179
         uut.pop(new MockPromise());
207
         uut.pop(new MockPromise());
180
         assertThat(uut.isEmpty()).isTrue();
208
         assertThat(uut.isEmpty()).isTrue();
181
 
209
 
182
-        uut.animatePush(child1, new MockPromise());
210
+        uut.animatePush(child1, new CommandListenerAdapter());
183
         uut.pop(new MockPromise());
211
         uut.pop(new MockPromise());
184
         assertContainsOnlyId(child1.getId());
212
         assertContainsOnlyId(child1.getId());
185
     }
213
     }
188
     public void canPopWhenSizeIsMoreThanOne() {
216
     public void canPopWhenSizeIsMoreThanOne() {
189
         assertThat(uut.isEmpty()).isTrue();
217
         assertThat(uut.isEmpty()).isTrue();
190
         assertThat(uut.canPop()).isFalse();
218
         assertThat(uut.canPop()).isFalse();
191
-        uut.animatePush(child1, new MockPromise());
219
+        uut.animatePush(child1, new CommandListenerAdapter());
192
         assertContainsOnlyId(child1.getId());
220
         assertContainsOnlyId(child1.getId());
193
         assertThat(uut.canPop()).isFalse();
221
         assertThat(uut.canPop()).isFalse();
194
-        uut.animatePush(child2, new MockPromise());
222
+        uut.animatePush(child2, new CommandListenerAdapter());
195
         assertContainsOnlyId(child1.getId(), child2.getId());
223
         assertContainsOnlyId(child1.getId(), child2.getId());
196
         assertThat(uut.canPop()).isTrue();
224
         assertThat(uut.canPop()).isTrue();
197
     }
225
     }
199
     @Test
227
     @Test
200
     public void pushAddsToViewTree() {
228
     public void pushAddsToViewTree() {
201
         assertThat(uut.getView().findViewById(child1.getView().getId())).isNull();
229
         assertThat(uut.getView().findViewById(child1.getView().getId())).isNull();
202
-        uut.animatePush(child1, new MockPromise());
230
+        uut.animatePush(child1, new CommandListenerAdapter());
203
         assertThat(uut.getView().findViewById(child1.getView().getId())).isNotNull();
231
         assertThat(uut.getView().findViewById(child1.getView().getId())).isNotNull();
204
     }
232
     }
205
 
233
 
206
     @Test
234
     @Test
207
     public void pushRemovesPreviousFromTree() {
235
     public void pushRemovesPreviousFromTree() {
208
         assertThat(uut.getView().findViewById(child1.getView().getId())).isNull();
236
         assertThat(uut.getView().findViewById(child1.getView().getId())).isNull();
209
-        uut.animatePush(child1, new MockPromise());
237
+        uut.animatePush(child1, new CommandListenerAdapter());
210
         assertThat(uut.getView().findViewById(child1.getView().getId())).isNotNull();
238
         assertThat(uut.getView().findViewById(child1.getView().getId())).isNotNull();
211
-        uut.animatePush(child2, new MockPromise() {
239
+        uut.animatePush(child2, new CommandListenerAdapter() {
212
             @Override
240
             @Override
213
-            public void resolve(@Nullable Object value) {
241
+            public void onSuccess(String childId) {
214
                 assertThat(uut.getView().findViewById(child1.getView().getId())).isNull();
242
                 assertThat(uut.getView().findViewById(child1.getView().getId())).isNull();
215
                 assertThat(uut.getView().findViewById(child2.getView().getId())).isNotNull();
243
                 assertThat(uut.getView().findViewById(child2.getView().getId())).isNotNull();
216
             }
244
             }
222
         final View child2View = child2.getView();
250
         final View child2View = child2.getView();
223
         final View child1View = child1.getView();
251
         final View child1View = child1.getView();
224
 
252
 
225
-        uut.animatePush(child1, new MockPromise());
226
-        uut.animatePush(child2, new MockPromise() {
253
+        uut.animatePush(child1, new CommandListenerAdapter());
254
+        uut.animatePush(child2, new CommandListenerAdapter() {
227
             @Override
255
             @Override
228
-            public void resolve(@Nullable Object value) {
256
+            public void onSuccess(String childId) {
229
                 assertIsChildById(uut.getView(), child2View);
257
                 assertIsChildById(uut.getView(), child2View);
230
                 assertNotChildOf(uut.getView(), child1View);
258
                 assertNotChildOf(uut.getView(), child1View);
231
                 uut.pop(new MockPromise());
259
                 uut.pop(new MockPromise());
237
 
265
 
238
     @Test
266
     @Test
239
     public void popSpecificWhenTopIsRegularPop() {
267
     public void popSpecificWhenTopIsRegularPop() {
240
-        uut.animatePush(child1, new MockPromise());
241
-        uut.animatePush(child2, new MockPromise() {
268
+        uut.animatePush(child1, new CommandListenerAdapter());
269
+        uut.animatePush(child2, new CommandListenerAdapter() {
242
             @Override
270
             @Override
243
-            public void resolve(@Nullable Object value) {
271
+            public void onSuccess(String childId) {
244
                 uut.popSpecific(child2, new MockPromise() {
272
                 uut.popSpecific(child2, new MockPromise() {
245
                     @Override
273
                     @Override
246
                     public void resolve(@Nullable Object value) {
274
                     public void resolve(@Nullable Object value) {
254
 
282
 
255
     @Test
283
     @Test
256
     public void popSpecificDeepInStack() {
284
     public void popSpecificDeepInStack() {
257
-        uut.animatePush(child1, new MockPromise());
258
-        uut.animatePush(child2, new MockPromise());
285
+        uut.animatePush(child1, new CommandListenerAdapter());
286
+        uut.animatePush(child2, new CommandListenerAdapter());
259
         assertIsChildById(uut.getView(), child2.getView());
287
         assertIsChildById(uut.getView(), child2.getView());
260
         uut.popSpecific(child1, new MockPromise());
288
         uut.popSpecific(child1, new MockPromise());
261
         assertContainsOnlyId(child2.getId());
289
         assertContainsOnlyId(child2.getId());
264
 
292
 
265
     @Test
293
     @Test
266
     public void popTo_PopsTopUntilControllerIsNewTop() {
294
     public void popTo_PopsTopUntilControllerIsNewTop() {
267
-        uut.animatePush(child1, new MockPromise());
268
-        uut.animatePush(child2, new MockPromise());
269
-        uut.animatePush(child3, new MockPromise() {
295
+        uut.animatePush(child1, new CommandListenerAdapter());
296
+        uut.animatePush(child2, new CommandListenerAdapter());
297
+        uut.animatePush(child3, new CommandListenerAdapter() {
270
             @Override
298
             @Override
271
-            public void resolve(@Nullable Object value) {
299
+            public void onSuccess(String childId) {
272
                 assertThat(uut.size()).isEqualTo(3);
300
                 assertThat(uut.size()).isEqualTo(3);
273
                 assertThat(uut.peek()).isEqualTo(child3);
301
                 assertThat(uut.peek()).isEqualTo(child3);
274
 
302
 
282
 
310
 
283
     @Test
311
     @Test
284
     public void popTo_NotAChildOfThisStack_DoesNothing() {
312
     public void popTo_NotAChildOfThisStack_DoesNothing() {
285
-        uut.animatePush(child1, new MockPromise());
286
-        uut.animatePush(child3, new MockPromise());
313
+        uut.animatePush(child1, new CommandListenerAdapter());
314
+        uut.animatePush(child3, new CommandListenerAdapter());
287
         assertThat(uut.size()).isEqualTo(2);
315
         assertThat(uut.size()).isEqualTo(2);
288
         uut.popTo(child2, new MockPromise());
316
         uut.popTo(child2, new MockPromise());
289
         assertThat(uut.size()).isEqualTo(2);
317
         assertThat(uut.size()).isEqualTo(2);
291
 
319
 
292
     @Test
320
     @Test
293
     public void popToRoot_PopsEverythingAboveFirstController() {
321
     public void popToRoot_PopsEverythingAboveFirstController() {
294
-        uut.animatePush(child1, new MockPromise());
295
-        uut.animatePush(child2, new MockPromise());
296
-        uut.animatePush(child3, new MockPromise() {
322
+        uut.animatePush(child1, new CommandListenerAdapter());
323
+        uut.animatePush(child2, new CommandListenerAdapter());
324
+        uut.animatePush(child3, new CommandListenerAdapter() {
297
             @Override
325
             @Override
298
-            public void resolve(@Nullable Object value) {
326
+            public void onSuccess(String childId) {
299
                 assertThat(uut.size()).isEqualTo(3);
327
                 assertThat(uut.size()).isEqualTo(3);
300
                 assertThat(uut.peek()).isEqualTo(child3);
328
                 assertThat(uut.peek()).isEqualTo(child3);
301
 
329
 
321
     public void findControllerById_ReturnsSelfOrChildrenById() {
349
     public void findControllerById_ReturnsSelfOrChildrenById() {
322
         assertThat(uut.findControllerById("123")).isNull();
350
         assertThat(uut.findControllerById("123")).isNull();
323
         assertThat(uut.findControllerById(uut.getId())).isEqualTo(uut);
351
         assertThat(uut.findControllerById(uut.getId())).isEqualTo(uut);
324
-        uut.animatePush(child1, new MockPromise());
352
+        uut.animatePush(child1, new CommandListenerAdapter());
325
         assertThat(uut.findControllerById(child1.getId())).isEqualTo(child1);
353
         assertThat(uut.findControllerById(child1.getId())).isEqualTo(child1);
326
     }
354
     }
327
 
355
 
328
     @Test
356
     @Test
329
     public void findControllerById_Deeply() {
357
     public void findControllerById_Deeply() {
330
         StackController stack = createStackController("another");
358
         StackController stack = createStackController("another");
331
-        stack.animatePush(child2, new MockPromise());
332
-        uut.animatePush(stack, new MockPromise());
359
+        stack.animatePush(child2, new CommandListenerAdapter());
360
+        uut.animatePush(stack, new CommandListenerAdapter());
333
         assertThat(uut.findControllerById(child2.getId())).isEqualTo(child2);
361
         assertThat(uut.findControllerById(child2.getId())).isEqualTo(child2);
334
     }
362
     }
335
 
363
 
338
         child1 = spy(child1);
366
         child1 = spy(child1);
339
         child2 = spy(child2);
367
         child2 = spy(child2);
340
         child3 = spy(child3);
368
         child3 = spy(child3);
341
-        uut.animatePush(child1, new MockPromise());
342
-        uut.animatePush(child2, new MockPromise());
343
-        uut.animatePush(child3, new MockPromise() {
369
+        uut.animatePush(child1, new CommandListenerAdapter());
370
+        uut.animatePush(child2, new CommandListenerAdapter());
371
+        uut.animatePush(child3, new CommandListenerAdapter() {
344
             @Override
372
             @Override
345
-            public void resolve(@Nullable Object value) {
373
+            public void onSuccess(String childId) {
346
                 verify(child3, times(0)).destroy();
374
                 verify(child3, times(0)).destroy();
347
                 uut.pop(new MockPromise());
375
                 uut.pop(new MockPromise());
348
                 verify(child3, times(1)).destroy();
376
                 verify(child3, times(1)).destroy();
354
     public void pop_callWillAppearWillDisappear() {
382
     public void pop_callWillAppearWillDisappear() {
355
         child1 = spy(child1);
383
         child1 = spy(child1);
356
         child2 = spy(child2);
384
         child2 = spy(child2);
357
-        uut.push(child1, new MockPromise());
358
-        uut.push(child2, new MockPromise());
385
+        uut.push(child1, new CommandListenerAdapter());
386
+        uut.push(child2, new CommandListenerAdapter());
359
         uut.pop(new MockPromise());
387
         uut.pop(new MockPromise());
360
         verify(child1, times(1)).onViewWillAppear();
388
         verify(child1, times(1)).onViewWillAppear();
361
         verify(child2, times(1)).onViewWillDisappear();
389
         verify(child2, times(1)).onViewWillDisappear();
368
         child1.options.topBarOptions.visible = new Bool(false);
396
         child1.options.topBarOptions.visible = new Bool(false);
369
         child1.options.topBarOptions.animate = new Bool(false);
397
         child1.options.topBarOptions.animate = new Bool(false);
370
         child2.options.topBarOptions.visible = new Bool(true);
398
         child2.options.topBarOptions.visible = new Bool(true);
371
-        uut.push(child1, new MockPromise());
399
+        uut.push(child1, new CommandListenerAdapter());
372
         child1.onViewAppeared();
400
         child1.onViewAppeared();
373
 
401
 
374
         assertThat(uut.getTopBar().getVisibility()).isEqualTo(View.GONE);
402
         assertThat(uut.getTopBar().getVisibility()).isEqualTo(View.GONE);
375
-        uut.push(child2, new MockPromise());
403
+        uut.push(child2, new CommandListenerAdapter());
376
         uut.animatePop(new MockPromise() {
404
         uut.animatePop(new MockPromise() {
377
             @Override
405
             @Override
378
             public void resolve(@Nullable Object value) {
406
             public void resolve(@Nullable Object value) {
386
         child1 = spy(child1);
414
         child1 = spy(child1);
387
         child2 = spy(child2);
415
         child2 = spy(child2);
388
         child3 = spy(child3);
416
         child3 = spy(child3);
389
-        uut.animatePush(child1, new MockPromise());
390
-        uut.animatePush(child2, new MockPromise());
391
-        uut.animatePush(child3, new MockPromise());
417
+        uut.animatePush(child1, new CommandListenerAdapter());
418
+        uut.animatePush(child2, new CommandListenerAdapter());
419
+        uut.animatePush(child3, new CommandListenerAdapter());
392
 
420
 
393
         verify(child2, times(0)).destroy();
421
         verify(child2, times(0)).destroy();
394
         uut.popSpecific(child2, new MockPromise());
422
         uut.popSpecific(child2, new MockPromise());
400
         child1 = spy(child1);
428
         child1 = spy(child1);
401
         child2 = spy(child2);
429
         child2 = spy(child2);
402
         child3 = spy(child3);
430
         child3 = spy(child3);
403
-        uut.animatePush(child1, new MockPromise());
404
-        uut.animatePush(child2, new MockPromise());
405
-        uut.animatePush(child3, new MockPromise() {
431
+        uut.animatePush(child1, new CommandListenerAdapter());
432
+        uut.animatePush(child2, new CommandListenerAdapter());
433
+        uut.animatePush(child3, new CommandListenerAdapter() {
406
             @Override
434
             @Override
407
-            public void resolve(@Nullable Object value) {
435
+            public void onSuccess(String childId) {
408
                 verify(child2, times(0)).destroy();
436
                 verify(child2, times(0)).destroy();
409
                 verify(child3, times(0)).destroy();
437
                 verify(child3, times(0)).destroy();
410
 
438
 
423
     public void stackCanBePushed() {
451
     public void stackCanBePushed() {
424
         StackController parent = createStackController("someStack");
452
         StackController parent = createStackController("someStack");
425
         parent.ensureViewIsCreated();
453
         parent.ensureViewIsCreated();
426
-        parent.push(uut, new MockPromise());
454
+        parent.push(uut, new CommandListenerAdapter());
427
         uut.onViewAppeared();
455
         uut.onViewAppeared();
428
         assertThat(parent.getView().getChildAt(1)).isEqualTo(uut.getView());
456
         assertThat(parent.getView().getChildAt(1)).isEqualTo(uut.getView());
429
     }
457
     }
432
     public void applyOptions_applyOnlyOnFirstStack() {
460
     public void applyOptions_applyOnlyOnFirstStack() {
433
         StackController parent = spy(createStackController("someStack"));
461
         StackController parent = spy(createStackController("someStack"));
434
         parent.ensureViewIsCreated();
462
         parent.ensureViewIsCreated();
435
-        parent.push(uut, new MockPromise());
463
+        parent.push(uut, new CommandListenerAdapter());
436
 
464
 
437
         Options childOptions = new Options();
465
         Options childOptions = new Options();
438
         childOptions.topBarOptions.title.text = new Text("Something");
466
         childOptions.topBarOptions.title.text = new Text("Something");
439
         child1.options = childOptions;
467
         child1.options = childOptions;
440
-        uut.push(child1, new MockPromise());
468
+        uut.push(child1, new CommandListenerAdapter());
441
         child1.ensureViewIsCreated();
469
         child1.ensureViewIsCreated();
442
         child1.onViewAppeared();
470
         child1.onViewAppeared();
443
 
471
 
450
     @Test
478
     @Test
451
     public void applyOptions_topTabsAreNotVisibleIfNoTabsAreDefined() {
479
     public void applyOptions_topTabsAreNotVisibleIfNoTabsAreDefined() {
452
         uut.ensureViewIsCreated();
480
         uut.ensureViewIsCreated();
453
-        uut.push(child1, new MockPromise());
481
+        uut.push(child1, new CommandListenerAdapter());
454
         child1.ensureViewIsCreated();
482
         child1.ensureViewIsCreated();
455
         child1.onViewAppeared();
483
         child1.onViewAppeared();
456
         assertThat(ViewHelper.isVisible(uut.getTopBar().getTopTabs())).isFalse();
484
         assertThat(ViewHelper.isVisible(uut.getTopBar().getTopTabs())).isFalse();
459
     @Test
487
     @Test
460
     public void buttonPressInvokedOnCurrentStack() {
488
     public void buttonPressInvokedOnCurrentStack() {
461
         uut.ensureViewIsCreated();
489
         uut.ensureViewIsCreated();
462
-        uut.push(child1, new MockPromise());
490
+        uut.push(child1, new CommandListenerAdapter());
463
         uut.sendOnNavigationButtonPressed("btn1");
491
         uut.sendOnNavigationButtonPressed("btn1");
464
         verify(child1, times(1)).sendOnNavigationButtonPressed("btn1");
492
         verify(child1, times(1)).sendOnNavigationButtonPressed("btn1");
465
     }
493
     }
467
     @Test
495
     @Test
468
     public void mergeChildOptions_updatesViewWithNewOptions() {
496
     public void mergeChildOptions_updatesViewWithNewOptions() {
469
         final StackLayout[] stackLayout = new StackLayout[1];
497
         final StackLayout[] stackLayout = new StackLayout[1];
470
-        StackController uut = new StackController(activity, new TopBarButtonCreatorMock(), new TitleBarReactViewCreatorMock(), new TopBarBackgroundViewController(activity, new TopBarBackgroundViewCreatorMock()), new TopBarController(), "stack", new Options()) {
471
-            @NonNull
472
-            @Override
473
-            protected StackLayout createView() {
474
-                stackLayout[0] = spy(super.createView());
475
-                return stackLayout[0];
476
-            }
477
-        };
498
+        StackController uut =
499
+                new StackController(activity, new TopBarButtonCreatorMock(), new TitleBarReactViewCreatorMock(), new TopBarBackgroundViewController(activity, new TopBarBackgroundViewCreatorMock()), new TopBarController(), "stack", new Options()) {
500
+                    @NonNull
501
+                    @Override
502
+                    protected StackLayout createView() {
503
+                        stackLayout[0] = spy(super.createView());
504
+                        return stackLayout[0];
505
+                    }
506
+                };
478
         Options optionsToMerge = new Options();
507
         Options optionsToMerge = new Options();
479
         Component component = mock(Component.class);
508
         Component component = mock(Component.class);
480
         uut.mergeChildOptions(optionsToMerge, component);
509
         uut.mergeChildOptions(optionsToMerge, component);
484
     @Test
513
     @Test
485
     public void mergeChildOptions_updatesParentControllerWithNewOptions() {
514
     public void mergeChildOptions_updatesParentControllerWithNewOptions() {
486
         final StackLayout[] stackLayout = new StackLayout[1];
515
         final StackLayout[] stackLayout = new StackLayout[1];
487
-        StackController uut = new StackController(activity, new TopBarButtonCreatorMock(), new TitleBarReactViewCreatorMock(), new TopBarBackgroundViewController(activity, new TopBarBackgroundViewCreatorMock()), new TopBarController(), "stack", new Options()) {
488
-            @NonNull
489
-            @Override
490
-            protected StackLayout createView() {
491
-                stackLayout[0] = spy(super.createView());
492
-                return stackLayout[0];
493
-            }
494
-        };
516
+        StackController uut =
517
+                new StackController(activity, new TopBarButtonCreatorMock(), new TitleBarReactViewCreatorMock(), new TopBarBackgroundViewController(activity, new TopBarBackgroundViewCreatorMock()), new TopBarController(), "stack", new Options()) {
518
+                    @NonNull
519
+                    @Override
520
+                    protected StackLayout createView() {
521
+                        stackLayout[0] = spy(super.createView());
522
+                        return stackLayout[0];
523
+                    }
524
+                };
495
         ParentController parentController = Mockito.mock(ParentController.class);
525
         ParentController parentController = Mockito.mock(ParentController.class);
496
         uut.setParentController(parentController);
526
         uut.setParentController(parentController);
497
         Options optionsToMerge = new Options();
527
         Options optionsToMerge = new Options();

+ 3
- 3
lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/TopTabsViewControllerTest.java Прегледај датотеку

65
         tabControllers.forEach(viewController -> viewController.setParentController(uut));
65
         tabControllers.forEach(viewController -> viewController.setParentController(uut));
66
 
66
 
67
         parentController = spy(createStackController("stackId"));
67
         parentController = spy(createStackController("stackId"));
68
-        parentController.push(uut, new MockPromise());
68
+        parentController.push(uut);
69
         uut.setParentController(parentController);
69
         uut.setParentController(parentController);
70
     }
70
     }
71
 
71
 
232
                 new TestComponentViewCreator(),
232
                 new TestComponentViewCreator(),
233
                 new Options()
233
                 new Options()
234
         );
234
         );
235
-        stackController.push(first, new MockPromise());
236
-        stackController.push(uut, new MockPromise());
235
+        stackController.push(first);
236
+        stackController.push(uut);
237
 
237
 
238
         first.ensureViewIsCreated();
238
         first.ensureViewIsCreated();
239
         uut.ensureViewIsCreated();
239
         uut.ensureViewIsCreated();

+ 2
- 2
lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/ViewControllerTest.java Прегледај датотеку

7
 import android.widget.LinearLayout;
7
 import android.widget.LinearLayout;
8
 
8
 
9
 import com.reactnativenavigation.BaseTest;
9
 import com.reactnativenavigation.BaseTest;
10
-import com.reactnativenavigation.mocks.MockPromise;
11
 import com.reactnativenavigation.mocks.SimpleViewController;
10
 import com.reactnativenavigation.mocks.SimpleViewController;
12
 import com.reactnativenavigation.mocks.TitleBarReactViewCreatorMock;
11
 import com.reactnativenavigation.mocks.TitleBarReactViewCreatorMock;
13
 import com.reactnativenavigation.mocks.TopBarBackgroundViewCreatorMock;
12
 import com.reactnativenavigation.mocks.TopBarBackgroundViewCreatorMock;
14
 import com.reactnativenavigation.mocks.TopBarButtonCreatorMock;
13
 import com.reactnativenavigation.mocks.TopBarButtonCreatorMock;
15
 import com.reactnativenavigation.parse.Options;
14
 import com.reactnativenavigation.parse.Options;
15
+import com.reactnativenavigation.utils.CommandListenerAdapter;
16
 import com.reactnativenavigation.viewcontrollers.topbar.TopBarBackgroundViewController;
16
 import com.reactnativenavigation.viewcontrollers.topbar.TopBarBackgroundViewController;
17
 import com.reactnativenavigation.viewcontrollers.topbar.TopBarController;
17
 import com.reactnativenavigation.viewcontrollers.topbar.TopBarController;
18
 
18
 
71
     public void holdsAReferenceToStackControllerOrNull() {
71
     public void holdsAReferenceToStackControllerOrNull() {
72
         assertThat(uut.getParentController()).isNull();
72
         assertThat(uut.getParentController()).isNull();
73
         StackController nav = new StackController(activity, new TopBarButtonCreatorMock(), new TitleBarReactViewCreatorMock(), new TopBarBackgroundViewController(activity, new TopBarBackgroundViewCreatorMock()), new TopBarController(), "stack", new Options());
73
         StackController nav = new StackController(activity, new TopBarButtonCreatorMock(), new TitleBarReactViewCreatorMock(), new TopBarBackgroundViewController(activity, new TopBarBackgroundViewCreatorMock()), new TopBarController(), "stack", new Options());
74
-        nav.animatePush(uut, new MockPromise());
74
+        nav.animatePush(uut, new CommandListenerAdapter());
75
         assertThat(uut.getParentController()).isEqualTo(nav);
75
         assertThat(uut.getParentController()).isEqualTo(nav);
76
     }
76
     }
77
 
77