@@ -5,7 +5,7 @@ import 'package:flutter/services.dart';
5
5
import 'package:flutter_test/flutter_test.dart' ;
6
6
import 'package:geolocator_platform_interface/geolocator_platform_interface.dart' ;
7
7
import 'package:geolocator_platform_interface/src/implementations/method_channel_geolocator.dart' ;
8
-
8
+ import 'package:geolocator_platform_interface/src/enums/location_service.dart' ;
9
9
import 'event_channel_mock.dart' ;
10
10
import 'method_channel_mock.dart' ;
11
11
@@ -556,6 +556,95 @@ void main() {
556
556
});
557
557
});
558
558
559
+ group (
560
+ // ignore: lines_longer_than_80_chars
561
+ 'getServiceStream: When requesting a stream of location service status updates' ,
562
+ () {
563
+ group (
564
+ 'And requesting for location service status updates multiple times' ,
565
+ () {
566
+ test ('Should return the same stream' , () {
567
+ final methodChannelGeolocator = MethodChannelGeolocator ();
568
+ final firstStream =
569
+ methodChannelGeolocator.getServiceStatusStream ();
570
+ final secondstream =
571
+ methodChannelGeolocator.getServiceStatusStream ();
572
+
573
+ expect (
574
+ identical (firstStream, secondstream),
575
+ true ,
576
+ );
577
+ });
578
+ });
579
+ });
580
+
581
+ test (
582
+ // ignore: lines_longer_than_80_chars
583
+ 'Should receive a stream with location service updates if permissions are granted' ,
584
+ () async {
585
+ // Arrange
586
+ final streamController = StreamController <int >.broadcast ();
587
+ EventChannelMock (
588
+ channelName: 'flutter.baseflow.com/geolocator_service_updates' ,
589
+ stream: streamController.stream);
590
+
591
+ // Act
592
+ final locationServiceStream =
593
+ MethodChannelGeolocator ().getServiceStatusStream ();
594
+ final streamQueue = StreamQueue (locationServiceStream);
595
+
596
+ // Emit test events
597
+ streamController.add (0 ); // disabled value in native enum
598
+ streamController.add (1 ); // enabled value in native enum
599
+
600
+ //Assert
601
+ expect (await streamQueue.next, ServiceStatus .disabled);
602
+ expect (await streamQueue.next, ServiceStatus .enabled);
603
+
604
+ // Clean up
605
+ await streamQueue.cancel ();
606
+ await streamController.close ();
607
+ });
608
+
609
+ test (
610
+ // ignore: lines_longer_than_80_chars
611
+ 'Should receive an exception if android activity is missing' ,
612
+ () async {
613
+ // Arrange
614
+ final streamController =
615
+ StreamController <PlatformException >.broadcast ();
616
+ EventChannelMock (
617
+ channelName: 'flutter.baseflow.com/geolocator_service_updates' ,
618
+ stream: streamController.stream,
619
+ );
620
+
621
+ // Act
622
+ final positionStream =
623
+ MethodChannelGeolocator ().getServiceStatusStream ();
624
+ final streamQueue = StreamQueue (positionStream);
625
+
626
+ // Emit test error
627
+ streamController.addError (PlatformException (
628
+ code: 'ACTIVITY_MISSING' ,
629
+ message: 'Activity missing' ,
630
+ details: null ));
631
+
632
+ // Assert
633
+ expect (
634
+ streamQueue.next,
635
+ throwsA (
636
+ isA <ActivityMissingException >().having (
637
+ (e) => e.message,
638
+ 'message' ,
639
+ 'Activity missing' ,
640
+ ),
641
+ ));
642
+
643
+ // Clean up
644
+ streamQueue.cancel ();
645
+ streamController.close ();
646
+ });
647
+
559
648
test (
560
649
// ignore: lines_longer_than_80_chars
561
650
'Should receive a stream with position updates if permissions are granted' ,
0 commit comments