summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJW Wang <wangchun@google.com>2019-09-04 17:19:30 +0800
committerJW Wang <wangchun@google.com>2019-09-06 19:04:05 +0800
commitb4b37500d697783b693ac2218a9a5e867b03997b (patch)
tree06cec57d8926fd520a39e55532dbaff0d8667e85
parent144f82b106ce1fc02da7f9ecfbe836528925a0ac (diff)
Add a helper to reduce boilerplate code (1/n)
Bug: 140472424 Test: atest PackageWatchdogTest Change-Id: I3aa80f1c7706702620da0ce2247afe0359cb0674
-rw-r--r--tests/PackageWatchdog/src/com/android/server/PackageWatchdogTest.java47
1 files changed, 19 insertions, 28 deletions
diff --git a/tests/PackageWatchdog/src/com/android/server/PackageWatchdogTest.java b/tests/PackageWatchdog/src/com/android/server/PackageWatchdogTest.java
index 4c5abf9fc6a6..ee59087d7f53 100644
--- a/tests/PackageWatchdog/src/com/android/server/PackageWatchdogTest.java
+++ b/tests/PackageWatchdog/src/com/android/server/PackageWatchdogTest.java
@@ -292,9 +292,7 @@ public class PackageWatchdogTest {
watchdog.startObservingHealth(observer1, Arrays.asList(APP_B), SHORT_DURATION);
// Then fail APP_C (not observed) above the threshold
- for (int i = 0; i < watchdog.getTriggerFailureCount(); i++) {
- watchdog.onPackageFailure(Arrays.asList(new VersionedPackage(APP_C, VERSION_CODE)));
- }
+ raiseFatalFailure(watchdog, Arrays.asList(new VersionedPackage(APP_C, VERSION_CODE)));
// Run handler so package failures are dispatched to observers
mTestLooper.dispatchAll();
@@ -326,10 +324,8 @@ public class PackageWatchdogTest {
watchdog.startObservingHealth(observer, Arrays.asList(APP_A), SHORT_DURATION);
// Then fail APP_A (different version) above the threshold
- for (int i = 0; i < watchdog.getTriggerFailureCount(); i++) {
- watchdog.onPackageFailure(Arrays.asList(
- new VersionedPackage(APP_A, differentVersionCode)));
- }
+ raiseFatalFailure(watchdog,
+ Arrays.asList(new VersionedPackage(APP_A, differentVersionCode)));
// Run handler so package failures are dispatched to observers
mTestLooper.dispatchAll();
@@ -365,12 +361,10 @@ public class PackageWatchdogTest {
SHORT_DURATION);
// Then fail all apps above the threshold
- for (int i = 0; i < watchdog.getTriggerFailureCount(); i++) {
- watchdog.onPackageFailure(Arrays.asList(new VersionedPackage(APP_A, VERSION_CODE),
- new VersionedPackage(APP_B, VERSION_CODE),
- new VersionedPackage(APP_C, VERSION_CODE),
- new VersionedPackage(APP_D, VERSION_CODE)));
- }
+ raiseFatalFailure(watchdog, Arrays.asList(new VersionedPackage(APP_A, VERSION_CODE),
+ new VersionedPackage(APP_B, VERSION_CODE),
+ new VersionedPackage(APP_C, VERSION_CODE),
+ new VersionedPackage(APP_D, VERSION_CODE)));
// Run handler so package failures are dispatched to observers
mTestLooper.dispatchAll();
@@ -418,9 +412,7 @@ public class PackageWatchdogTest {
watchdog.startObservingHealth(observerSecond, Arrays.asList(APP_A), LONG_DURATION);
// Then fail APP_A above the threshold
- for (int i = 0; i < watchdog.getTriggerFailureCount(); i++) {
- watchdog.onPackageFailure(Arrays.asList(new VersionedPackage(APP_A, VERSION_CODE)));
- }
+ raiseFatalFailure(watchdog, Arrays.asList(new VersionedPackage(APP_A, VERSION_CODE)));
// Run handler so package failures are dispatched to observers
mTestLooper.dispatchAll();
@@ -435,9 +427,7 @@ public class PackageWatchdogTest {
observerSecond.mFailedPackages.clear();
// Then fail APP_A again above the threshold
- for (int i = 0; i < watchdog.getTriggerFailureCount(); i++) {
- watchdog.onPackageFailure(Arrays.asList(new VersionedPackage(APP_A, VERSION_CODE)));
- }
+ raiseFatalFailure(watchdog, Arrays.asList(new VersionedPackage(APP_A, VERSION_CODE)));
// Run handler so package failures are dispatched to observers
mTestLooper.dispatchAll();
@@ -452,9 +442,7 @@ public class PackageWatchdogTest {
observerSecond.mFailedPackages.clear();
// Then fail APP_A again above the threshold
- for (int i = 0; i < watchdog.getTriggerFailureCount(); i++) {
- watchdog.onPackageFailure(Arrays.asList(new VersionedPackage(APP_A, VERSION_CODE)));
- }
+ raiseFatalFailure(watchdog, Arrays.asList(new VersionedPackage(APP_A, VERSION_CODE)));
// Run handler so package failures are dispatched to observers
mTestLooper.dispatchAll();
@@ -469,9 +457,7 @@ public class PackageWatchdogTest {
observerSecond.mFailedPackages.clear();
// Then fail APP_A again above the threshold
- for (int i = 0; i < watchdog.getTriggerFailureCount(); i++) {
- watchdog.onPackageFailure(Arrays.asList(new VersionedPackage(APP_A, VERSION_CODE)));
- }
+ raiseFatalFailure(watchdog, Arrays.asList(new VersionedPackage(APP_A, VERSION_CODE)));
// Run handler so package failures are dispatched to observers
mTestLooper.dispatchAll();
@@ -496,9 +482,7 @@ public class PackageWatchdogTest {
watchdog.startObservingHealth(observer1, Arrays.asList(APP_A), SHORT_DURATION);
// Then fail APP_A above the threshold
- for (int i = 0; i < watchdog.getTriggerFailureCount(); i++) {
- watchdog.onPackageFailure(Arrays.asList(new VersionedPackage(APP_A, VERSION_CODE)));
- }
+ raiseFatalFailure(watchdog, Arrays.asList(new VersionedPackage(APP_A, VERSION_CODE)));
// Run handler so package failures are dispatched to observers
mTestLooper.dispatchAll();
@@ -770,6 +754,13 @@ public class PackageWatchdogTest {
mTestLooper.dispatchAll();
}
+ /** Trigger package failures above the threshold. */
+ private void raiseFatalFailure(PackageWatchdog watchdog, List<VersionedPackage> packages) {
+ for (int i = 0; i < watchdog.getTriggerFailureCount(); i++) {
+ watchdog.onPackageFailure(packages);
+ }
+ }
+
private PackageWatchdog createWatchdog() {
return createWatchdog(new TestController(), true /* withPackagesReady */);
}