MockBluetoothServer
A behavioral mock implementation of BluetoothServer.
The status, isAdvertising and services flows are backed by MutableStateFlows the test can observe, and the methods are also mocked using the Kaluga mocking library so calls can be verified.
Unlike a purely call-recording mock, add actually builds the requested LocalService graph (via buildCapturingLocalService), stores it in servicesState and captures the per-characteristic read/write actions into reads/writes. This lets a test simulate a connected central reading, writing and subscribing through triggerRead, triggerWrite and subscribe without a live Bluetooth stack or a real BluetoothServer.
Parameters
the initial ServerStatus
if true the mocks are configured with sensible default behaviour
Properties
Mock for add
Mock for advertise
Mock for close
The read actions captured per-descriptor UUID while building services.
The write actions captured per-descriptor UUID while building services.
The MutableStateFlow backing isAdvertising
The read actions captured per-characteristic UUID while building services.
Mock for remove
The MutableStateFlow backing services
The MutableStateFlow backing status
Mock for stopAdvertising
The UUIDs of the characteristics that can be subscribed to.
The write actions captured per-characteristic UUID while building services.
Functions
Simulates a connected central subscribing to characteristic. The characteristic must be a LocalCharacteristic.Notifiable.
Simulates a connected central reading descriptor by invoking the captured descriptor read action.
Simulates a connected central writing value to descriptor by invoking the captured descriptor write action.
Simulates a connected central reading characteristic by invoking the captured read action.
Simulates a connected central writing value to characteristic by invoking the captured write action.