Bug 1356517 - Add tests for deep link. r?grisha
MozReview-Commit-ID: 1LMFBl8EGzW
--- a/mobile/android/base/java/org/mozilla/gecko/deeplink/DeepLinkStore.java
+++ b/mobile/android/base/java/org/mozilla/gecko/deeplink/DeepLinkStore.java
@@ -46,9 +46,14 @@ final public class DeepLinkStore {
}
}
if (removing != null) {
queue.remove(removing);
}
}
}
+
+ public static void clear() {
+ queue.clear();
+ reducers.clear();
+ }
}
\ No newline at end of file
--- a/mobile/android/tests/background/junit4/src/org/mozilla/gecko/deeplink/DeepLinkStoreTest.java
+++ b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/deeplink/DeepLinkStoreTest.java
@@ -1,10 +1,11 @@
package org.mozilla.gecko.deeplink;
+import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mozilla.gecko.background.testhelpers.TestRunner;
import static org.mockito.Mockito.atLeastOnce;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
@@ -17,24 +18,59 @@ public class DeepLinkStoreTest {
DeepLinkListener listener;
@Before
public void setUp() throws Exception {
listener = mock(DeepLinkListener.class);
}
@Test
- public void testRegisterSuccess() {
+ public void testRegisterBeforeAction() {
DeepLinkStore.register(DeepLinkAction.TYPE.DEFAULT_BROWSER, listener);
DeepLinkAction action = new DeepLinkAction(DeepLinkAction.TYPE.DEFAULT_BROWSER, "");
DeepLinkStore.dispatch(action);
verify(listener, atLeastOnce()).execute(action);
}
@Test
+ public void testReducerNeverCame() {
+ DeepLinkAction action = new DeepLinkAction(DeepLinkAction.TYPE.DEFAULT_BROWSER, "");
+ DeepLinkStore.dispatch(action);
+ DeepLinkStore.register(DeepLinkAction.TYPE.DEFAULT_BROWSER, listener);
+
+ verify(listener, atLeastOnce()).execute(action);
+ }
+
+ @Test
+ public void testReducerCameLater() {
+ DeepLinkAction action = new DeepLinkAction(DeepLinkAction.TYPE.DEFAULT_BROWSER, "");
+ DeepLinkStore.dispatch(action);
+ DeepLinkStore.register(DeepLinkAction.TYPE.DEFAULT_BROWSER, listener);
+
+ verify(listener, atLeastOnce()).execute(action);
+ }
+
+ @Test
+ public void testMultiActionShouldWork() {
+ DeepLinkAction action1 = new DeepLinkAction(DeepLinkAction.TYPE.DEFAULT_BROWSER, "");
+ DeepLinkAction action2 = new DeepLinkAction(DeepLinkAction.TYPE.DEFAULT_BROWSER, "");
+ DeepLinkStore.dispatch(action1);
+ DeepLinkStore.dispatch(action2);
+ DeepLinkStore.register(DeepLinkAction.TYPE.DEFAULT_BROWSER, listener);
+
+ verify(listener, times(1)).execute(action1);
+ verify(listener, times(1)).execute(action2);
+ }
+
+ @Test
public void testRegisterFailed() {
DeepLinkStore.register(DeepLinkAction.TYPE.DEFAULT_BROWSER, listener);
DeepLinkAction action = new DeepLinkAction(DeepLinkAction.TYPE.SIGN_UP, "");
DeepLinkStore.dispatch(action);
verify(listener, never()).execute(action);
}
+ @After
+ public void tearDown() throws Exception {
+ DeepLinkStore.clear();
+ }
+
}