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

Commit 4b6103da authored by Harpreet Eli Sangha's avatar Harpreet Eli Sangha
Browse files

DckTest: Clean-Up GATT Connections in `@After` Method

Test: atest BumbleBluetoothTests
Bug: 315519456
Bug: 315520166
Flag: TEST_ONLY
Change-Id: If3e7f3e1a9d00771766c66b062d9375b2652e0ec
parent 8fb906f9
Loading
Loading
Loading
Loading
+16 −9
Original line number Diff line number Diff line
@@ -30,11 +30,13 @@ import com.google.protobuf.Empty
import io.grpc.Deadline
import java.util.UUID
import java.util.concurrent.TimeUnit
import org.junit.After
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.kotlin.any
import org.mockito.kotlin.argumentCaptor
import org.mockito.kotlin.doAnswer
import org.mockito.kotlin.eq
import org.mockito.kotlin.mock
import org.mockito.kotlin.timeout
@@ -53,7 +55,11 @@ public class DckTest {

    private val scanResultCaptor = argumentCaptor<ScanResult>()
    private val scanCallbackMock = mock<ScanCallback>()
    private val gattCallbackMock = mock<BluetoothGattCallback>()
    private val gattCaptor = argumentCaptor<BluetoothGatt>()
    private val gattCallbackMock =
        mock<BluetoothGattCallback> {
            on { onConnectionStateChange(gattCaptor.capture(), any(), any()) } doAnswer {}
        }

    // A Rule live from a test setup through it's teardown.
    // Gives shell permissions during the test.
@@ -63,6 +69,13 @@ public class DckTest {
    // Acting as a Pandora client, it can be interacted with through the Pandora APIs.
    @Rule @JvmField val mBumble = PandoraDevice()

    @After
    fun tearDown() {
        for (gatt in gattCaptor.allValues.toSet()) {
            gatt.close()
        }
    }

    /**
     * Tests the discovery of the Digital Car Key (DCK) GATT service via Bluetooth on an Android
     * device.
@@ -209,7 +222,7 @@ public class DckTest {

        // Verify successful GATT connection
        val device = scanResult.device
        val gatt = device.connectGatt(context, false, gattCallbackMock)
        device.connectGatt(context, false, gattCallbackMock)
        verify(gattCallbackMock, timeout(TIMEOUT))
            .onConnectionStateChange(
                any(),
@@ -219,9 +232,6 @@ public class DckTest {

        // Stop scan on DUT after GATT connect
        leScanner.stopScan(scanCallbackMock)

        // Clean-Up
        gatt.close()
    }

    /*
@@ -268,16 +278,13 @@ public class DckTest {

        // Verify successful GATT connection
        val device = scanResult.device
        val gatt = device.connectGatt(context, false, gattCallbackMock)
        device.connectGatt(context, false, gattCallbackMock)
        verify(gattCallbackMock, timeout(TIMEOUT))
            .onConnectionStateChange(
                any(),
                eq(BluetoothGatt.GATT_SUCCESS),
                eq(BluetoothProfile.STATE_CONNECTED)
            )

        // Clean-Up
        gatt.close()
    }

    companion object {