Move expectFail to TestUtil

Flag: NA
Bug: 298234173
Test: atest TaplWorkspaceTest
Change-Id: I7aadab92891ecdb9e8910601a6e1b417ffa5f605
This commit is contained in:
Sebastian Franco
2023-11-30 11:56:43 -06:00
parent 0734ef2d7c
commit 38e8f83392
3 changed files with 14 additions and 13 deletions
@@ -15,7 +15,7 @@
*/
package com.android.launcher3.allapps;
import static com.android.launcher3.ui.TaplTestsLauncher3.expectFail;
import static com.android.launcher3.util.TestUtil.expectFail;
import static com.android.launcher3.ui.AbstractLauncherUiTest.initialize;
import static org.junit.Assert.assertEquals;
@@ -17,7 +17,6 @@
package com.android.launcher3.ui;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import androidx.test.filters.LargeTest;
import androidx.test.runner.AndroidJUnit4;
@@ -36,17 +35,6 @@ public class TaplTestsLauncher3 extends AbstractLauncherUiTest {
initialize(this);
}
// Please don't add negative test cases for methods that fail only after a long wait.
public static void expectFail(String message, Runnable action) {
boolean failed = false;
try {
action.run();
} catch (AssertionError e) {
failed = true;
}
assertTrue(message, failed);
}
@Test
public void testDevicePressMenu() throws Exception {
mDevice.pressMenu();
@@ -24,6 +24,8 @@ import static com.android.launcher3.LauncherSettings.Settings.LAYOUT_DIGEST_KEY;
import static com.android.launcher3.LauncherSettings.Settings.LAYOUT_DIGEST_LABEL;
import static com.android.launcher3.LauncherSettings.Settings.LAYOUT_DIGEST_TAG;
import static org.junit.Assert.assertTrue;
import android.app.Instrumentation;
import android.app.blob.BlobHandle;
import android.app.blob.BlobStoreManager;
@@ -252,6 +254,17 @@ public class TestUtil {
}
}
// Please don't add negative test cases for methods that fail only after a long wait.
public static void expectFail(String message, Runnable action) {
boolean failed = false;
try {
action.run();
} catch (AssertionError e) {
failed = true;
}
assertTrue(message, failed);
}
/** Interface to indicate a runnable which can throw any exception. */
public interface UncheckedRunnable {
/** Method to run the task */