aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYuexi Ma <yuexima@google.com>2021-02-11 01:35:44 -0800
committerYuexi Ma <yuexima@google.com>2021-03-01 23:49:45 +0000
commite11386db17efd68eba8cb13da397cc2fcf882cf6 (patch)
tree833729ea0f1d2a58f4d9e06ef63eaf176f913cdd
parenta2b2ba7289958a0d3150c00725de07757a27895e (diff)
downloadplatform_test_app_compat_csuite-e11386db17efd68eba8cb13da397cc2fcf882cf6.tar.gz
platform_test_app_compat_csuite-e11386db17efd68eba8cb13da397cc2fcf882cf6.tar.bz2
platform_test_app_compat_csuite-e11386db17efd68eba8cb13da397cc2fcf882cf6.zip
Change the system app uninstaller preparer into a util class
Change the system app uninstaller preparer into a util class and call it from the app setup preparer. Test: atest :presubmit Bug: 179101382 Change-Id: I945fd5d41bedf22599fc53fdc2679738e1c35215
-rw-r--r--harness/src/main/java/com/android/compatibility/targetprep/AppSetupPreparer.java10
-rw-r--r--harness/src/main/java/com/android/csuite/core/SystemPackageUninstaller.java (renamed from harness/src/main/java/com/android/compatibility/targetprep/SystemAppRemovalPreparer.java)44
-rw-r--r--harness/src/main/resources/config/csuite-system-app-launch.xml.template1
-rw-r--r--harness/src/test/java/com/android/csuite/CSuiteUnitTests.java2
-rw-r--r--harness/src/test/java/com/android/csuite/core/SystemAppUninstallerTest.java (renamed from harness/src/test/java/com/android/compatibility/targetprep/SystemAppRemovalPreparerTest.java)166
5 files changed, 94 insertions, 129 deletions
diff --git a/harness/src/main/java/com/android/compatibility/targetprep/AppSetupPreparer.java b/harness/src/main/java/com/android/compatibility/targetprep/AppSetupPreparer.java
index 0dc6ca4..9445316 100644
--- a/harness/src/main/java/com/android/compatibility/targetprep/AppSetupPreparer.java
+++ b/harness/src/main/java/com/android/compatibility/targetprep/AppSetupPreparer.java
@@ -18,6 +18,7 @@ package com.android.compatibility.targetprep;
import static com.google.common.base.Preconditions.checkArgument;
+import com.android.csuite.core.SystemPackageUninstaller;
import com.android.tradefed.build.IBuildInfo;
import com.android.tradefed.config.Option;
import com.android.tradefed.device.DeviceNotAvailableException;
@@ -42,7 +43,6 @@ import java.util.List;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
-
/** A Tradefed preparer that downloads and installs an app on the target device. */
public final class AppSetupPreparer implements ITargetPreparer {
@@ -62,6 +62,9 @@ public final class AppSetupPreparer implements ITargetPreparer {
@VisibleForTesting static final String OPTION_MAX_RETRY = "max-retry";
@VisibleForTesting static final String OPTION_AAPT_VERSION = "aapt-version";
+ @Option(name = "package-name", description = "Package name of testing app.")
+ private String mPackageName;
+
@Option(
name = OPTION_TEST_FILE_NAME,
description = "the name of an apk file to be installed on device. Can be repeated.")
@@ -144,6 +147,7 @@ public final class AppSetupPreparer implements ITargetPreparer {
ITargetPreparer handler =
mTimeLimiter.newProxy(
new ITargetPreparer() {
+ @Override
public void setUp(ITestDevice device, IBuildInfo buildInfo)
throws DeviceNotAvailableException, BuildError,
TargetSetupError {
@@ -183,6 +187,10 @@ public final class AppSetupPreparer implements ITargetPreparer {
throws DeviceNotAvailableException, BuildError, TargetSetupError {
mTestAppInstallSetup.setAaptVersion(mAaptVersion);
+ if (mPackageName != null) {
+ SystemPackageUninstaller.uninstallPackage(mPackageName, device);
+ }
+
for (File testFile : mTestFiles) {
mTestAppInstallSetup.addTestFile(testFile);
}
diff --git a/harness/src/main/java/com/android/compatibility/targetprep/SystemAppRemovalPreparer.java b/harness/src/main/java/com/android/csuite/core/SystemPackageUninstaller.java
index 8ab58d6..b878578 100644
--- a/harness/src/main/java/com/android/compatibility/targetprep/SystemAppRemovalPreparer.java
+++ b/harness/src/main/java/com/android/csuite/core/SystemPackageUninstaller.java
@@ -14,17 +14,13 @@
* limitations under the License.
*/
-package com.android.compatibility.targetprep;
+package com.android.csuite.core;
import static com.google.common.base.Preconditions.checkNotNull;
-import com.android.tradefed.build.IBuildInfo;
-import com.android.tradefed.config.Option;
-import com.android.tradefed.config.Option.Importance;
import com.android.tradefed.device.DeviceNotAvailableException;
import com.android.tradefed.device.ITestDevice;
import com.android.tradefed.log.LogUtil.CLog;
-import com.android.tradefed.targetprep.ITargetPreparer;
import com.android.tradefed.targetprep.TargetSetupError;
import com.android.tradefed.util.CommandResult;
import com.android.tradefed.util.CommandStatus;
@@ -37,54 +33,46 @@ import java.util.Arrays;
/**
* Uninstalls a system app.
*
- * <p>This preparer class may not restore the uninstalled system app after test completes.
+ * <p>This utility class may not restore the uninstalled system app after test completes.
*
- * <p>The preparer may disable dm verity on some devices, and it does not re-enable it after
+ * <p>The class may disable dm verity on some devices, and it does not re-enable it after
* uninstalling a system app.
*/
-public final class SystemAppRemovalPreparer implements ITargetPreparer {
+public final class SystemPackageUninstaller {
@VisibleForTesting static final String OPTION_PACKAGE_NAME = "package-name";
static final String SYSPROP_DEV_BOOTCOMPLETE = "dev.bootcomplete";
static final String SYSPROP_SYS_BOOT_COMPLETED = "sys.boot_completed";
static final long WAIT_FOR_BOOT_COMPLETE_TIMEOUT_MILLIS = 1000 * 60;
@VisibleForTesting static final int MAX_NUMBER_OF_UPDATES = 100;
- @Option(
- name = OPTION_PACKAGE_NAME,
- description = "The package name of the system app to be removed.",
- importance = Importance.ALWAYS)
- private String mPackageName;
-
- /** {@inheritDoc} */
- @Override
- public void setUp(ITestDevice device, IBuildInfo buildInfo)
+ public static void uninstallPackage(String packageName, ITestDevice device)
throws TargetSetupError, DeviceNotAvailableException {
- checkNotNull(mPackageName);
+ checkNotNull(packageName);
- if (!isPackageInstalled(mPackageName, device)) {
- CLog.i("Package %s is not installed.", mPackageName);
+ if (!isPackageInstalled(packageName, device)) {
+ CLog.i("Package %s is not installed.", packageName);
return;
}
// Attempts to uninstall the package/updates from user partition.
// This method should be called before the other methods and requires
// the framework to be running.
- removePackageUpdates(mPackageName, device);
+ removePackageUpdates(packageName, device);
- if (!isPackageInstalled(mPackageName, device)) {
- CLog.i("Package %s has been removed.", mPackageName);
+ if (!isPackageInstalled(packageName, device)) {
+ CLog.i("Package %s has been removed.", packageName);
return;
}
- String packageInstallDirectory = getPackageInstallDirectory(mPackageName, device);
- CLog.d("Install directory for package %s is %s", mPackageName, packageInstallDirectory);
+ String packageInstallDirectory = getPackageInstallDirectory(packageName, device);
+ CLog.d("Install directory for package %s is %s", packageName, packageInstallDirectory);
if (!isPackagePathSystemApp(packageInstallDirectory)) {
- CLog.w("%s is not a system app, skipping", mPackageName);
+ CLog.w("%s is not a system app, skipping", packageName);
return;
}
- CLog.i("Uninstalling system app %s", mPackageName);
+ CLog.i("Uninstalling system app %s", packageName);
runWithWritableFilesystem(
device,
@@ -93,7 +81,7 @@ public final class SystemAppRemovalPreparer implements ITargetPreparer {
device,
() -> {
removePackageInstallDirectory(packageInstallDirectory, device);
- removePackageData(mPackageName, device);
+ removePackageData(packageName, device);
}));
}
diff --git a/harness/src/main/resources/config/csuite-system-app-launch.xml.template b/harness/src/main/resources/config/csuite-system-app-launch.xml.template
index a7841f3..4d1181b 100644
--- a/harness/src/main/resources/config/csuite-system-app-launch.xml.template
+++ b/harness/src/main/resources/config/csuite-system-app-launch.xml.template
@@ -15,7 +15,6 @@
-->
<configuration description="Reinstalls a system app and check for launch crashes.">
<option name="package-name" value="{package}"/>
- <target_preparer class="com.android.compatibility.targetprep.SystemAppRemovalPreparer"/>
<target_preparer class="com.android.compatibility.targetprep.AppSetupPreparer">
<option name="test-file-name" value="app://{package}"/>
</target_preparer>
diff --git a/harness/src/test/java/com/android/csuite/CSuiteUnitTests.java b/harness/src/test/java/com/android/csuite/CSuiteUnitTests.java
index 8ba878d..6eb1103 100644
--- a/harness/src/test/java/com/android/csuite/CSuiteUnitTests.java
+++ b/harness/src/test/java/com/android/csuite/CSuiteUnitTests.java
@@ -23,12 +23,12 @@ import org.junit.runners.Suite.SuiteClasses;
@SuiteClasses({
com.android.compatibility.targetprep.AppSetupPreparerTest.class,
com.android.compatibility.targetprep.CheckGmsPreparerTest.class,
- com.android.compatibility.targetprep.SystemAppRemovalPreparerTest.class,
com.android.compatibility.testtype.AppLaunchTestTest.class,
com.android.csuite.config.AppRemoteFileResolverTest.class,
com.android.csuite.config.ModuleGeneratorTest.class,
com.android.csuite.core.CommandLinePackageNameProviderTest.class,
com.android.csuite.core.FileBasedPackageNameProviderTest.class,
+ com.android.csuite.core.SystemAppUninstallerTest.class,
com.android.csuite.testing.CorrespondencesTest.class,
com.android.csuite.testing.MoreAssertsTest.class,
})
diff --git a/harness/src/test/java/com/android/compatibility/targetprep/SystemAppRemovalPreparerTest.java b/harness/src/test/java/com/android/csuite/core/SystemAppUninstallerTest.java
index 374559c..2af9d9c 100644
--- a/harness/src/test/java/com/android/compatibility/targetprep/SystemAppRemovalPreparerTest.java
+++ b/harness/src/test/java/com/android/csuite/core/SystemAppUninstallerTest.java
@@ -13,23 +13,17 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.android.compatibility.targetprep;
-
+package com.android.csuite.core;
import static org.testng.Assert.assertThrows;
-import com.android.tradefed.config.ConfigurationException;
-import com.android.tradefed.config.OptionSetter;
import com.android.tradefed.device.DeviceNotAvailableException;
import com.android.tradefed.device.ITestDevice;
import com.android.tradefed.targetprep.TargetSetupError;
import com.android.tradefed.util.CommandResult;
import com.android.tradefed.util.CommandStatus;
-import com.google.common.collect.ArrayListMultimap;
-import com.google.common.collect.ListMultimap;
-import java.util.Map;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -38,7 +32,7 @@ import org.mockito.ArgumentMatchers;
import org.mockito.Mockito;
@RunWith(JUnit4.class)
-public final class SystemAppRemovalPreparerTest {
+public final class SystemAppUninstallerTest {
private static final ITestDevice NULL_DEVICE = null;
private static final String TEST_PACKAGE_NAME = "test.package.name";
private static final String SYSTEM_APP_INSTALL_DIRECTORY = "/system/app";
@@ -50,15 +44,14 @@ public final class SystemAppRemovalPreparerTest {
private static final String MOUNT_COMMAND_PREFIX = "mount";
@Test
- public void setUp_packageNameIsNull_throws() throws Exception {
- SystemAppRemovalPreparer preparer = new SystemAppRemovalPreparer();
-
- assertThrows(NullPointerException.class, () -> preparer.setUp(null, null));
+ public void uninstallPackage_packageNameIsNull_throws() throws Exception {
+ assertThrows(
+ NullPointerException.class,
+ () -> SystemPackageUninstaller.uninstallPackage(TEST_PACKAGE_NAME, null));
}
@Test
- public void setUp_packageIsNotInstalled_doesNotRemove() throws Exception {
- SystemAppRemovalPreparer preparer = preparerBuilder().build();
+ public void uninstallPackage_packageIsNotInstalled_doesNotRemove() throws Exception {
ITestDevice device = createGoodDeviceWithSystemAppInstalled();
// Mock the device as if the test package does not exist on device
CommandResult commandResult = createSuccessfulCommandResult();
@@ -69,14 +62,14 @@ public final class SystemAppRemovalPreparerTest {
CHECK_PACKAGE_INSTALLED_COMMAND_PREFIX)))
.thenReturn(commandResult);
- preparer.setUp(device, null);
+ SystemPackageUninstaller.uninstallPackage(TEST_PACKAGE_NAME, device);
Mockito.verify(device, Mockito.times(0)).executeShellV2Command(Mockito.startsWith("rm"));
}
@Test
- public void setUp_differentPackageWithSameNamePrefixInstalled_doesNotRemove() throws Exception {
- SystemAppRemovalPreparer preparer = preparerBuilder().build();
+ public void uninstallPackage_differentPackageWithSameNamePrefixInstalled_doesNotRemove()
+ throws Exception {
ITestDevice device = createGoodDeviceWithSystemAppInstalled();
// Mock the device as if the test package does not exist on device
CommandResult commandResult = createSuccessfulCommandResult();
@@ -87,14 +80,13 @@ public final class SystemAppRemovalPreparerTest {
CHECK_PACKAGE_INSTALLED_COMMAND_PREFIX)))
.thenReturn(commandResult);
- preparer.setUp(device, null);
+ SystemPackageUninstaller.uninstallPackage(TEST_PACKAGE_NAME, device);
Mockito.verify(device, Mockito.times(0)).executeShellV2Command(Mockito.startsWith("rm"));
}
@Test
- public void setUp_checkPackageInstalledCommandFailed_throws() throws Exception {
- SystemAppRemovalPreparer preparer = preparerBuilder().build();
+ public void uninstallPackage_checkPackageInstalledCommandFailed_throws() throws Exception {
ITestDevice device = createGoodDeviceWithSystemAppInstalled();
Mockito.when(
device.executeShellV2Command(
@@ -102,12 +94,13 @@ public final class SystemAppRemovalPreparerTest {
CHECK_PACKAGE_INSTALLED_COMMAND_PREFIX)))
.thenReturn(createFailedCommandResult());
- assertThrows(TargetSetupError.class, () -> preparer.setUp(device, null));
+ assertThrows(
+ TargetSetupError.class,
+ () -> SystemPackageUninstaller.uninstallPackage(TEST_PACKAGE_NAME, device));
}
@Test
- public void setUp_getInstallDirectoryCommandFailed_throws() throws Exception {
- SystemAppRemovalPreparer preparer = preparerBuilder().build();
+ public void uninstallPackage_getInstallDirectoryCommandFailed_throws() throws Exception {
ITestDevice device = createGoodDeviceWithSystemAppInstalled();
Mockito.when(
device.executeShellV2Command(
@@ -115,94 +108,97 @@ public final class SystemAppRemovalPreparerTest {
GET_PACKAGE_INSTALL_PATH_COMMAND_PREFIX)))
.thenReturn(createFailedCommandResult());
- assertThrows(TargetSetupError.class, () -> preparer.setUp(device, null));
+ assertThrows(
+ TargetSetupError.class,
+ () -> SystemPackageUninstaller.uninstallPackage(TEST_PACKAGE_NAME, device));
}
@Test
- public void setUp_packageIsNotSystemApp_doesNotRemove() throws Exception {
- SystemAppRemovalPreparer preparer = preparerBuilder().build();
+ public void uninstallPackage_packageIsNotSystemApp_doesNotRemove() throws Exception {
ITestDevice device = createGoodDeviceWithUserAppInstalled();
- preparer.setUp(device, null);
+ SystemPackageUninstaller.uninstallPackage(TEST_PACKAGE_NAME, device);
Mockito.verify(device, Mockito.times(0)).executeShellV2Command(Mockito.startsWith("rm"));
}
@Test
- public void setUp_adbAlreadyRooted_doesNotRootAgain() throws Exception {
- SystemAppRemovalPreparer preparer = preparerBuilder().build();
+ public void uninstallPackage_adbAlreadyRooted_doesNotRootAgain() throws Exception {
ITestDevice device = createGoodDeviceWithSystemAppInstalled();
Mockito.when(device.isAdbRoot()).thenReturn(true);
- preparer.setUp(device, null);
+ SystemPackageUninstaller.uninstallPackage(TEST_PACKAGE_NAME, device);
Mockito.verify(device, Mockito.times(0)).enableAdbRoot();
}
@Test
- public void setUp_adbNotAlreadyRooted_rootAdbAndThenUnroot() throws Exception {
- SystemAppRemovalPreparer preparer = preparerBuilder().build();
+ public void uninstallPackage_adbNotAlreadyRooted_rootAdbAndThenUnroot() throws Exception {
ITestDevice device = createGoodDeviceWithSystemAppInstalled();
Mockito.when(device.isAdbRoot()).thenReturn(false);
- preparer.setUp(device, null);
+ SystemPackageUninstaller.uninstallPackage(TEST_PACKAGE_NAME, device);
Mockito.verify(device, Mockito.times(1)).enableAdbRoot();
Mockito.verify(device, Mockito.times(1)).disableAdbRoot();
}
@Test
- public void setUp_adbRootCommandFailed_throws() throws Exception {
- SystemAppRemovalPreparer preparer = preparerBuilder().build();
+ public void uninstallPackage_adbRootCommandFailed_throws() throws Exception {
ITestDevice device = createGoodDeviceWithSystemAppInstalled();
Mockito.when(device.enableAdbRoot()).thenThrow(new DeviceNotAvailableException());
- assertThrows(DeviceNotAvailableException.class, () -> preparer.setUp(device, null));
+ assertThrows(
+ DeviceNotAvailableException.class,
+ () -> SystemPackageUninstaller.uninstallPackage(TEST_PACKAGE_NAME, device));
}
@Test
- public void setUp_adbRootFailed_throws() throws Exception {
- SystemAppRemovalPreparer preparer = preparerBuilder().build();
+ public void uninstallPackage_adbRootFailed_throws() throws Exception {
ITestDevice device = createGoodDeviceWithSystemAppInstalled();
Mockito.when(device.enableAdbRoot()).thenReturn(false);
- assertThrows(TargetSetupError.class, () -> preparer.setUp(device, null));
+ assertThrows(
+ TargetSetupError.class,
+ () -> SystemPackageUninstaller.uninstallPackage(TEST_PACKAGE_NAME, device));
}
@Test
- public void setUp_adbDisableRootCommandFailed_throws() throws Exception {
- SystemAppRemovalPreparer preparer = preparerBuilder().build();
+ public void uninstallPackage_adbDisableRootCommandFailed_throws() throws Exception {
ITestDevice device = createGoodDeviceWithSystemAppInstalled();
Mockito.when(device.disableAdbRoot()).thenThrow(new DeviceNotAvailableException());
- assertThrows(DeviceNotAvailableException.class, () -> preparer.setUp(device, null));
+ assertThrows(
+ DeviceNotAvailableException.class,
+ () -> SystemPackageUninstaller.uninstallPackage(TEST_PACKAGE_NAME, device));
}
@Test
- public void setUp_adbDisableRootFailed_throws() throws Exception {
- SystemAppRemovalPreparer preparer = preparerBuilder().build();
+ public void uninstallPackage_adbDisableRootFailed_throws() throws Exception {
ITestDevice device = createGoodDeviceWithSystemAppInstalled();
Mockito.when(device.disableAdbRoot()).thenReturn(false);
- assertThrows(TargetSetupError.class, () -> preparer.setUp(device, null));
+ assertThrows(
+ TargetSetupError.class,
+ () -> SystemPackageUninstaller.uninstallPackage(TEST_PACKAGE_NAME, device));
}
@Test
- public void setUp_adbRemountFailed_throws() throws Exception {
- SystemAppRemovalPreparer preparer = preparerBuilder().build();
+ public void uninstallPackage_adbRemountFailed_throws() throws Exception {
ITestDevice device = createGoodDeviceWithSystemAppInstalled();
Mockito.doThrow(new DeviceNotAvailableException()).when(device).remountSystemWritable();
- assertThrows(DeviceNotAvailableException.class, () -> preparer.setUp(device, null));
+ assertThrows(
+ DeviceNotAvailableException.class,
+ () -> SystemPackageUninstaller.uninstallPackage(TEST_PACKAGE_NAME, device));
}
@Test
- public void setUp_adbRemounted_mountReadOnlyAfterwards() throws Exception {
- SystemAppRemovalPreparer preparer = preparerBuilder().build();
+ public void uninstallPackage_adbRemounted_mountReadOnlyAfterwards() throws Exception {
ITestDevice device = createGoodDeviceWithSystemAppInstalled();
Mockito.doNothing().when(device).remountSystemWritable();
- preparer.setUp(device, null);
+ SystemPackageUninstaller.uninstallPackage(TEST_PACKAGE_NAME, device);
Mockito.verify(device, Mockito.times(1)).remountSystemWritable();
Mockito.verify(device, Mockito.times(1))
@@ -210,47 +206,47 @@ public final class SystemAppRemovalPreparerTest {
}
@Test
- public void setUp_mountReadOnlyFailed_throws() throws Exception {
- SystemAppRemovalPreparer preparer = preparerBuilder().build();
+ public void uninstallPackage_mountReadOnlyFailed_throws() throws Exception {
ITestDevice device = createGoodDeviceWithSystemAppInstalled();
Mockito.when(
device.executeShellV2Command(
ArgumentMatchers.startsWith(MOUNT_COMMAND_PREFIX)))
.thenReturn(createFailedCommandResult());
- assertThrows(TargetSetupError.class, () -> preparer.setUp(device, null));
+ assertThrows(
+ TargetSetupError.class,
+ () -> SystemPackageUninstaller.uninstallPackage(TEST_PACKAGE_NAME, device));
}
@Test
- public void setUp_removePackageInstallDirectoryFailed_throws() throws Exception {
- SystemAppRemovalPreparer preparer = preparerBuilder().build();
+ public void uninstallPackage_removePackageInstallDirectoryFailed_throws() throws Exception {
ITestDevice device = createGoodDeviceWithSystemAppInstalled();
Mockito.when(
device.executeShellV2Command(
ArgumentMatchers.startsWith(REMOVE_SYSTEM_APP_COMMAND_PREFIX)))
.thenReturn(createFailedCommandResult());
- assertThrows(TargetSetupError.class, () -> preparer.setUp(device, null));
+ assertThrows(
+ TargetSetupError.class,
+ () -> SystemPackageUninstaller.uninstallPackage(TEST_PACKAGE_NAME, device));
}
@Test
- public void setUp_removePackageDataDirectoryFailed_doesNotThrow() throws Exception {
- SystemAppRemovalPreparer preparer = preparerBuilder().build();
+ public void uninstallPackage_removePackageDataDirectoryFailed_doesNotThrow() throws Exception {
ITestDevice device = createGoodDeviceWithSystemAppInstalled();
Mockito.when(
device.executeShellV2Command(
ArgumentMatchers.startsWith(REMOVE_APP_DATA_COMMAND_PREFIX)))
.thenReturn(createFailedCommandResult());
- preparer.setUp(device, null);
+ SystemPackageUninstaller.uninstallPackage(TEST_PACKAGE_NAME, device);
}
@Test
- public void setUp_packageIsSystemApp_appRemoved() throws Exception {
- SystemAppRemovalPreparer preparer = preparerBuilder().build();
+ public void uninstallPackage_packageIsSystemApp_appRemoved() throws Exception {
ITestDevice device = createGoodDeviceWithSystemAppInstalled();
- preparer.setUp(device, null);
+ SystemPackageUninstaller.uninstallPackage(TEST_PACKAGE_NAME, device);
Mockito.verify(device, Mockito.times(1))
.executeShellV2Command(Mockito.startsWith(REMOVE_SYSTEM_APP_COMMAND_PREFIX));
@@ -259,12 +255,11 @@ public final class SystemAppRemovalPreparerTest {
}
@Test
- public void setUp_noUpdatePackagePresent_appRemoved() throws Exception {
- SystemAppRemovalPreparer preparer = preparerBuilder().build();
+ public void uninstallPackage_noUpdatePackagePresent_appRemoved() throws Exception {
int numberOfUpdates = 0;
ITestDevice device = createGoodDeviceWithSystemAppInstalled(numberOfUpdates);
- preparer.setUp(device, null);
+ SystemPackageUninstaller.uninstallPackage(TEST_PACKAGE_NAME, device);
Mockito.verify(device, Mockito.times(numberOfUpdates + 1))
.uninstallPackage(TEST_PACKAGE_NAME);
@@ -273,12 +268,11 @@ public final class SystemAppRemovalPreparerTest {
}
@Test
- public void setUp_someUpdatePackagesPresent_appRemoved() throws Exception {
- SystemAppRemovalPreparer preparer = preparerBuilder().build();
+ public void uninstallPackage_someUpdatePackagesPresent_appRemoved() throws Exception {
int numberOfUpdates = 2;
ITestDevice device = createGoodDeviceWithSystemAppInstalled(numberOfUpdates);
- preparer.setUp(device, null);
+ SystemPackageUninstaller.uninstallPackage(TEST_PACKAGE_NAME, device);
Mockito.verify(device, Mockito.times(numberOfUpdates + 1))
.uninstallPackage(TEST_PACKAGE_NAME);
@@ -287,33 +281,14 @@ public final class SystemAppRemovalPreparerTest {
}
@Test
- public void setUp_tooManyUpdatePackagesPresent_throwsException() throws Exception {
- SystemAppRemovalPreparer preparer = preparerBuilder().build();
+ public void uninstallPackage_tooManyUpdatePackagesPresent_throwsException() throws Exception {
ITestDevice device =
createGoodDeviceWithSystemAppInstalled(
- SystemAppRemovalPreparer.MAX_NUMBER_OF_UPDATES + 1);
+ SystemPackageUninstaller.MAX_NUMBER_OF_UPDATES + 1);
- assertThrows(TargetSetupError.class, () -> preparer.setUp(device, null));
- }
-
- private static final class PreparerBuilder {
- private final ListMultimap<String, String> mOptions = ArrayListMultimap.create();
-
- PreparerBuilder setOption(String key, String value) {
- mOptions.put(key, value);
- return this;
- }
-
- SystemAppRemovalPreparer build() throws ConfigurationException {
- SystemAppRemovalPreparer preparer = new SystemAppRemovalPreparer();
- OptionSetter optionSetter = new OptionSetter(preparer);
-
- for (Map.Entry<String, String> e : mOptions.entries()) {
- optionSetter.setOptionValue(e.getKey(), e.getValue());
- }
-
- return preparer;
- }
+ assertThrows(
+ TargetSetupError.class,
+ () -> SystemPackageUninstaller.uninstallPackage(TEST_PACKAGE_NAME, device));
}
private ITestDevice createGoodDeviceWithUserAppInstalled() throws Exception {
@@ -410,11 +385,6 @@ public final class SystemAppRemovalPreparerTest {
return device;
}
- private static PreparerBuilder preparerBuilder() {
- return new PreparerBuilder()
- .setOption(SystemAppRemovalPreparer.OPTION_PACKAGE_NAME, TEST_PACKAGE_NAME);
- }
-
private static CommandResult createSuccessfulCommandResult() {
CommandResult commandResult = new CommandResult(CommandStatus.SUCCESS);
commandResult.setExitCode(0);