Add parameter to VersionCheckingTest

Using JUnit 4's Parameters class, VersionCheckingTest can receive
a "run name" argument on the command line (via its Intent extras) and
then pass that as a display name to blackbox. This should let multiple
OTA paths be clumped together in one box, like the Smoke (device) aka
DeviceSmokeTests suite.

Bug: 29490401
Change-Id: I7a2b272199ca91d66af7d11051a9ee9be507c6e7
diff --git a/tests/functional/otatests/Android.mk b/tests/functional/otatests/Android.mk
index 110ea6a..b73860e 100644
--- a/tests/functional/otatests/Android.mk
+++ b/tests/functional/otatests/Android.mk
@@ -7,6 +7,7 @@
 LOCAL_SRC_FILES := $(call all-java-files-under, src)
 LOCAL_MODULE_TAGS := tests
 LOCAL_STATIC_JAVA_LIBRARIES := \
+    android-support-test \
     easymocklib \
     objenesis-target \
     ub-uiautomator
diff --git a/tests/functional/otatests/AndroidManifest.xml b/tests/functional/otatests/AndroidManifest.xml
index 54cccad..b4037ea 100644
--- a/tests/functional/otatests/AndroidManifest.xml
+++ b/tests/functional/otatests/AndroidManifest.xml
@@ -2,16 +2,18 @@
 
 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
         package="com.android.functional.otatests">
+        
+    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
+    
+    <uses-sdk android:minSdkVersion="19"
+        android:targetSdkVersion="24" />
+
     <application>
         <uses-library android:name="android.test.runner" />
     </application>
 
-    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
-
-    <uses-sdk android:minSdkVersion="19"
-        android:targetSdkVersion="24" />
     <instrumentation
-        android:name="android.test.InstrumentationTestRunner"
+        android:name="android.support.test.runner.AndroidJUnitRunner"
         android:targetPackage="com.android.functional.otatests"
         android:label="Android System Update Functional Tests" />
 </manifest>
diff --git a/tests/functional/otatests/src/com/android/functional/otatests/PackageProcessTest.java b/tests/functional/otatests/src/com/android/functional/otatests/PackageProcessTest.java
index cf74375..f3a873a 100644
--- a/tests/functional/otatests/src/com/android/functional/otatests/PackageProcessTest.java
+++ b/tests/functional/otatests/src/com/android/functional/otatests/PackageProcessTest.java
@@ -16,17 +16,23 @@
 package com.android.functional.otatests;
 
 import static org.easymock.EasyMock.createNiceMock;
+import static org.junit.Assert.assertTrue;
 
+import android.app.Instrumentation;
 import android.content.Context;
 import android.content.ContextWrapper;
 import android.os.IPowerManager;
 import android.os.PowerManager;
 import android.os.RecoverySystem;
-import android.test.InstrumentationTestCase;
-
+import android.support.test.InstrumentationRegistry;
+import android.support.test.runner.AndroidJUnit4;
 import java.io.File;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
 
-public class PackageProcessTest extends InstrumentationTestCase {
+@RunWith(AndroidJUnit4.class)
+public class PackageProcessTest {
 
     private static final String PACKAGE_DATA_PATH =
             "/data/data/com.google.android.gms/app_download/update.zip";
@@ -36,6 +42,7 @@
     private Context mMockContext;
     private Context mContext;
     private PowerManager mMockPowerManager;
+    private Instrumentation mInstrumentation;
 
     private class PackageProcessMockContext extends ContextWrapper {
 
@@ -55,10 +62,10 @@
         }
     }
 
-    @Override
+    @Before
     public void setUp() throws Exception {
-        super.setUp();
-        mContext = getInstrumentation().getContext();
+        mInstrumentation = InstrumentationRegistry.getInstrumentation();
+        mContext = mInstrumentation.getContext();
         mMockContext = new PackageProcessMockContext(mContext);
         // Set a mocked out power manager into the mocked context, so the device
         // won't reboot at the end of installPackage
@@ -66,6 +73,7 @@
         mMockPowerManager = new PowerManager(mContext, mockIPowerManager, null);
     }
 
+    @Test
     public void testPackageProcessOnly() throws Exception {
         File pkg = new File(PACKAGE_DATA_PATH);
         RecoverySystem.verifyPackage(pkg, null, null);
@@ -74,6 +82,7 @@
         assertTrue(new File(BLOCK_MAP).exists());
     }
 
+    @Test
     public void testPackageProcessViaInstall() throws Exception {
         File pkg = new File(PACKAGE_DATA_PATH);
         RecoverySystem.verifyPackage(pkg, null, null);
diff --git a/tests/functional/otatests/src/com/android/functional/otatests/SystemUpdateTest.java b/tests/functional/otatests/src/com/android/functional/otatests/SystemUpdateTest.java
index 065ccb1..18de573 100644
--- a/tests/functional/otatests/src/com/android/functional/otatests/SystemUpdateTest.java
+++ b/tests/functional/otatests/src/com/android/functional/otatests/SystemUpdateTest.java
@@ -1,10 +1,17 @@
 package com.android.functional.otatests;
 
+import org.junit.Test;
+
 /**
  * A basic test case to assert that the system was updated to the expected version.
  */
 public class SystemUpdateTest extends VersionCheckingTest {
 
+    public SystemUpdateTest(String testPath) {
+        super(testPath);
+    }
+
+    @Test
     public void testIsUpdated() throws Exception {
         assertUpdated();
     }
diff --git a/tests/functional/otatests/src/com/android/functional/otatests/VersionCheckingTest.java b/tests/functional/otatests/src/com/android/functional/otatests/VersionCheckingTest.java
index 174786c..4f18192 100644
--- a/tests/functional/otatests/src/com/android/functional/otatests/VersionCheckingTest.java
+++ b/tests/functional/otatests/src/com/android/functional/otatests/VersionCheckingTest.java
@@ -1,12 +1,21 @@
 package com.android.functional.otatests;
 
-import android.test.InstrumentationTestCase;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
 
+import android.os.Bundle;
+import android.support.test.InstrumentationRegistry;
 import java.io.BufferedReader;
 import java.io.IOException;
 import java.io.InputStreamReader;
+import java.util.Arrays;
+import org.junit.Before;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameters;
 
-public class VersionCheckingTest extends InstrumentationTestCase {
+@RunWith(Parameterized.class)
+public class VersionCheckingTest {
 
     protected static final String OLD_VERSION = "/sdcard/otatest/version.old";
     protected static final String NEW_VERSION = "/sdcard/otatest/version.new";
@@ -14,11 +23,18 @@
     protected static final String KEY_BOOTLOADER = "ro.bootloader";
     protected static final String KEY_BASEBAND = "ro.build.expect.baseband";
     protected static final String KEY_BASEBAND_GSM = "gsm.version.baseband";
+    protected static final String PATH_NAME = "path_name";
 
     protected VersionInfo mOldVersion;
     protected VersionInfo mNewVersion;
 
-    @Override
+    protected String mTestPath;
+
+    public VersionCheckingTest(String testPath) {
+        mTestPath = testPath;
+    }
+
+    @Before
     public void setUp() throws Exception {
         try {
             mOldVersion = VersionInfo.parseFromFile(OLD_VERSION);
@@ -29,6 +45,15 @@
         }
     }
 
+    @Parameters(name = "{0}")
+    public static Iterable<? extends Object> getOtaPathName() {
+        Bundle args = InstrumentationRegistry.getArguments();
+        if (args.containsKey(PATH_NAME)) {
+            return Arrays.asList(args.getString(PATH_NAME));
+        }
+        return Arrays.asList("unnamed path");
+    }
+
     protected void assertNotUpdated() throws IOException {
         assertEquals(mOldVersion.getBuildId(), getProp(KEY_BUILD_ID));
         assertEquals(mOldVersion.getBootloaderVersion(), getProp(KEY_BOOTLOADER));