Bug 1207714 - Pre: Expose synchronous executor to product code. r=rnewman
authorNick Alexander <nalexander@mozilla.com>
Thu, 25 Feb 2016 09:30:28 -0800
changeset 322950 be96c33be89b0e88259926b25295ff9e898dc25d
parent 322949 b7606518d932b45aeea57824effaa31a81d15336
child 322951 ed7d80c104347dcc4fca943c8187909c8d61b43b
push id5913
push userjlund@mozilla.com
push dateMon, 25 Apr 2016 16:57:49 +0000
treeherdermozilla-beta@dcaf0a6fa115 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersrnewman
bugs1207714
milestone47.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
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());