summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author David Saff <david@saff.net> 2025-03-06 13:12:30 -0500
committer David Saff <david@saff.net> 2025-03-12 14:21:09 -0400
commit1675a0d3c96091aff47fe466a9fb1c98a8870a03 (patch)
tree412fc705c55b96a6809ae45d9b111b0f0e83196e
parentebf848a5a4e9ce67f71c5a574688afdb79360975 (diff)
Better error message when temp files can't be created
Bug: 391948934 Test: local and presubmit Flag: TEST_ONLY Change-Id: I019bbe5266fd3143f870ade30d9e6ed3185ab4e2
-rw-r--r--packages/SystemUI/tests/utils/src/com/android/systemui/SysuiTestCase.java26
1 files changed, 26 insertions, 0 deletions
diff --git a/packages/SystemUI/tests/utils/src/com/android/systemui/SysuiTestCase.java b/packages/SystemUI/tests/utils/src/com/android/systemui/SysuiTestCase.java
index e550e88b7bc7..6b2864fc5136 100644
--- a/packages/SystemUI/tests/utils/src/com/android/systemui/SysuiTestCase.java
+++ b/packages/SystemUI/tests/utils/src/com/android/systemui/SysuiTestCase.java
@@ -15,6 +15,7 @@
*/
package com.android.systemui;
+import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;
@@ -50,11 +51,13 @@ import com.android.systemui.log.LogWtfHandlerRule;
import org.junit.After;
import org.junit.AfterClass;
+import org.junit.Assert;
import org.junit.Before;
import org.junit.ClassRule;
import org.junit.Rule;
import org.mockito.Mockito;
+import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.lang.annotation.Retention;
@@ -208,6 +211,7 @@ public abstract class SysuiTestCase {
@Before
public void SysuiSetup() throws Exception {
+ assertTempFilesAreCreatable();
ProtoLog.REQUIRE_PROTOLOGTOOL = false;
mSysuiDependency = new SysuiTestDependency(mContext, shouldFailOnLeakedReceiver());
mDependency = mSysuiDependency.install();
@@ -229,6 +233,28 @@ public abstract class SysuiTestCase {
}
}
+ private static Boolean sCanCreateTempFiles = null;
+
+ private static void assertTempFilesAreCreatable() {
+ // TODO(b/391948934): hopefully remove this hack
+ if (sCanCreateTempFiles == null) {
+ try {
+ File tempFile = File.createTempFile("confirm_temp_file_createable", "txt");
+ sCanCreateTempFiles = true;
+ assertTrue(tempFile.delete());
+ } catch (IOException e) {
+ sCanCreateTempFiles = false;
+ throw new RuntimeException(e);
+ }
+ }
+ if (!sCanCreateTempFiles) {
+ Assert.fail(
+ "Cannot create temp files, so mockito will probably fail (b/391948934). Temp"
+ + " folder should be: "
+ + System.getProperty("java.io.tmpdir"));
+ }
+ }
+
protected boolean shouldFailOnLeakedReceiver() {
return false;
}