Bug 1207714 - Pre: Expose synchronous executor to product code. r=rnewman draft
authorNick Alexander <nalexander@mozilla.com>
Thu, 25 Feb 2016 09:30:28 -0800
changeset 336292 3bd81e142b1733953bfd07bffc1de0293d1f4c00
parent 336291 17c38c9397ec8874760fe32f383d1ba7c9ff0940
child 336293 aa358e6914932fd7372e56703a53797336633093
push id12029
push usernalexander@mozilla.com
push dateThu, 03 Mar 2016 00:10:36 +0000
reviewersrnewman
bugs1207714
milestone47.0a1
Bug 1207714 - Pre: Expose synchronous executor to product code. r=rnewman MozReview-Commit-ID: 3eDVh0nk7Nc
mobile/android/services/src/main/java/org/mozilla/gecko/sync/Utils.java
mobile/android/tests/background/junit4/src/org/mozilla/gecko/background/testhelpers/WaitHelper.java
mobile/android/tests/background/junit4/src/org/mozilla/gecko/push/autopush/test/TestAutopushClient.java
mobile/android/tests/background/junit4/src/org/mozilla/gecko/push/autopush/test/TestLiveAutopushClient.java
--- a/mobile/android/services/src/main/java/org/mozilla/gecko/sync/Utils.java
+++ b/mobile/android/services/src/main/java/org/mozilla/gecko/sync/Utils.java
@@ -18,16 +18,17 @@ import java.security.SecureRandom;
 import java.text.DecimalFormat;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Locale;
 import java.util.Map;
 import java.util.TreeMap;
+import java.util.concurrent.Executor;
 
 import org.json.simple.JSONArray;
 import org.mozilla.apache.commons.codec.binary.Base32;
 import org.mozilla.apache.commons.codec.binary.Base64;
 import org.mozilla.gecko.background.common.log.Logger;
 import org.mozilla.gecko.background.nativecode.NativeCrypto;
 import org.mozilla.gecko.sync.setup.Constants;
 
@@ -557,9 +558,18 @@ public class Utils {
 
   public static void throwIfNull(Object... objects) {
     for (Object object : objects) {
       if (object == null) {
         throw new IllegalArgumentException("object must not be null");
       }
     }
   }
+
+  public static Executor newSynchronousExecutor() {
+    return new Executor() {
+      @Override
+      public void execute(Runnable runnable) {
+        runnable.run();
+      }
+    };
+  }
 }
--- a/mobile/android/tests/background/junit4/src/org/mozilla/gecko/background/testhelpers/WaitHelper.java
+++ b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/background/testhelpers/WaitHelper.java
@@ -164,19 +164,9 @@ public class WaitHelper {
 
   public static void resetTestWaiter() {
     singleWaiter = new WaitHelper();
   }
 
   public boolean isIdle() {
     return queue.isEmpty();
   }
-
-  public static Executor newSynchronousExecutor() {
-    return new Executor() {
-
-      @Override
-      public void execute(Runnable runnable) {
-        runnable.run();
-      }
-    };
-  }
 }
--- a/mobile/android/tests/background/junit4/src/org/mozilla/gecko/push/autopush/test/TestAutopushClient.java
+++ b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/push/autopush/test/TestAutopushClient.java
@@ -5,25 +5,26 @@ package org.mozilla.gecko.push.autopush.
 
 import org.junit.Assert;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.mozilla.gecko.background.testhelpers.TestRunner;
 import org.mozilla.gecko.background.testhelpers.WaitHelper;
 import org.mozilla.gecko.push.autopush.AutopushClient;
 import org.mozilla.gecko.push.autopush.AutopushClientException;
+import org.mozilla.gecko.sync.Utils;
 
 @RunWith(TestRunner.class)
 public class TestAutopushClient {
     @Test
     public void testGetSenderID() throws Exception {
         final AutopushClient client = new AutopushClient("https://updates-autopush-dev.stage.mozaws.net/v1/gcm/829133274407",
-                WaitHelper.newSynchronousExecutor());
+                Utils.newSynchronousExecutor());
         Assert.assertEquals("829133274407", client.getSenderIDFromServerURI());
     }
 
     @Test(expected=AutopushClientException.class)
     public void testGetNoSenderID() throws Exception {
         final AutopushClient client = new AutopushClient("https://updates-autopush-dev.stage.mozaws.net/v1/gcm",
-                WaitHelper.newSynchronousExecutor());
+                Utils.newSynchronousExecutor());
         client.getSenderIDFromServerURI();
     }
 }
--- a/mobile/android/tests/background/junit4/src/org/mozilla/gecko/push/autopush/test/TestLiveAutopushClient.java
+++ b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/push/autopush/test/TestLiveAutopushClient.java
@@ -37,17 +37,17 @@ import static org.mockito.Mockito.verify
 public class TestLiveAutopushClient {
     final String serverURL = "https://updates-autopush-dev.stage.mozaws.net/v1/gcm/829133274407";
 
     protected AutopushClient client;
 
     @Before
     public void setUp() throws Exception {
         BaseResource.rewriteLocalhost = false;
-        client = new AutopushClient(serverURL, WaitHelper.newSynchronousExecutor());
+        client = new AutopushClient(serverURL, Utils.newSynchronousExecutor());
     }
 
     protected <T> T assertSuccess(RequestDelegate<T> delegate, Class<T> klass) {
         verify(delegate, never()).handleError(any(Exception.class));
         verify(delegate, never()).handleFailure(any(AutopushClientException.class));
 
         final ArgumentCaptor<T> register = ArgumentCaptor.forClass(klass);
         verify(delegate).handleSuccess(register.capture());