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

Commit d35174bd authored by David Saff's avatar David Saff
Browse files

Prevent mockito initialization issue in ScreenshotViewModelTest

When this test runs first, we haven't yet done the check in waitUntilMockitoCanBeInitialized,
so for now, we need to run that first.  (This doesn't necessarily scale,
so hoping on a better solution for b/404544974 eventually)

Bug: 414420481
Test: ScreenshotViewModelTest
Flag: TEST_ONLY
Change-Id: I99fc2cfbd8644757c2d82f7a7575d94b309b65f1
parent b6ac14b3
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ package com.android.systemui.screenshot.ui.viewmodel
import android.view.accessibility.AccessibilityManager
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.SmallTest
import com.android.systemui.SysuiTestCase
import com.google.common.truth.Truth.assertThat
import org.junit.Test
import org.junit.runner.RunWith
@@ -79,4 +80,10 @@ class ScreenshotViewModelTest {
        assertThat(updated.appearance).isEqualTo(otherAppearance)
        assertThat(updated.onClicked).isEqualTo(onclick)
    }

    companion object {
        init {
            SysuiTestCase.waitUntilMockitoCanBeInitialized()
        }
    }
}
+11 −1
Original line number Diff line number Diff line
@@ -193,7 +193,7 @@ public abstract class SysuiTestCase {
    private SysuiTestDependency mSysuiDependency;

    static {
        assertTempFilesAreCreatable();
        waitUntilMockitoCanBeInitialized();
    }

    @Before
@@ -219,6 +219,16 @@ public abstract class SysuiTestCase {
        }
    }

    /**
     * Due to b/404544974, it is possible for a test process to start without access to its
     * temp folder, and then gain access later.  Mockito cannot initialize (b/391948934) if the
     * temp folder is not writeable, so calling this method allows a test not to proceed until
     * mockito will be workable.
     */
    public static void waitUntilMockitoCanBeInitialized() {
        assertTempFilesAreCreatable();
    }

    private static Boolean sCanCreateTempFiles = null;
    private static void assertTempFilesAreCreatable() throws RuntimeException {
        // TODO(b/391948934): hopefully remove this hack