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

Commit 411af4be authored by Harry Cutts's avatar Harry Cutts Committed by Android (Google) Code Review
Browse files

Merge changes I53b40671,Ia5a480cc into main

* changes:
  BatteryControllerTests: create TestableContext as a @Rule
  TouchpadDebugView tests: Use TestableContext as a @Rule
parents ff5962db 45f86b77
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -184,6 +184,8 @@ class BatteryControllerTests {
    @get:Rule
    val rule = MockitoJUnit.rule()!!
    @get:Rule
    val context = TestableContext(ApplicationProvider.getApplicationContext())
    @get:Rule
    val inputManagerRule = MockInputManagerRule()

    @Mock
@@ -194,7 +196,6 @@ class BatteryControllerTests {
    private lateinit var bluetoothBatteryManager: BluetoothBatteryManager

    private lateinit var batteryController: BatteryController
    private lateinit var context: TestableContext
    private lateinit var testLooper: TestLooper
    private lateinit var devicesChangedListener: IInputDevicesChangedListener
    private lateinit var inputManagerGlobalSession: InputManagerGlobal.TestSession
@@ -202,7 +203,6 @@ class BatteryControllerTests {

    @Before
    fun setup() {
        context = TestableContext(ApplicationProvider.getApplicationContext())
        testLooper = TestLooper()
        val inputManager = InputManager(context)
        context.addMockSystemService(InputManager::class.java, inputManager)
+4 −4
Original line number Diff line number Diff line
@@ -23,7 +23,6 @@ import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

import android.content.Context;
import android.graphics.Rect;
import android.hardware.input.InputManager;
import android.testing.AndroidTestingRunner;
@@ -59,10 +58,13 @@ public class TouchpadDebugViewControllerTests {
    private static final int DEVICE_ID = 1000;
    private static final String TAG = "TouchpadDebugViewController";

    @Rule
    public final TestableContext mTestableContext =
            new TestableContext(InstrumentationRegistry.getInstrumentation().getContext());

    @Rule
    public final MockitoRule mockito = MockitoJUnit.rule();

    private Context mContext;
    private TouchpadDebugViewController mTouchpadDebugViewController;
    @Mock
    private InputManager mInputManagerMock;
@@ -74,8 +76,6 @@ public class TouchpadDebugViewControllerTests {

    @Before
    public void setup() throws Exception {
        mContext = InstrumentationRegistry.getInstrumentation().getContext();
        TestableContext mTestableContext = new TestableContext(mContext);
        mTestableContext.addMockSystemService(WindowManager.class, mWindowManagerMock);

        Rect bounds = new Rect(0, 0, 2560, 1600);
+5 −5
Original line number Diff line number Diff line
@@ -26,7 +26,6 @@ import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

import android.content.Context;
import android.graphics.Color;
import android.graphics.Rect;
import android.graphics.drawable.ColorDrawable;
@@ -51,6 +50,7 @@ import com.android.server.input.TouchpadHardwareProperties;
import com.android.server.input.TouchpadHardwareState;

import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
@@ -70,6 +70,10 @@ public class TouchpadDebugViewTest {
    private TouchpadDebugView mTouchpadDebugView;
    private WindowManager.LayoutParams mWindowLayoutParams;

    @Rule
    public final TestableContext mTestableContext =
            new TestableContext(InstrumentationRegistry.getInstrumentation().getContext());

    @Mock
    WindowManager mWindowManager;
    @Mock
@@ -77,14 +81,10 @@ public class TouchpadDebugViewTest {

    Rect mWindowBounds;
    WindowMetrics mWindowMetrics;
    TestableContext mTestableContext;

    @Before
    public void setUp() {
        MockitoAnnotations.initMocks(this);
        Context context = InstrumentationRegistry.getInstrumentation().getContext();
        mTestableContext = new TestableContext(context);

        mTestableContext.addMockSystemService(WindowManager.class, mWindowManager);
        mTestableContext.addMockSystemService(InputManager.class, mInputManager);