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

Commit f0239bfe authored by Ben Reich's avatar Ben Reich
Browse files

Introduce @Before / @After to ActivityTestJunit4

These annotations run in sequence from the highest superclass to the
implementation [1]. So ActivityTestJunit4 will run its @Before first
then the actual test class will run their own @Before method. This
means we can omit the explicit super.setUp implementations throughout
and rely on the annotations directly.

[1] https://junit.org/junit4/javadoc/latest/org/junit/Before.html

Bug: 383932124
Test: atest DocumentsUIGoogleTests
Flag: EXEMPT test change
Change-Id: I526d7873b6f76b54254d61e28c9ff627223776d5
parent 10694e02
Loading
Loading
Loading
Loading
+6 −4
Original line number Diff line number Diff line
@@ -37,6 +37,8 @@ import com.android.documentsui.bots.Bots
import com.android.documentsui.files.FilesActivity
import java.io.IOException
import java.util.Objects
import org.junit.After
import org.junit.Before

/**
 * Provides basic test environment for UI tests:
@@ -98,8 +100,8 @@ abstract class ActivityTestJunit4<T : Activity?> {
        this.initialRoot = rootDir0
    }

    @Throws(Exception::class)
    open fun setUp() {
    @Before
    fun setUp() {
        device = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())
        // NOTE: Must be the "target" context, else security checks in content provider will fail.
        context = InstrumentationRegistry.getInstrumentation().getTargetContext()
@@ -137,8 +139,8 @@ abstract class ActivityTestJunit4<T : Activity?> {
        mDocsHelper!!.configure(null, Bundle.EMPTY)
    }

    @Throws(Exception::class)
    open fun tearDown() {
    @After
    fun tearDown() {
        device!!.unfreezeRotation()
        mDocsHelper!!.cleanUp()
        restoreScreenOffAndSleepTimeouts()
+2 −3
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package com.android.documentsui;

import static com.android.documentsui.flags.Flags.FLAG_USE_SEARCH_V2_READ_ONLY;

import android.os.RemoteException;
import android.platform.test.annotations.RequiresFlagsDisabled;
import android.platform.test.annotations.RequiresFlagsEnabled;
import android.platform.test.flag.junit.CheckFlagsRule;
@@ -37,10 +38,8 @@ public class ArchiveUiTest extends ActivityTestJunit4<FilesActivity> {
    @Rule
    public final CheckFlagsRule mCheckFlagsRule = DeviceFlagsValueProvider.createCheckFlagsRule();


    @Before
    public void setUp() throws Exception {
        super.setUp();
    public void setUpTest() throws RemoteException {
        initTestFiles();
    }

+0 −12
Original line number Diff line number Diff line
@@ -33,8 +33,6 @@ import com.android.documentsui.base.RootInfo;
import com.android.documentsui.files.FilesActivity;
import com.android.documentsui.filters.HugeLongTest;

import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -46,16 +44,6 @@ public class FilesActivityDefaultsUiTest extends ActivityTestJunit4<FilesActivit
    @Rule
    public final CheckFlagsRule mCheckFlagsRule = DeviceFlagsValueProvider.createCheckFlagsRule();

    @Before
    public void setUp() throws Exception {
        super.setUp();
    }

    @After
    public void tearDown() throws Exception {
        super.tearDown();
    }

    @Override
    protected void initTestFiles() {
        // Overriding to init with no items in test roots
+1 −8
Original line number Diff line number Diff line
@@ -46,7 +46,6 @@ import com.android.documentsui.files.FilesActivity;
import com.android.documentsui.filters.HugeLongTest;
import com.android.documentsui.inspector.InspectorActivity;

import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
@@ -60,16 +59,10 @@ public class FilesActivityUiTest extends ActivityTestJunit4<FilesActivity> {
    public final CheckFlagsRule mCheckFlagsRule = DeviceFlagsValueProvider.createCheckFlagsRule();

    @Before
    public void setUp() throws Exception {
        super.setUp();
    public void setUpTest() throws RemoteException {
        initTestFiles();
    }

    @After
    public void tearDown() throws Exception {
        super.tearDown();
    }

    @Override
    public void initTestFiles() throws RemoteException {
        Uri uri = mDocsHelper.createFolder(rootDir0, dirName1);
+0 −12
Original line number Diff line number Diff line
@@ -43,8 +43,6 @@ import com.android.documentsui.testing.MutableJobProgress
import org.hamcrest.Description
import org.hamcrest.Matcher
import org.hamcrest.Matchers.allOf
import org.junit.After
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
@@ -79,16 +77,6 @@ class JobPanelUiTest : ActivityTestJunit4<FilesActivity>() {
        context.sendBroadcast(intent)
    }

    @Before
    override fun setUp() {
        super.setUp()
    }

    @After
    override fun tearDown() {
        super.tearDown()
    }

    @Test
    fun testJobPanelAppearsOnClick() {
        onView(withId(R.id.option_menu_job_progress)).check(doesNotExist())
Loading