Skip to content

Commit 0fe048a

Browse files
Migrated BleGattExceptionTest.
1 parent e516977 commit 0fe048a

File tree

3 files changed

+43
-24
lines changed

3 files changed

+43
-24
lines changed

rxandroidble/src/test/groovy/com/polidea/rxandroidble2/exceptions/BleGattExceptionTest.groovy

Lines changed: 0 additions & 24 deletions
This file was deleted.
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.polidea.rxandroidble2.exceptions;
2+
3+
import static org.junit.jupiter.api.Assertions.assertEquals;
4+
5+
import android.bluetooth.BluetoothGatt;
6+
7+
import org.junit.jupiter.api.Test;
8+
9+
import utils.MockUtils;
10+
11+
public class BleGattExceptionTest {
12+
13+
@Test
14+
public void toStringShouldContainMessage() {
15+
// given
16+
BluetoothGatt mockBtGatt = MockUtils.bluetoothGatt("AA:BB:CC:DD:EE:FF");
17+
BleGattException out = new BleGattException(mockBtGatt, 10, BleGattOperationType.CONNECTION_STATE);
18+
19+
// expect
20+
assertEquals(out.toString(),
21+
"com.polidea.rxandroidble2.exceptions.BleGattException: GATT exception from MAC='XX:XX:XX:XX:XX:XX', status 10 (GATT_NOT_FOUND), " +
22+
"type BleGattOperation{description='CONNECTION_STATE'}. " +
23+
"(Look up status 0x0a here " +
24+
"https://cs.android.com/android/platform/superproject/+/master:packages/modules/Bluetooth/system/stack/include/gatt_api.h)");
25+
}
26+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package utils;
2+
3+
import android.bluetooth.BluetoothDevice;
4+
import android.bluetooth.BluetoothGatt;
5+
6+
import org.mockito.Mockito;
7+
8+
public class MockUtils {
9+
10+
public static BluetoothGatt bluetoothGatt(String deviceAddress) {
11+
BluetoothGatt bluetoothGatt = Mockito.mock(BluetoothGatt.class);
12+
BluetoothDevice bluetoothDevice = Mockito.mock(BluetoothDevice.class);
13+
Mockito.when(bluetoothGatt.getDevice()).thenReturn(bluetoothDevice);
14+
Mockito.when(bluetoothDevice.getAddress()).thenReturn(deviceAddress);
15+
return bluetoothGatt;
16+
}
17+
}

0 commit comments

Comments
 (0)