Update to using newer android.support.test libraries.

com.android.support.test:runner:1.0.0
com.android.support.test:rules:1.0.0
com.android.support.test.espresso:espresso-core:3.0.0
com.android.support.test.espresso:espresso-contrib:3.0.0

Additionally:
- removed the usage of internal espresso apis.
- fixed PostMessageTest that was using ServiceTestRule incorrectly.
- added workaround to AndroidManifest.xml for test packages that use
  mockito

Test: ./gradlew assembleAndroidTest works
Change-Id: I7a512e00844e9caefc5f26928f87c8441fc1289a
diff --git a/buildSrc/dependencies.gradle b/buildSrc/dependencies.gradle
index 53f0672..101d890 100644
--- a/buildSrc/dependencies.gradle
+++ b/buildSrc/dependencies.gradle
@@ -21,11 +21,11 @@
 libs.dexmaker_mockito = 'com.linkedin.dexmaker:dexmaker-mockito:2.2.0'
 libs.multidex = 'com.android.support:multidex:1.0.1'
 libs.junit = 'junit:junit:4.12'
-libs.test_runner = 'com.android.support.test:runner:0.6-alpha'
-libs.espresso_core = 'com.android.support.test.espresso:espresso-core:2.3-alpha'
-libs.espresso_contrib = 'com.android.support.test.espresso:espresso-contrib:2.3-alpha'
+libs.test_runner = 'com.android.support.test:runner:1.0.0'
+libs.espresso_core = 'com.android.support.test.espresso:espresso-core:3.0.0'
+libs.espresso_contrib = 'com.android.support.test.espresso:espresso-contrib:3.0.0'
 libs.jacoco = 'org.jacoco:org.jacoco.core:0.7.8'
-libs.test_rules = 'com.android.support.test:rules:0.6-alpha'
+libs.test_rules = 'com.android.support.test:rules:1.0.0'
 
 def androidPluginVersionOverride = System.getenv("GRADLE_PLUGIN_VERSION")
 
diff --git a/compat/tests/AndroidManifest.xml b/compat/tests/AndroidManifest.xml
index 4988845..7698fec 100644
--- a/compat/tests/AndroidManifest.xml
+++ b/compat/tests/AndroidManifest.xml
@@ -16,6 +16,15 @@
   -->
 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
           package="android.support.compat.test">
+    <!-- Workaround for the Android test runner + Mockito 2 bug -->
+    <!--suppress AndroidDomInspection -->
+    <instrumentation>
+        <!--suppress AndroidElementNotAllowed -->
+        <meta-data
+            android:name="notPackage"
+            android:value="net.bytebuddy" />
+    </instrumentation>
+
     <uses-sdk android:targetSdkVersion="${target-sdk-version}"/>
 
     <uses-permission android:name="android.permission.VIBRATE"/>
diff --git a/core-ui/tests/AndroidManifest.xml b/core-ui/tests/AndroidManifest.xml
index c1b1a75..a23d2f1 100644
--- a/core-ui/tests/AndroidManifest.xml
+++ b/core-ui/tests/AndroidManifest.xml
@@ -16,6 +16,15 @@
   -->
 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
           package="android.support.coreui.test">
+    <!-- Workaround for the Android test runner + Mockito 2 bug -->
+    <!--suppress AndroidDomInspection -->
+    <instrumentation>
+        <!--suppress AndroidElementNotAllowed -->
+        <meta-data
+            android:name="notPackage"
+            android:value="net.bytebuddy" />
+    </instrumentation>
+
     <uses-sdk android:targetSdkVersion="${target-sdk-version}"/>
 
     <uses-permission android:name="android.permission.VIBRATE"/>
diff --git a/core-utils/tests/AndroidManifest.xml b/core-utils/tests/AndroidManifest.xml
index e3d060c..743bcb0 100644
--- a/core-utils/tests/AndroidManifest.xml
+++ b/core-utils/tests/AndroidManifest.xml
@@ -16,6 +16,15 @@
   -->
 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
           package="android.support.coreutils.test">
+    <!-- Workaround for the Android test runner + Mockito 2 bug -->
+    <!--suppress AndroidDomInspection -->
+    <instrumentation>
+        <!--suppress AndroidElementNotAllowed -->
+        <meta-data
+            android:name="notPackage"
+            android:value="net.bytebuddy" />
+    </instrumentation>
+
     <uses-sdk android:targetSdkVersion="${target-sdk-version}"/>
 
     <uses-permission android:name="android.permission.VIBRATE"/>
diff --git a/customtabs/tests/src/android/support/customtabs/PostMessageTest.java b/customtabs/tests/src/android/support/customtabs/PostMessageTest.java
index e832b23..7e342b4 100644
--- a/customtabs/tests/src/android/support/customtabs/PostMessageTest.java
+++ b/customtabs/tests/src/android/support/customtabs/PostMessageTest.java
@@ -36,7 +36,6 @@
 import org.junit.Test;
 import org.junit.runner.RunWith;
 
-import java.util.concurrent.TimeoutException;
 import java.util.concurrent.atomic.AtomicBoolean;
 
 
@@ -50,8 +49,6 @@
 @SmallTest
 public class PostMessageTest {
     @Rule
-    public final ServiceTestRule mServiceRule;
-    @Rule
     public final ActivityTestRule<TestActivity> mActivityTestRule;
     private TestCustomTabsCallback mCallback;
     private Context mContext;
@@ -63,7 +60,6 @@
 
     public PostMessageTest() {
         mActivityTestRule = new ActivityTestRule<TestActivity>(TestActivity.class);
-        mServiceRule = new ServiceTestRule();
         mCustomTabsServiceConnected = new AtomicBoolean(false);
     }
 
@@ -80,9 +76,9 @@
                     postMessageServiceIntent.setClassName(
                             mContext.getPackageName(), PostMessageService.class.getName());
                     try {
-                        mServiceRule.bindService(postMessageServiceIntent,
+                        mContext.bindService(postMessageServiceIntent,
                                 mPostMessageServiceConnection, Context.BIND_AUTO_CREATE);
-                    } catch (TimeoutException e) {
+                    } catch (Exception e) {
                         fail();
                     }
                 }
@@ -117,9 +113,9 @@
         customTabsServiceIntent.setClassName(
                 mContext.getPackageName(), TestCustomTabsService.class.getName());
         try {
-            mServiceRule.bindService(customTabsServiceIntent,
+            mContext.bindService(customTabsServiceIntent,
                     mCustomTabsServiceConnection, Context.BIND_AUTO_CREATE);
-        } catch (TimeoutException e) {
+        } catch (Exception e) {
             fail();
         }
     }
diff --git a/design/tests/AndroidManifest.xml b/design/tests/AndroidManifest.xml
index d5dbf91..911ec50 100755
--- a/design/tests/AndroidManifest.xml
+++ b/design/tests/AndroidManifest.xml
@@ -16,6 +16,15 @@
   -->
 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
           package="android.support.design.test">
+    <!-- Workaround for the Android test runner + Mockito 2 bug -->
+    <!--suppress AndroidDomInspection -->
+    <instrumentation>
+        <!--suppress AndroidElementNotAllowed -->
+        <meta-data
+            android:name="notPackage"
+            android:value="net.bytebuddy" />
+    </instrumentation>
+
     <uses-sdk android:targetSdkVersion="${target-sdk-version}"/>
 
     <application
diff --git a/design/tests/src/android/support/design/widget/BottomSheetBehaviorTest.java b/design/tests/src/android/support/design/widget/BottomSheetBehaviorTest.java
index fbb44eb..4a27d0c 100644
--- a/design/tests/src/android/support/design/widget/BottomSheetBehaviorTest.java
+++ b/design/tests/src/android/support/design/widget/BottomSheetBehaviorTest.java
@@ -43,7 +43,6 @@
 import android.support.test.espresso.action.Swipe;
 import android.support.test.espresso.action.ViewActions;
 import android.support.test.espresso.assertion.ViewAssertions;
-import android.support.test.espresso.core.deps.guava.base.Preconditions;
 import android.support.test.espresso.matcher.ViewMatchers;
 import android.support.test.filters.LargeTest;
 import android.support.test.filters.MediumTest;
@@ -58,6 +57,7 @@
 
 import org.hamcrest.Matcher;
 import org.hamcrest.Matchers;
+import org.junit.Assert;
 import org.junit.Test;
 
 public class BottomSheetBehaviorTest extends
@@ -229,8 +229,8 @@
         }
 
         private static float[][] interpolate(float[] start, float[] end, int steps) {
-            Preconditions.checkElementIndex(1, start.length);
-            Preconditions.checkElementIndex(1, end.length);
+            Assert.assertTrue(1 < start.length);
+            Assert.assertTrue(1 < end.length);
             float[][] res = new float[steps][2];
             for(int i = 1; i < steps + 1; ++i) {
                 res[i - 1][0] = start[0] + (end[0] - start[0]) * (float)i / ((float)steps + 2.0F);
diff --git a/dynamic-animation/tests/AndroidManifest.xml b/dynamic-animation/tests/AndroidManifest.xml
index 79b4331..a67f2fb 100755
--- a/dynamic-animation/tests/AndroidManifest.xml
+++ b/dynamic-animation/tests/AndroidManifest.xml
@@ -16,6 +16,15 @@
   -->
 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
           package="android.support.animation.test">
+    <!-- Workaround for the Android test runner + Mockito 2 bug -->
+    <!--suppress AndroidDomInspection -->
+    <instrumentation>
+        <!--suppress AndroidElementNotAllowed -->
+        <meta-data
+            android:name="notPackage"
+            android:value="net.bytebuddy" />
+    </instrumentation>
+
     <uses-sdk android:targetSdkVersion="${target-sdk-version}"/>
 
     <application android:supportsRtl="true">
diff --git a/emoji/appcompat/build.gradle b/emoji/appcompat/build.gradle
index 5e9f83a..2e37619 100644
--- a/emoji/appcompat/build.gradle
+++ b/emoji/appcompat/build.gradle
@@ -20,15 +20,6 @@
     api fileTree(include: ['*.jar'], dir: 'libs')
     api project(':support-emoji')
     api project(':support-appcompat-v7')
-
-    androidTestImplementation (libs.test_runner) {
-        exclude module: 'support-annotations'
-    }
-    androidTestImplementation (libs.espresso_core) {
-        exclude module: 'support-annotations'
-    }
-    androidTestImplementation libs.mockito_core
-    androidTestImplementation libs.dexmaker_mockito
 }
 
 android {
diff --git a/fragment/tests/AndroidManifest.xml b/fragment/tests/AndroidManifest.xml
index e6a520e..e230374 100644
--- a/fragment/tests/AndroidManifest.xml
+++ b/fragment/tests/AndroidManifest.xml
@@ -16,6 +16,15 @@
   -->
 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
           package="android.support.fragment.test">
+    <!-- Workaround for the Android test runner + Mockito 2 bug -->
+    <!--suppress AndroidDomInspection -->
+    <instrumentation>
+        <!--suppress AndroidElementNotAllowed -->
+        <meta-data
+            android:name="notPackage"
+            android:value="net.bytebuddy" />
+    </instrumentation>
+
     <uses-sdk android:targetSdkVersion="${target-sdk-version}"/>
 
     <uses-permission android:name="android.permission.VIBRATE"/>
diff --git a/media-compat/tests/AndroidManifest.xml b/media-compat/tests/AndroidManifest.xml
index 6d9a4f6..7bc61d5 100644
--- a/media-compat/tests/AndroidManifest.xml
+++ b/media-compat/tests/AndroidManifest.xml
@@ -16,6 +16,15 @@
 -->
 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
           package="android.support.mediacompat.test">
+    <!-- Workaround for the Android test runner + Mockito 2 bug -->
+    <!--suppress AndroidDomInspection -->
+    <instrumentation>
+        <!--suppress AndroidElementNotAllowed -->
+        <meta-data
+            android:name="notPackage"
+            android:value="net.bytebuddy" />
+    </instrumentation>
+
     <uses-sdk android:targetSdkVersion="${target-sdk-version}"/>
 
     <application android:supportsRtl="true">
diff --git a/transition/tests/AndroidManifest.xml b/transition/tests/AndroidManifest.xml
index 35be32b..c6146d0 100755
--- a/transition/tests/AndroidManifest.xml
+++ b/transition/tests/AndroidManifest.xml
@@ -16,6 +16,15 @@
 -->
 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
           package="android.support.transition.test">
+    <!-- Workaround for the Android test runner + Mockito 2 bug -->
+    <!--suppress AndroidDomInspection -->
+    <instrumentation>
+        <!--suppress AndroidElementNotAllowed -->
+        <meta-data
+            android:name="notPackage"
+            android:value="net.bytebuddy" />
+    </instrumentation>
+
     <uses-sdk android:targetSdkVersion="${target-sdk-version}"/>
 
     <application
diff --git a/v13/tests/AndroidManifest.xml b/v13/tests/AndroidManifest.xml
index b2d04c9..d2633b4 100644
--- a/v13/tests/AndroidManifest.xml
+++ b/v13/tests/AndroidManifest.xml
@@ -16,6 +16,15 @@
   -->
 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
           package="android.support.v13.test">
+    <!-- Workaround for the Android test runner + Mockito 2 bug -->
+    <!--suppress AndroidDomInspection -->
+    <instrumentation>
+        <!--suppress AndroidElementNotAllowed -->
+        <meta-data
+            android:name="notPackage"
+            android:value="net.bytebuddy" />
+    </instrumentation>
+
     <uses-sdk android:targetSdkVersion="${target-sdk-version}"/>
 
     <application>
diff --git a/v17/leanback/tests/AndroidManifest.xml b/v17/leanback/tests/AndroidManifest.xml
index d719485..b2c2d39 100644
--- a/v17/leanback/tests/AndroidManifest.xml
+++ b/v17/leanback/tests/AndroidManifest.xml
@@ -15,6 +15,15 @@
 -->
 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
           package="android.support.v17.leanback.test">
+    <!-- Workaround for the Android test runner + Mockito 2 bug -->
+    <!--suppress AndroidDomInspection -->
+    <instrumentation>
+        <!--suppress AndroidElementNotAllowed -->
+        <meta-data
+            android:name="notPackage"
+            android:value="net.bytebuddy" />
+    </instrumentation>
+
     <uses-sdk android:targetSdkVersion="${target-sdk-version}"/>
 
     <application
diff --git a/v7/appcompat/tests/AndroidManifest.xml b/v7/appcompat/tests/AndroidManifest.xml
index abad7d6..605f3d5 100644
--- a/v7/appcompat/tests/AndroidManifest.xml
+++ b/v7/appcompat/tests/AndroidManifest.xml
@@ -16,6 +16,15 @@
   -->
 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
           package="android.support.v7.appcompat.test">
+    <!-- Workaround for the Android test runner + Mockito 2 bug -->
+    <!--suppress AndroidDomInspection -->
+    <instrumentation>
+        <!--suppress AndroidElementNotAllowed -->
+        <meta-data
+            android:name="notPackage"
+            android:value="net.bytebuddy" />
+    </instrumentation>
+
     <uses-sdk android:targetSdkVersion="${target-sdk-version}"/>
 
     <application
diff --git a/v7/preference/tests/AndroidManifest.xml b/v7/preference/tests/AndroidManifest.xml
index 34b8a72..fae7e55 100644
--- a/v7/preference/tests/AndroidManifest.xml
+++ b/v7/preference/tests/AndroidManifest.xml
@@ -16,5 +16,14 @@
 
 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
           package="android.support.v7.preference.tests">
+    <!-- Workaround for the Android test runner + Mockito 2 bug -->
+    <!--suppress AndroidDomInspection -->
+    <instrumentation>
+        <!--suppress AndroidElementNotAllowed -->
+        <meta-data
+            android:name="notPackage"
+            android:value="net.bytebuddy" />
+    </instrumentation>
+
     <uses-sdk android:targetSdkVersion="${target-sdk-version}"/>
 </manifest>
diff --git a/v7/preference/tests/src/android/support/v7/preference/tests/PreferenceDataStoreTest.java b/v7/preference/tests/src/android/support/v7/preference/tests/PreferenceDataStoreTest.java
index 8f9929e..beadb87 100644
--- a/v7/preference/tests/src/android/support/v7/preference/tests/PreferenceDataStoreTest.java
+++ b/v7/preference/tests/src/android/support/v7/preference/tests/PreferenceDataStoreTest.java
@@ -43,7 +43,6 @@
 import android.content.SharedPreferences;
 import android.support.test.InstrumentationRegistry;
 import android.support.test.annotation.UiThreadTest;
-import android.support.test.espresso.core.deps.guava.collect.ImmutableSet;
 import android.support.test.filters.SmallTest;
 import android.support.test.runner.AndroidJUnit4;
 import android.support.v7.preference.CheckBoxPreference;
@@ -58,6 +57,7 @@
 import org.junit.runner.RunWith;
 import org.mockito.Mockito;
 
+import java.util.Collections;
 import java.util.HashSet;
 import java.util.Set;
 
@@ -278,7 +278,7 @@
     }
 
     private void putStringSetTestCommon() {
-        Set<String> testSet = ImmutableSet.of(TEST_STR);
+        Set<String> testSet = Collections.singleton(TEST_STR);
 
         mPreference.putStringSet(testSet);
 
diff --git a/v7/preference/tests/src/android/support/v7/preference/tests/PreferencePersistTest.java b/v7/preference/tests/src/android/support/v7/preference/tests/PreferencePersistTest.java
index 536e2a7..13e317e 100644
--- a/v7/preference/tests/src/android/support/v7/preference/tests/PreferencePersistTest.java
+++ b/v7/preference/tests/src/android/support/v7/preference/tests/PreferencePersistTest.java
@@ -27,7 +27,6 @@
 import android.content.SharedPreferences;
 import android.support.test.InstrumentationRegistry;
 import android.support.test.annotation.UiThreadTest;
-import android.support.test.espresso.core.deps.guava.collect.ImmutableSet;
 import android.support.test.filters.SmallTest;
 import android.support.test.runner.AndroidJUnit4;
 import android.support.v7.preference.PreferenceManager;
@@ -38,6 +37,9 @@
 import org.junit.Test;
 import org.junit.runner.RunWith;
 
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashSet;
 import java.util.Set;
 
 /**
@@ -51,9 +53,11 @@
 
     private static final float FLOAT_PRECISION = 0.01f;
 
-    private static final Set<String> TEST_STR_SET = ImmutableSet.of("a", "b");
-    private static final Set<String> TEST_STR_SET2 = ImmutableSet.of("c", "d");
-    private static final Set<String> TEST_DEFAULT_STR_SET = ImmutableSet.of("e");
+    private static final String[] A_B = {"a", "b"};
+    private static final String[] C_D = {"c", "d"};
+    private static final Set<String> TEST_STR_SET = new HashSet<>(Arrays.asList(A_B));
+    private static final Set<String> TEST_STR_SET2 = new HashSet<>(Arrays.asList(C_D));
+    private static final Set<String> TEST_DEFAULT_STR_SET = Collections.singleton("e");
 
     private PreferenceWrapper mPreference;
     private SharedPreferences mSharedPref;
diff --git a/v7/recyclerview/tests/AndroidManifest.xml b/v7/recyclerview/tests/AndroidManifest.xml
index 3d10333..e11ef82 100644
--- a/v7/recyclerview/tests/AndroidManifest.xml
+++ b/v7/recyclerview/tests/AndroidManifest.xml
@@ -16,6 +16,15 @@
   -->
 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
           package="android.support.v7.recyclerview.test">
+    <!-- Workaround for the Android test runner + Mockito 2 bug -->
+    <!--suppress AndroidDomInspection -->
+    <instrumentation>
+        <!--suppress AndroidElementNotAllowed -->
+        <meta-data
+            android:name="notPackage"
+            android:value="net.bytebuddy" />
+    </instrumentation>
+
     <uses-sdk android:targetSdkVersion="${target-sdk-version}"/>
 
     <application android:supportsRtl="true">
diff --git a/wear/tests/AndroidManifest.xml b/wear/tests/AndroidManifest.xml
index 23d66f4d..00d3dd7 100644
--- a/wear/tests/AndroidManifest.xml
+++ b/wear/tests/AndroidManifest.xml
@@ -16,6 +16,15 @@
   -->
 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
           package="android.support.wear.test">
+    <!-- Workaround for the Android test runner + Mockito 2 bug -->
+    <!--suppress AndroidDomInspection -->
+    <instrumentation>
+        <!--suppress AndroidElementNotAllowed -->
+        <meta-data
+            android:name="notPackage"
+            android:value="net.bytebuddy" />
+    </instrumentation>
+
     <uses-sdk android:targetSdkVersion="${target-sdk-version}"/>
 
     <uses-permission android:name="android.permission.WAKE_LOCK"/>