@@ -19,6 +19,11 @@ void main() {
19
19
20
20
const PERIPHERAL_NAME = 'Peripheral name' ;
21
21
const PERIPHERAL_ID = 'peripheral id' ;
22
+ const SERVICE_UUID = 's1' ;
23
+ const CHARACTERISTIC_UUID = 'c1' ;
24
+ const TRANSACTION_ID = 't1' ;
25
+ const DESCRIPTOR_UUID = "d1" ;
26
+
22
27
23
28
ManagerForPeripheralMock managerForPeripheral;
24
29
TransactionIdGeneratorMock transactionIdGeneratorMock;
@@ -128,14 +133,11 @@ void main() {
128
133
129
134
group ("Discovery" , () {
130
135
test ("use given transactionId" , () async {
131
- //given
132
- const transactionId = "86791384-" ;
133
-
134
136
//when
135
- await peripheral.discoverAllServicesAndCharacteristics (transactionId: transactionId );
137
+ await peripheral.discoverAllServicesAndCharacteristics (transactionId: TRANSACTION_ID );
136
138
137
139
//then
138
- verify (managerForPeripheral.discoverAllServicesAndCharacteristics (any, transactionId ));
140
+ verify (managerForPeripheral.discoverAllServicesAndCharacteristics (any, TRANSACTION_ID ));
139
141
});
140
142
141
143
test ("use generated transactionId" , () async {
@@ -171,11 +173,10 @@ void main() {
171
173
test ("should return characteristic for given service" , () async {
172
174
//given
173
175
List <Characteristic > characteristics = [CharacteristicMock (), CharacteristicMock ()];
174
- const serviceUuid = "123uuid" ;
175
- when (managerForPeripheral.characteristics (any, serviceUuid)).thenAnswer ((_) => Future .value (characteristics));
176
+ when (managerForPeripheral.characteristics (any, SERVICE_UUID )).thenAnswer ((_) => Future .value (characteristics));
176
177
177
178
//when
178
- List <Characteristic > fetchedCharacteristic = await peripheral.characteristics (serviceUuid );
179
+ List <Characteristic > fetchedCharacteristic = await peripheral.characteristics (SERVICE_UUID );
179
180
180
181
//then
181
182
expect (fetchedCharacteristic, characteristics);
@@ -212,17 +213,14 @@ void main() {
212
213
test ("should write value to characteristic" , () async {
213
214
//given
214
215
CharacteristicWithValue mockedCharacteristicWithValue = CharacteristicWithValueMock ();
215
- const serviceUuid = 's1' ;
216
- const characteristicUuid = 'c1' ;
217
- const transactionId = 't1' ;
218
216
Uint8List value = Uint8List .fromList ([1 , 4 , 9 ]);
219
217
const withResponse = false ;
220
218
221
- when (managerForPeripheral.writeCharacteristicForDevice (any, serviceUuid, characteristicUuid , value, withResponse, transactionId ))
219
+ when (managerForPeripheral.writeCharacteristicForDevice (any, SERVICE_UUID , CHARACTERISTIC_UUID , value, withResponse, TRANSACTION_ID ))
222
220
.thenAnswer ((_) => Future .value (mockedCharacteristicWithValue));
223
221
224
222
//when
225
- CharacteristicWithValue characteristicWithValue = await peripheral.writeCharacteristic (serviceUuid, characteristicUuid , value, withResponse, transactionId: transactionId );
223
+ CharacteristicWithValue characteristicWithValue = await peripheral.writeCharacteristic (SERVICE_UUID , CHARACTERISTIC_UUID , value, withResponse, transactionId: TRANSACTION_ID );
226
224
227
225
//then
228
226
expect (characteristicWithValue, mockedCharacteristicWithValue);
@@ -249,14 +247,11 @@ void main() {
249
247
CharacteristicWithValueMock (),
250
248
CharacteristicWithValueMock ()
251
249
];
252
- const serviceUuid = 's1' ;
253
- const characteristicUuid = 'c1' ;
254
- const transactionId = 't1' ;
255
- when (managerForPeripheral.monitorCharacteristicForDevice (any, serviceUuid, characteristicUuid, transactionId))
250
+ when (managerForPeripheral.monitorCharacteristicForDevice (any, SERVICE_UUID , CHARACTERISTIC_UUID , TRANSACTION_ID ))
256
251
.thenAnswer ((_) => Stream .fromIterable (emittedValues));
257
252
258
253
//when
259
- Stream <CharacteristicWithValue > characteristicsStream = peripheral.monitorCharacteristic (serviceUuid, characteristicUuid , transactionId: transactionId );
254
+ Stream <CharacteristicWithValue > characteristicsStream = peripheral.monitorCharacteristic (SERVICE_UUID , CHARACTERISTIC_UUID , transactionId: TRANSACTION_ID );
260
255
261
256
//then
262
257
expect (characteristicsStream, emitsInOrder (emittedValues));
@@ -341,12 +336,10 @@ void main() {
341
336
test ("should return desriptors of characteristic" , () async {
342
337
//given
343
338
List <Descriptor > descriptors = [DescriptorMock (), DescriptorMock ()];
344
- const serviceUuid = "123uuid" ;
345
- const characteristicUuid = "c1" ;
346
- when (managerForPeripheral.descriptorsForPeripheral (any, serviceUuid, characteristicUuid)).thenAnswer ((_) => Future .value (descriptors));
339
+ when (managerForPeripheral.descriptorsForPeripheral (any, SERVICE_UUID , CHARACTERISTIC_UUID )).thenAnswer ((_) => Future .value (descriptors));
347
340
348
341
//when
349
- List <Descriptor > fetchedDescriptors = await peripheral.descriptorsForCharacteristic (serviceUuid, characteristicUuid );
342
+ List <Descriptor > fetchedDescriptors = await peripheral.descriptorsForCharacteristic (SERVICE_UUID , CHARACTERISTIC_UUID );
350
343
351
344
//then
352
345
expect (fetchedDescriptors, descriptors);
@@ -355,15 +348,12 @@ void main() {
355
348
test ("should return Descriptor value" , () async {
356
349
//given
357
350
DescriptorWithValue descriptorWithValue = DescriptorWithValueMock ();
358
- const serviceUuid = "123uuid" ;
359
- const characteristicUuid = "c1" ;
360
- const descriptorUuid = "c1" ;
361
351
const transactionId = "t1" ;
362
- when (managerForPeripheral.readDescriptorForPeripheral (any, serviceUuid, characteristicUuid, descriptorUuid , transactionId))
352
+ when (managerForPeripheral.readDescriptorForPeripheral (any, SERVICE_UUID , CHARACTERISTIC_UUID , DESCRIPTOR_UUID , transactionId))
363
353
.thenAnswer ((_) => Future .value (descriptorWithValue));
364
354
365
355
//when
366
- DescriptorWithValueMock obtainedDescriptorWithValue = await peripheral.readDescriptor (serviceUuid, characteristicUuid, descriptorUuid , transactionId: transactionId);
356
+ DescriptorWithValueMock obtainedDescriptorWithValue = await peripheral.readDescriptor (SERVICE_UUID , CHARACTERISTIC_UUID , DESCRIPTOR_UUID , transactionId: transactionId);
367
357
368
358
//then
369
359
expect (obtainedDescriptorWithValue, descriptorWithValue);
@@ -386,17 +376,13 @@ void main() {
386
376
test ("should write value to descriptor" , () async {
387
377
//given
388
378
DescriptorWithValue descriptorWithValue = DescriptorWithValueMock ();
389
- const serviceUuid = "123uuid" ;
390
- const characteristicUuid = "c1" ;
391
- const descriptorUuid = "c1" ;
392
- const transactionId = "t1" ;
393
379
Uint8List value = Uint8List .fromList ([1 , 4 , 9 ]);
394
380
395
- when (managerForPeripheral.writeDescriptorForPeripheral (any, serviceUuid, characteristicUuid, descriptorUuid , value, transactionId ))
381
+ when (managerForPeripheral.writeDescriptorForPeripheral (any, SERVICE_UUID , CHARACTERISTIC_UUID , DESCRIPTOR_UUID , value, TRANSACTION_ID ))
396
382
.thenAnswer ((_) => Future .value (descriptorWithValue));
397
383
398
384
//when
399
- DescriptorWithValue obtainedDescriptorWithValue = await peripheral.writeDescriptor (serviceUuid, characteristicUuid, descriptorUuid , value, transactionId: transactionId );
385
+ DescriptorWithValue obtainedDescriptorWithValue = await peripheral.writeDescriptor (SERVICE_UUID , CHARACTERISTIC_UUID , DESCRIPTOR_UUID , value, transactionId: TRANSACTION_ID );
400
386
401
387
//then
402
388
expect (obtainedDescriptorWithValue, descriptorWithValue);
0 commit comments