@@ -6,10 +6,10 @@ import 'dart:io' show Directory;
66import 'dart:async' ;
77
88import 'package:flutter_test/flutter_test.dart' ;
9- import 'package:mockito/mockito.dart' ;
109import 'package:path_provider/path_provider.dart' ;
1110import 'package:path_provider_platform_interface/path_provider_platform_interface.dart' ;
1211import 'package:plugin_platform_interface/plugin_platform_interface.dart' ;
12+ import 'package:test/fake.dart' ;
1313
1414const String kTemporaryPath = 'temporaryPath' ;
1515const String kApplicationSupportPath = 'applicationSupportPath' ;
@@ -20,31 +20,30 @@ const String kExternalCachePath = 'externalCachePath';
2020const String kExternalStoragePath = 'externalStoragePath' ;
2121
2222void main () {
23- group ('PathProvider' , () {
24- TestWidgetsFlutterBinding .ensureInitialized ();
25-
23+ TestWidgetsFlutterBinding .ensureInitialized ();
24+ group ('PathProvider full implementation' , () {
2625 setUp (() async {
27- PathProviderPlatform .instance = MockPathProviderPlatform ();
26+ PathProviderPlatform .instance = FakePathProviderPlatform ();
2827 });
2928
3029 test ('getTemporaryDirectory' , () async {
31- Directory ? result = await getTemporaryDirectory ();
32- expect (result? .path, kTemporaryPath);
30+ Directory result = await getTemporaryDirectory ();
31+ expect (result.path, kTemporaryPath);
3332 });
3433
3534 test ('getApplicationSupportDirectory' , () async {
36- Directory ? result = await getApplicationSupportDirectory ();
37- expect (result? .path, kApplicationSupportPath);
35+ Directory result = await getApplicationSupportDirectory ();
36+ expect (result.path, kApplicationSupportPath);
3837 });
3938
4039 test ('getLibraryDirectory' , () async {
41- Directory ? result = await getLibraryDirectory ();
42- expect (result? .path, kLibraryPath);
40+ Directory result = await getLibraryDirectory ();
41+ expect (result.path, kLibraryPath);
4342 });
4443
4544 test ('getApplicationDocumentsDirectory' , () async {
46- Directory ? result = await getApplicationDocumentsDirectory ();
47- expect (result? .path, kApplicationDocumentsPath);
45+ Directory result = await getApplicationDocumentsDirectory ();
46+ expect (result.path, kApplicationDocumentsPath);
4847 });
4948
5049 test ('getExternalStorageDirectory' , () async {
@@ -69,42 +68,126 @@ void main() {
6968 expect (result? .path, kDownloadsPath);
7069 });
7170 });
71+
72+ group ('PathProvider null implementation' , () {
73+ setUp (() async {
74+ PathProviderPlatform .instance = AllNullFakePathProviderPlatform ();
75+ });
76+
77+ test ('getTemporaryDirectory throws on null' , () async {
78+ expect (getTemporaryDirectory (),
79+ throwsA (isA <MissingPlatformDirectoryException >()));
80+ });
81+
82+ test ('getApplicationSupportDirectory throws on null' , () async {
83+ expect (getApplicationSupportDirectory (),
84+ throwsA (isA <MissingPlatformDirectoryException >()));
85+ });
86+
87+ test ('getLibraryDirectory throws on null' , () async {
88+ expect (getLibraryDirectory (),
89+ throwsA (isA <MissingPlatformDirectoryException >()));
90+ });
91+
92+ test ('getApplicationDocumentsDirectory throws on null' , () async {
93+ expect (getApplicationDocumentsDirectory (),
94+ throwsA (isA <MissingPlatformDirectoryException >()));
95+ });
96+
97+ test ('getExternalStorageDirectory passes null through' , () async {
98+ Directory ? result = await getExternalStorageDirectory ();
99+ expect (result, isNull);
100+ });
101+
102+ test ('getExternalCacheDirectories passes null through' , () async {
103+ List <Directory >? result = await getExternalCacheDirectories ();
104+ expect (result, isNull);
105+ });
106+
107+ test ('getExternalStorageDirectories passes null through' , () async {
108+ List <Directory >? result = await getExternalStorageDirectories ();
109+ expect (result, isNull);
110+ });
111+
112+ test ('getDownloadsDirectory passses null through' , () async {
113+ Directory ? result = await getDownloadsDirectory ();
114+ expect (result, isNull);
115+ });
116+ });
72117}
73118
74- class MockPathProviderPlatform extends Mock
119+ class FakePathProviderPlatform extends Fake
75120 with MockPlatformInterfaceMixin
76121 implements PathProviderPlatform {
77- Future <String > getTemporaryPath () async {
122+ Future <String ? > getTemporaryPath () async {
78123 return kTemporaryPath;
79124 }
80125
81- Future <String > getApplicationSupportPath () async {
126+ Future <String ? > getApplicationSupportPath () async {
82127 return kApplicationSupportPath;
83128 }
84129
85- Future <String > getLibraryPath () async {
130+ Future <String ? > getLibraryPath () async {
86131 return kLibraryPath;
87132 }
88133
89- Future <String > getApplicationDocumentsPath () async {
134+ Future <String ? > getApplicationDocumentsPath () async {
90135 return kApplicationDocumentsPath;
91136 }
92137
93- Future <String > getExternalStoragePath () async {
138+ Future <String ? > getExternalStoragePath () async {
94139 return kExternalStoragePath;
95140 }
96141
97- Future <List <String >> getExternalCachePaths () async {
142+ Future <List <String >? > getExternalCachePaths () async {
98143 return < String > [kExternalCachePath];
99144 }
100145
101- Future <List <String >> getExternalStoragePaths ({
146+ Future <List <String >? > getExternalStoragePaths ({
102147 StorageDirectory ? type,
103148 }) async {
104149 return < String > [kExternalStoragePath];
105150 }
106151
107- Future <String > getDownloadsPath () async {
152+ Future <String ? > getDownloadsPath () async {
108153 return kDownloadsPath;
109154 }
110155}
156+
157+ class AllNullFakePathProviderPlatform extends Fake
158+ with MockPlatformInterfaceMixin
159+ implements PathProviderPlatform {
160+ Future <String ?> getTemporaryPath () async {
161+ return null ;
162+ }
163+
164+ Future <String ?> getApplicationSupportPath () async {
165+ return null ;
166+ }
167+
168+ Future <String ?> getLibraryPath () async {
169+ return null ;
170+ }
171+
172+ Future <String ?> getApplicationDocumentsPath () async {
173+ return null ;
174+ }
175+
176+ Future <String ?> getExternalStoragePath () async {
177+ return null ;
178+ }
179+
180+ Future <List <String >?> getExternalCachePaths () async {
181+ return null ;
182+ }
183+
184+ Future <List <String >?> getExternalStoragePaths ({
185+ StorageDirectory ? type,
186+ }) async {
187+ return null ;
188+ }
189+
190+ Future <String ?> getDownloadsPath () async {
191+ return null ;
192+ }
193+ }
0 commit comments