Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
avdyushin committed Dec 1, 2023
1 parent 77df749 commit ce34d0f
Showing 1 changed file with 31 additions and 2 deletions.
33 changes: 31 additions & 2 deletions test-utils-bluetooth/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,34 @@ dependencies {
```

## Mocks
This library contains mock classes for `Scanner`, `DeviceConnectionManager`, `AdvertisementData`, `Characteristic`, `Descriptor`, and `BluetoothMonitor`.
In addition use `createDeviceWrapper` and `createServiceWrapper` to generate mocked Device and Service wrappers.
This library contains mock classes for `Scanner`, `DeviceConnectionManager`, `AdvertisementData`, `Characteristic`, `Descriptor`, `BluetoothMonitor`, and `MockDevice`.
In addition use `createDeviceWrapper`, `createServiceWrapper` to generate mocked Device and Service wrappers.

### Using MockDevice

Create mock using `buildMockDevice`:

```kotlin
val device = buildMockDevice(coroutineContext) {
identifier = identifierFromString("1234")!!
manufacturerId = 0xf00d
services {
add(uuidFrom("2345"))
}
connectionDelay = 100.milliseconds
}
```

Simulate connection to the device after given delay (`connectionDelay`) and check connected state afterwords:

```kotlin
device.connect()
device.state.firstInstance<ConnectableDeviceState.Connected>()
```

Disconnect from the device:

```kotlin
device.disconnect()
device.state.firstInstance<ConnectableDeviceState.Disconnected>()
```

0 comments on commit ce34d0f

Please sign in to comment.