diff options
author | 2022-02-07 16:05:56 +0000 | |
---|---|---|
committer | 2022-02-07 16:05:56 +0000 | |
commit | dda94e8f13569e6236958cec6e45072da11df2aa (patch) | |
tree | 7aa05d4a6faf676bcf5ea94b7332d82415ec82d5 | |
parent | 48caf9d6a1857fc04773028197028d6e28dfb55e (diff) | |
parent | 5c97595aafa51cd11c609afe31a848f20cf908ee (diff) |
Merge "Avoid catching AssertionError for actual failures."
-rw-r--r-- | services/Android.bp | 1 | ||||
-rw-r--r-- | services/tests/servicestests/src/com/android/server/am/ActivityManagerUtilsTest.java | 22 |
2 files changed, 13 insertions, 10 deletions
diff --git a/services/Android.bp b/services/Android.bp index 2bd8c1af1d06..134218b5c724 100644 --- a/services/Android.bp +++ b/services/Android.bp @@ -18,6 +18,7 @@ java_defaults { // "-Xep:AndroidFrameworkUid:ERROR", "-Xep:SelfEquals:ERROR", "-Xep:NullTernary:ERROR", + "-Xep:TryFailThrowable:ERROR", // NOTE: only enable to generate local patchfiles // "-XepPatchChecks:refaster:frameworks/base/errorprone/refaster/EfficientXml.java.refaster", // "-XepPatchLocation:/tmp/refaster/", diff --git a/services/tests/servicestests/src/com/android/server/am/ActivityManagerUtilsTest.java b/services/tests/servicestests/src/com/android/server/am/ActivityManagerUtilsTest.java index 96103e36ae92..d95c9ac1bd6c 100644 --- a/services/tests/servicestests/src/com/android/server/am/ActivityManagerUtilsTest.java +++ b/services/tests/servicestests/src/com/android/server/am/ActivityManagerUtilsTest.java @@ -17,7 +17,7 @@ package com.android.server.am; import static com.google.common.truth.Truth.assertThat; -import static org.junit.Assert.fail; +import static org.junit.Assert.assertTrue; import androidx.test.filters.SmallTest; @@ -89,18 +89,20 @@ public class ActivityManagerUtilsTest { } @Test - public void testSheckShouldSamplePackage() { + public void testCheckShouldSamplePackage() { // Just make sure checkShouldSamplePackage is actually working... + assertFailure(() -> checkShouldSamplePackage(0.3f, 0.6f, false, true)); + assertFailure(() -> checkShouldSamplePackage(0.6f, 0.3f, true, false)); + } + + private static void assertFailure(Runnable r) { + boolean failed = false; try { - checkShouldSamplePackage(0.3f, 0.6f, false, true); - fail(); - } catch (AssertionError expected) { - } - try { - checkShouldSamplePackage(0.6f, 0.3f, true, false); - fail(); - } catch (AssertionError expected) { + r.run(); + } catch (AssertionError e) { + failed = true; } + assertTrue(failed); } private void checkShouldSamplePackage(float inputSampleRate, float expectedRate, |