Skip to content

Commit

Permalink
Test setup changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Codel1417 committed Jun 5, 2024
1 parent e465b14 commit 6d2b690
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions test/testing_utils/bluetooth_test_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,23 @@ import 'package:tail_app/Backend/Bluetooth/bluetooth_utils.dart';
import 'bluetooth_test_utils.mocks.dart';

void setupBTMock(String btName, String btMac) {
flutterBluePlus = MockFlutterBluePlusMockable();

when(flutterBluePlus.isSupported).thenAnswer((_) async => true);
when(flutterBluePlus.adapterState).thenAnswer((_) => Stream.fromIterable([BluetoothAdapterState.on]));
when(flutterBluePlus.isScanning).thenAnswer((_) => Stream.fromIterable([false]));
when(flutterBluePlus.isScanningNow).thenAnswer((_) => true);
when(flutterBluePlus.isSupported).thenAnswer((_) async => true);
when(flutterBluePlus.isSupported).thenAnswer((_) async => true);
when(flutterBluePlus.connectedDevices).thenAnswer((_) => [BluetoothDevice(remoteId: DeviceIdentifier(btMac))]);
when(flutterBluePlus.scanResults).thenAnswer((_) =>
MockFlutterBluePlusMockable flutterBluePlusMock = MockFlutterBluePlusMockable();
flutterBluePlus = flutterBluePlusMock;
when(flutterBluePlusMock.isSupported).thenAnswer((_) async => true);
when(flutterBluePlusMock.adapterState).thenAnswer((_) => Stream.fromIterable([BluetoothAdapterState.on]));
when(flutterBluePlusMock.isScanning).thenAnswer((_) => Stream.fromIterable([false]));
when(flutterBluePlusMock.isScanningNow).thenAnswer((_) => true);
when(flutterBluePlusMock.isSupported).thenAnswer((_) async => true);
when(flutterBluePlusMock.isSupported).thenAnswer((_) async => true);
when(flutterBluePlusMock.connectedDevices).thenAnswer((_) => [BluetoothDevice(remoteId: DeviceIdentifier(btMac))]);
when(flutterBluePlusMock.scanResults).thenAnswer((_) =>
Stream.value([ScanResult(rssi: 50, advertisementData: AdvertisementData(advName: btName, txPowerLevel: null, appearance: null, connectable: true, manufacturerData: {}, serviceData: {}, serviceUuids: []), device: BluetoothDevice(remoteId: DeviceIdentifier(btMac)), timeStamp: DateTime.now())]));
when(flutterBluePlus.onScanResults).thenAnswer((_) =>
when(flutterBluePlusMock.onScanResults).thenAnswer((_) =>
Stream.value([ScanResult(rssi: 50, advertisementData: AdvertisementData(advName: btName, txPowerLevel: null, appearance: null, connectable: true, manufacturerData: {}, serviceData: {}, serviceUuids: []), device: BluetoothDevice(remoteId: DeviceIdentifier(btMac)), timeStamp: DateTime.now())]));
when(flutterBluePlus.setLogLevel(LogLevel.warning, color: true)).thenReturn(Future(() {}));
when(flutterBluePlusMock.setLogLevel(any, color: any)).thenReturn(Future(() {}));

BluetoothEvents bluetoothEvents = MockBluetoothEvents();
when(flutterBluePlus.events).thenAnswer((_) => bluetoothEvents);
when(flutterBluePlusMock.events).thenAnswer((_) => bluetoothEvents);
when(bluetoothEvents.onMtuChanged).thenAnswer((_) => Stream.fromIterable([OnMtuChangedEvent(BmMtuChangedResponse(mtu: 50, success: true, remoteId: DeviceIdentifier(btMac)))]));
when(bluetoothEvents.onReadRssi).thenAnswer((_) => Stream.fromIterable([OnReadRssiEvent(BmReadRssiResult(rssi: 50, success: true, remoteId: DeviceIdentifier(btMac), errorCode: 0, errorString: ''))]));
when(bluetoothEvents.onServicesReset).thenAnswer((_) => Stream.fromIterable([OnServicesResetEvent(BmBluetoothDevice(remoteId: DeviceIdentifier(btMac), platformName: btName))]));
Expand Down

0 comments on commit 6d2b690

Please sign in to comment.