@@ -6,10 +6,10 @@ import 'dart:io' show Directory;
6
6
import 'dart:async' ;
7
7
8
8
import 'package:flutter_test/flutter_test.dart' ;
9
- import 'package:mockito/mockito.dart' ;
10
9
import 'package:path_provider/path_provider.dart' ;
11
10
import 'package:path_provider_platform_interface/path_provider_platform_interface.dart' ;
12
11
import 'package:plugin_platform_interface/plugin_platform_interface.dart' ;
12
+ import 'package:test/fake.dart' ;
13
13
14
14
const String kTemporaryPath = 'temporaryPath' ;
15
15
const String kApplicationSupportPath = 'applicationSupportPath' ;
@@ -20,31 +20,30 @@ const String kExternalCachePath = 'externalCachePath';
20
20
const String kExternalStoragePath = 'externalStoragePath' ;
21
21
22
22
void main () {
23
- group ('PathProvider' , () {
24
- TestWidgetsFlutterBinding .ensureInitialized ();
25
-
23
+ TestWidgetsFlutterBinding .ensureInitialized ();
24
+ group ('PathProvider full implementation' , () {
26
25
setUp (() async {
27
- PathProviderPlatform .instance = MockPathProviderPlatform ();
26
+ PathProviderPlatform .instance = FakePathProviderPlatform ();
28
27
});
29
28
30
29
test ('getTemporaryDirectory' , () async {
31
- Directory ? result = await getTemporaryDirectory ();
32
- expect (result? .path, kTemporaryPath);
30
+ Directory result = await getTemporaryDirectory ();
31
+ expect (result.path, kTemporaryPath);
33
32
});
34
33
35
34
test ('getApplicationSupportDirectory' , () async {
36
- Directory ? result = await getApplicationSupportDirectory ();
37
- expect (result? .path, kApplicationSupportPath);
35
+ Directory result = await getApplicationSupportDirectory ();
36
+ expect (result.path, kApplicationSupportPath);
38
37
});
39
38
40
39
test ('getLibraryDirectory' , () async {
41
- Directory ? result = await getLibraryDirectory ();
42
- expect (result? .path, kLibraryPath);
40
+ Directory result = await getLibraryDirectory ();
41
+ expect (result.path, kLibraryPath);
43
42
});
44
43
45
44
test ('getApplicationDocumentsDirectory' , () async {
46
- Directory ? result = await getApplicationDocumentsDirectory ();
47
- expect (result? .path, kApplicationDocumentsPath);
45
+ Directory result = await getApplicationDocumentsDirectory ();
46
+ expect (result.path, kApplicationDocumentsPath);
48
47
});
49
48
50
49
test ('getExternalStorageDirectory' , () async {
@@ -69,42 +68,126 @@ void main() {
69
68
expect (result? .path, kDownloadsPath);
70
69
});
71
70
});
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
+ });
72
117
}
73
118
74
- class MockPathProviderPlatform extends Mock
119
+ class FakePathProviderPlatform extends Fake
75
120
with MockPlatformInterfaceMixin
76
121
implements PathProviderPlatform {
77
- Future <String > getTemporaryPath () async {
122
+ Future <String ? > getTemporaryPath () async {
78
123
return kTemporaryPath;
79
124
}
80
125
81
- Future <String > getApplicationSupportPath () async {
126
+ Future <String ? > getApplicationSupportPath () async {
82
127
return kApplicationSupportPath;
83
128
}
84
129
85
- Future <String > getLibraryPath () async {
130
+ Future <String ? > getLibraryPath () async {
86
131
return kLibraryPath;
87
132
}
88
133
89
- Future <String > getApplicationDocumentsPath () async {
134
+ Future <String ? > getApplicationDocumentsPath () async {
90
135
return kApplicationDocumentsPath;
91
136
}
92
137
93
- Future <String > getExternalStoragePath () async {
138
+ Future <String ? > getExternalStoragePath () async {
94
139
return kExternalStoragePath;
95
140
}
96
141
97
- Future <List <String >> getExternalCachePaths () async {
142
+ Future <List <String >? > getExternalCachePaths () async {
98
143
return < String > [kExternalCachePath];
99
144
}
100
145
101
- Future <List <String >> getExternalStoragePaths ({
146
+ Future <List <String >? > getExternalStoragePaths ({
102
147
StorageDirectory ? type,
103
148
}) async {
104
149
return < String > [kExternalStoragePath];
105
150
}
106
151
107
- Future <String > getDownloadsPath () async {
152
+ Future <String ? > getDownloadsPath () async {
108
153
return kDownloadsPath;
109
154
}
110
155
}
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