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

Commit bbdfd79b authored by Makoto Onuki's avatar Makoto Onuki Committed by Android (Google) Code Review
Browse files

Merge "Add / fix a few tests" into main

parents de007d17 570de736
Loading
Loading
Loading
Loading
+10 −2
Original line number Diff line number Diff line
@@ -16,9 +16,11 @@
package com.android.ravenwoodtest.coretest;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;

import android.app.ActivityThread;
import android.content.Context;
import android.platform.test.annotations.DisabledOnRavenwood;

import androidx.test.platform.app.InstrumentationRegistry;

@@ -30,8 +32,14 @@ public class RavenwoodActivityThreadTest {

    @Test
    public void testActivityThreadCurrentSystemContext() {
        assertEquals(ActivityThread.currentSystemContext().getPackageName(),
                sContext.getPackageName());
        assertNotNull(ActivityThread.currentSystemContext());
    }

    @Test
    @DisabledOnRavenwood(
            reason = "ravenwood just returns a package context as system context for now")
    public void testActivityThreadCurrentSystemContextPackage() {
        assertEquals("android", ActivityThread.currentSystemContext().getPackageName());
    }

    @Test
+6 −0
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ import static com.google.common.truth.Truth.assertThat;

import android.app.ActivityManager;
import android.platform.test.ravenwood.RavenwoodRule;
import android.platform.test.ravenwood.RavenwoodUtils;

import com.android.dx.mockito.inline.extended.ExtendedMockito;

@@ -39,6 +40,11 @@ public class RavenwoodMockitoDeviceOnlyTest {
            ExtendedMockito.doReturn(true).when(ActivityManager::isUserAMonkey);

            assertThat(ActivityManager.isUserAMonkey()).isEqualTo(true);

            // Extended mockito's static mocking works on any threads.
            RavenwoodUtils.runOnMainThreadSync(() -> {
                assertThat(ActivityManager.isUserAMonkey()).isEqualTo(true);
            });
        } finally {
            mockingSession.finishMocking();
        }
+7 −0
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ import static com.google.common.truth.Truth.assertThat;

import android.app.ActivityManager;
import android.platform.test.ravenwood.RavenwoodRule;
import android.platform.test.ravenwood.RavenwoodUtils;

import org.junit.Rule;
import org.junit.Test;
@@ -33,6 +34,12 @@ public class RavenwoodMockitoRavenwoodOnlyTest {
        try (MockedStatic<ActivityManager> am = Mockito.mockStatic(ActivityManager.class)) {
            am.when(ActivityManager::isUserAMonkey).thenReturn(true);
            assertThat(ActivityManager.isUserAMonkey()).isEqualTo(true);

            // Mockito's static mocking only works on the current thread.
            // (unlike ExtendedMockito's)
            RavenwoodUtils.runOnMainThreadSync(() -> {
                assertThat(ActivityManager.isUserAMonkey()).isEqualTo(false);
            });
        }
    }
}