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

Commit c5e46b3f authored by William Escande's avatar William Escande
Browse files

GattClientTest: User wrapper in all test

This is fixing some test not disconnecting before closing and this will
ensure that all the test are properly closing the gatt instance

Bug: 311772251
Test: atest BumbleBluetoothTests
Change-Id: Ic7a13a93255e9f853dd8b7544a71b4b1fcfb8617
parent 9983f693
Loading
Loading
Loading
Loading
+5 −21
Original line number Diff line number Diff line
@@ -100,25 +100,9 @@ public class GattClientTest {

    @Test
    public void fullGattClientLifecycle() throws Exception {
        advertiseWithBumble();

        BluetoothDevice device =
                mAdapter.getRemoteLeDevice(
                        Utils.BUMBLE_RANDOM_ADDRESS, BluetoothDevice.ADDRESS_TYPE_RANDOM);

        for (int i = 0; i < 10; i++) {
        BluetoothGattCallback gattCallback = mock(BluetoothGattCallback.class);
            BluetoothGatt gatt = device.connectGatt(mContext, false, gattCallback);
            verify(gattCallback, timeout(1000))
                    .onConnectionStateChange(any(), anyInt(), eq(BluetoothProfile.STATE_CONNECTED));

            gatt.disconnect();
            verify(gattCallback, timeout(1000))
                    .onConnectionStateChange(
                            any(), anyInt(), eq(BluetoothProfile.STATE_DISCONNECTED));

            gatt.close();
        }
        BluetoothGatt gatt = connectGattAndWaitConnection(gattCallback);
        disconnectAndWaitDisconnection(gatt, gattCallback);
    }

    @Test
@@ -179,9 +163,9 @@ public class GattClientTest {

    private void disconnectAndWaitDisconnection(
            BluetoothGatt gatt, BluetoothGattCallback callback) {
        final int state = BluetoothProfile.STATE_DISCONNECTED;
        gatt.disconnect();
        verify(callback, timeout(1000))
                .onConnectionStateChange(any(), anyInt(), eq(BluetoothProfile.STATE_DISCONNECTED));
        verify(callback, timeout(1000)).onConnectionStateChange(eq(gatt), anyInt(), eq(state));

        gatt.close();
        gatt = null;