simulateConnectionFailure method
void
simulateConnectionFailure(
- String deviceAddress,
- BleConnectionFailure failure, {
- BleConnectionState state = BleConnectionState.failed,
Simulates a connection failure by emitting a failure event on the connection stream.
This lets tests exercise the failure-handling path introduced with BleConnectionEvent. The emitted event uses
the given state (defaulting to BleConnectionState.failed) and carries the provided failure detail. The
device's snapshot state (as returned by getCurrentConnectionState) is also updated to state.
Example usage:
fakeCentral.simulateConnectionFailure(
'00:11:22:33:44:55',
const BleConnectionFailure(category: BleConnectionFailureCategory.timeout),
);
- Parameter
deviceAddress: The device whose connection stream should emit the failure. - Parameter
failure: The failure detail to attach to the emitted event. - Parameter
state: The connection state to report with the failure. Defaults to BleConnectionState.failed.
Implementation
void simulateConnectionFailure(
String deviceAddress,
BleConnectionFailure failure, {
BleConnectionState state = BleConnectionState.failed,
}) {
_connectionStates[deviceAddress] = state;
_connectionControllers[deviceAddress]?.add(
BleConnectionEvent(state: state, failure: failure),
);
}