@@ -325,9 +325,7 @@ class CoroutinesGattTest {
325
325
createDispatcher().use { dispatcher ->
326
326
val bluetoothGatt = mockk<BluetoothGatt > {
327
327
every { readCharacteristic(any()) } returns false
328
- every<BluetoothDevice ?> { device } returns mockk {
329
- every { this @mockk.toString() } returns " 00:11:22:33:FF:EE"
330
- }
328
+ every<BluetoothDevice ?> { device } returns createBluetoothDevice()
331
329
}
332
330
val callback = GattCallback (dispatcher)
333
331
val gatt = CoroutinesGatt (bluetoothGatt, dispatcher, callback)
@@ -373,9 +371,7 @@ class CoroutinesGattTest {
373
371
val callback = GattCallback (dispatcher)
374
372
val bluetoothGatt = mockk<BluetoothGatt > {
375
373
every { close() } returns Unit
376
- every { device } returns mockk {
377
- every { this @mockk.toString() } returns " 00:11:22:33:FF:EE"
378
- }
374
+ every { device } returns createBluetoothDevice()
379
375
every { disconnect() } answers {
380
376
callback.onConnectionStateChange(this @mockk, GATT_SUCCESS , STATE_DISCONNECTING )
381
377
callback.onConnectionStateChange(this @mockk, GATT_SUCCESS , STATE_DISCONNECTED )
@@ -397,9 +393,7 @@ class CoroutinesGattTest {
397
393
val callback = GattCallback (dispatcher)
398
394
val bluetoothGatt = mockk<BluetoothGatt > {
399
395
every { close() } returns Unit
400
- every { device } returns mockk {
401
- every { this @mockk.toString() } returns " 00:11:22:33:FF:EE"
402
- }
396
+ every { device } returns createBluetoothDevice()
403
397
every { disconnect() } answers {
404
398
callback.onConnectionStateChange(this @mockk, GATT_SUCCESS , STATE_DISCONNECTING )
405
399
}
@@ -425,11 +419,12 @@ class CoroutinesGattTest {
425
419
val callback = GattCallback (dispatcher)
426
420
val bluetoothGatt = mockk<BluetoothGatt > {
427
421
every { close() } returns Unit
428
- every { device } returns mockk {
429
- every { this @mockk.toString() } returns " 00:11:22:33:FF:EE"
430
- }
422
+ every { device } returns createBluetoothDevice()
431
423
}
432
- val characteristic = FakeCharacteristic (testUuid, value = byteArrayOf(0xF , 0x0 , 0x0 , 0xD ))
424
+ val characteristic = FakeCharacteristic (
425
+ testUuid,
426
+ value = byteArrayOf(0xF , 0x0 , 0x0 , 0xD )
427
+ )
433
428
val gatt = CoroutinesGatt (bluetoothGatt, dispatcher, callback)
434
429
435
430
val events = runBlocking {
@@ -463,9 +458,7 @@ class CoroutinesGattTest {
463
458
val callback = GattCallback (dispatcher)
464
459
val bluetoothGatt = mockk<BluetoothGatt > {
465
460
every { close() } returns Unit
466
- every { device } returns mockk {
467
- every { this @mockk.toString() } returns " 00:11:22:33:FF:EE"
468
- }
461
+ every { device } returns createBluetoothDevice()
469
462
}
470
463
val gatt = CoroutinesGatt (bluetoothGatt, dispatcher, callback)
471
464
@@ -488,9 +481,7 @@ class CoroutinesGattTest {
488
481
val callback = GattCallback (dispatcher)
489
482
val bluetoothGatt = mockk<BluetoothGatt > {
490
483
every { close() } returns Unit
491
- every { device } returns mockk {
492
- every { this @mockk.toString() } returns " 00:11:22:33:FF:EE"
493
- }
484
+ every { device } returns createBluetoothDevice()
494
485
every { readCharacteristic(any()) } answers {
495
486
callback.onConnectionStateChange(this @mockk, GATT_SUCCESS , STATE_DISCONNECTED )
496
487
true
@@ -520,9 +511,7 @@ class CoroutinesGattTest {
520
511
val callback = GattCallback (dispatcher)
521
512
val bluetoothGatt = mockk<BluetoothGatt > {
522
513
every { close() } returns Unit
523
- every { device } returns mockk {
524
- every { this @mockk.toString() } returns " 00:11:22:33:FF:EE"
525
- }
514
+ every { device } returns createBluetoothDevice()
526
515
every { readCharacteristic(any()) } answers {
527
516
didReadCharacteristic.offer(Unit )
528
517
true
@@ -554,6 +543,10 @@ private val dispatcherNumber = AtomicInteger()
554
543
private fun createDispatcher () =
555
544
newSingleThreadContext(" MockGatt${dispatcherNumber.incrementAndGet()} " )
556
545
546
+ private fun createBluetoothDevice (): BluetoothDevice = mockk {
547
+ every { this @mockk.toString() } returns " 00:11:22:33:FF:EE"
548
+ }
549
+
557
550
private fun createCharacteristic (
558
551
uuid : UUID = testUuid,
559
552
data : ByteArray = byteArrayOf()
0 commit comments