Skip to content

Commit

Permalink
Migrated BleGattExceptionTest.
Browse files Browse the repository at this point in the history
  • Loading branch information
dariuszseweryn committed Mar 17, 2024
1 parent e516977 commit 0fe048a
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 24 deletions.

This file was deleted.

@@ -0,0 +1,26 @@
package com.polidea.rxandroidble2.exceptions;

import static org.junit.jupiter.api.Assertions.assertEquals;

import android.bluetooth.BluetoothGatt;

import org.junit.jupiter.api.Test;

import utils.MockUtils;

public class BleGattExceptionTest {

@Test
public void toStringShouldContainMessage() {
// given
BluetoothGatt mockBtGatt = MockUtils.bluetoothGatt("AA:BB:CC:DD:EE:FF");
BleGattException out = new BleGattException(mockBtGatt, 10, BleGattOperationType.CONNECTION_STATE);

// expect
assertEquals(out.toString(),
"com.polidea.rxandroidble2.exceptions.BleGattException: GATT exception from MAC='XX:XX:XX:XX:XX:XX', status 10 (GATT_NOT_FOUND), " +
"type BleGattOperation{description='CONNECTION_STATE'}. " +
"(Look up status 0x0a here " +
"https://cs.android.com/android/platform/superproject/+/master:packages/modules/Bluetooth/system/stack/include/gatt_api.h)");
}
}
17 changes: 17 additions & 0 deletions rxandroidble/src/test/java/utils/MockUtils.java
@@ -0,0 +1,17 @@
package utils;

import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothGatt;

import org.mockito.Mockito;

public class MockUtils {

public static BluetoothGatt bluetoothGatt(String deviceAddress) {
BluetoothGatt bluetoothGatt = Mockito.mock(BluetoothGatt.class);
BluetoothDevice bluetoothDevice = Mockito.mock(BluetoothDevice.class);
Mockito.when(bluetoothGatt.getDevice()).thenReturn(bluetoothDevice);
Mockito.when(bluetoothDevice.getAddress()).thenReturn(deviceAddress);
return bluetoothGatt;
}
}

0 comments on commit 0fe048a

Please sign in to comment.