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

Commit 45f86b77 authored by Harry Cutts's avatar Harry Cutts
Browse files

BatteryControllerTests: create 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, it won't fix b/339924248 on its own.

Bug: 339924248
Test: $ atest InputTests:com.android.server.input.BatteryControllerTests
Flag: TEST_ONLY
Change-Id: I53b40671286530a7c411cfff6bc08239f5baf13b
parent e53d473b
Loading
Loading
Loading
Loading
+2 −2
Original line number Original line Diff line number Diff line
@@ -184,6 +184,8 @@ class BatteryControllerTests {
    @get:Rule
    @get:Rule
    val rule = MockitoJUnit.rule()!!
    val rule = MockitoJUnit.rule()!!
    @get:Rule
    @get:Rule
    val context = TestableContext(ApplicationProvider.getApplicationContext())
    @get:Rule
    val inputManagerRule = MockInputManagerRule()
    val inputManagerRule = MockInputManagerRule()


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


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


    @Before
    @Before
    fun setup() {
    fun setup() {
        context = TestableContext(ApplicationProvider.getApplicationContext())
        testLooper = TestLooper()
        testLooper = TestLooper()
        val inputManager = InputManager(context)
        val inputManager = InputManager(context)
        context.addMockSystemService(InputManager::class.java, inputManager)
        context.addMockSystemService(InputManager::class.java, inputManager)