Bug 1356517 - Add tests for deep link. r?grisha draft
authorNevin Chen <cnevinchen@gmail.com>
Mon, 24 Apr 2017 07:50:42 +0800
changeset 566915 ef8a4d00b0d89e19abafb5feb16fde77e51bda0d
parent 566914 1c90e81edd107cd75c2b89b3da358bf6fe1211be
child 567022 ab9104a8a7adabd6e5740c7ac1238dff5f40de9c
push id55378
push userbmo:cnevinchen@gmail.com
push dateMon, 24 Apr 2017 06:01:29 +0000
reviewersgrisha
bugs1356517
milestone55.0a1
Bug 1356517 - Add tests for deep link. r?grisha MozReview-Commit-ID: 1LMFBl8EGzW
mobile/android/base/java/org/mozilla/gecko/deeplink/DeepLinkStore.java
mobile/android/tests/background/junit4/src/org/mozilla/gecko/deeplink/DeepLinkStoreTest.java
--- 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();
+    }
+
 }