Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 0012d539 authored by David Saff's avatar David Saff Committed by Android (Google) Code Review
Browse files

Merge "Better error message when temp files can't be created" into main

parents 86fbc604 1675a0d3
Loading
Loading
Loading
Loading
+26 −0
Original line number Diff line number Diff line
@@ -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;

@@ -49,11 +50,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;
@@ -190,6 +193,7 @@ public abstract class SysuiTestCase {

    @Before
    public void SysuiSetup() throws Exception {
        assertTempFilesAreCreatable();
        ProtoLog.REQUIRE_PROTOLOGTOOL = false;
        mSysuiDependency = new SysuiTestDependency(mContext, shouldFailOnLeakedReceiver());
        mDependency = mSysuiDependency.install();
@@ -211,6 +215,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;
    }