Skip to content

Commit

Permalink
Add unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
droolingsheep committed Feb 5, 2021
1 parent 50b6f47 commit bf7ed3d
Show file tree
Hide file tree
Showing 3 changed files with 151 additions and 77 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import io.reactivex.Observable
import io.reactivex.Scheduler
import io.reactivex.schedulers.Schedulers
import io.reactivex.subjects.BehaviorSubject
import io.reactivex.subjects.Subject
import timber.log.Timber
import java.util.UUID

Expand Down Expand Up @@ -58,15 +57,15 @@ class LinkConfigurationServiceEventListener internal constructor(
private fun getDataSubject(
device: BluetoothDevice,
characteristicUuid: UUID
): Subject<GattCharacteristicSubscriptionStatus> {
): BehaviorSubject<GattCharacteristicSubscriptionStatus> {
return registry[Pair(device, characteristicUuid)] ?: add(device, characteristicUuid)
}

@Synchronized
private fun add(
device: BluetoothDevice,
characteristicUuid: UUID
): Subject<GattCharacteristicSubscriptionStatus> {
): BehaviorSubject<GattCharacteristicSubscriptionStatus> {
val dataSubject =
BehaviorSubject.createDefault(GattCharacteristicSubscriptionStatus.DISABLED)
registry[Pair(device, characteristicUuid)] = dataSubject
Expand Down Expand Up @@ -349,8 +348,7 @@ class LinkConfigurationServiceEventListener internal constructor(
connection: GattServerConnection
) {
if (result.descriptorUuid == CLIENT_CONFIG_UUID) {
val enabledStatus = registry[Pair(device, characteristicUuid)]?.value
val enabledValue = when (enabledStatus) {
val enabledValue = when (getDataSubject(device, characteristicUuid).value) {
GattCharacteristicSubscriptionStatus.ENABLED -> gattServiceSubscribedValue
GattCharacteristicSubscriptionStatus.DISABLED -> gattServiceUnSubscribedValue
null -> null
Expand Down
Loading

0 comments on commit bf7ed3d

Please sign in to comment.