@@ -17,9 +17,15 @@ class _MockVideoPlayerController extends Mock
1717
1818void main () {
1919 late VideoPlayerService sut;
20+ late VideoPlayerController controller;
2021
2122 setUp (() {
22- sut = VideoPlayerService (options: VideoPlayerOptions ());
23+ controller = _MockVideoPlayerController ();
24+ sut = VideoPlayerService .test (controller: controller);
25+ });
26+
27+ tearDown (() {
28+ sut.dispose ();
2329 });
2430
2531 group ('VideoPlayerService' , () {
@@ -28,22 +34,25 @@ void main() {
2834 });
2935
3036 test ('can provide a controller' , () {
31- expect (sut.controller, isNull );
37+ expect (sut.controller, isNotNull );
3238 });
3339
3440 test ('can provide status of the video player' , () {
35- expect (sut.isReady, false );
41+ expect (sut.isReady, true );
3642 });
3743
3844 test ('can provide current status of the video player' , () {
45+ when (() => controller.value.isPlaying).thenThrow (Exception ());
3946 expect (sut.isPlaying, false );
4047 });
4148
4249 test ('can provide current position of the video' , () {
50+ when (() => controller.value.position).thenThrow (Exception ());
4351 expect (sut.position, Duration .zero);
4452 });
4553
4654 test ('can provide duration of the video' , () {
55+ when (() => controller.value.duration).thenThrow (Exception ());
4756 expect (sut.duration, Duration .zero);
4857 });
4958
@@ -60,23 +69,20 @@ void main() {
6069 });
6170
6271 test ('can load a video from file' , () async {
63- final controller = _MockVideoPlayerController ();
64- final videoPlayerService = VideoPlayerService .test (
65- controller: controller,
66- );
67-
68- when (controller.initialize).thenAnswer ((_) => Future .value ());
69- when (() => controller.setVolume (any ())).thenAnswer ((_) => Future .value ());
70-
71- await videoPlayerService.loadFile (File ('' ));
72-
72+ when (() => controller.initialize ()).thenAnswer (Future .value);
73+ when (() => controller.setVolume (any ())).thenAnswer (Future .value);
74+ await sut.loadFile (File ('' ));
7375 verify (controller.initialize).called (1 );
7476 verify (() => controller.setVolume (any ())).called (1 );
7577 });
7678
7779 test ('can throw LoadVideoException while loading a video from file' , () {
80+ final videoPlayerService = VideoPlayerService (
81+ options: VideoPlayerOptions (),
82+ );
83+
7884 expect (
79- sut .loadFile (File ('' )),
85+ videoPlayerService .loadFile (File ('' )),
8086 throwsA (isA <LoadVideoException >()),
8187 );
8288 });
@@ -87,13 +93,8 @@ void main() {
8793
8894 test ('can log the issue when could not dispose the video player controller' ,
8995 () {
90- final controller = _MockVideoPlayerController ();
91- final videoPlayerService = VideoPlayerService .test (
92- controller: controller,
93- );
94-
9596 when (controller.dispose).thenThrow (Exception ());
96- expect (videoPlayerService .dispose (), isA <Future <void >>());
97+ expect (sut .dispose (), isA <Future <void >>());
9798 });
9899
99100 test ('can throw PlayVideoException while trying to play a video' , () {
0 commit comments