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

Commit e53d473b authored by Harry Cutts's avatar Harry Cutts
Browse files

TouchpadDebugView tests: Use TestableContext as a @Rule

This is the way that TestableContext's JavaDoc recommends, to let it
clean up after itself once the test finishes, so we should do it anyway.
However, unfortunately, it doesn't fix b/339924248, where
com.android.test.input.AnrTest fails if it's run after the touchpad
debug view tests.

Bug: 339924248
Test: $ atest \
    InputTests:com.android.server.input.debug.TouchpadDebugViewTest \
    InputTests:com.android.server.input.debug.TouchpadDebugViewControllerTests
Flag: TEST_ONLY
Change-Id: Ia5a480ccbdc05491c7e0bab8c269aa5bd55a205c
parent facb9af4
Loading
Loading
Loading
Loading
+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);