-
Notifications
You must be signed in to change notification settings - Fork 3.6k
[path_provider] added android support for getDownloadsDirectory #4167
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
df16d00
5e0b0bf
3d3d0f6
6d75ecb
a107bba
af4151b
cbf5d11
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -81,7 +81,9 @@ class PathProviderAndroid extends PathProviderPlatform { | |
| } | ||
|
|
||
| @override | ||
| Future<String?> getDownloadsPath() { | ||
| throw UnsupportedError('getDownloadsPath is not supported on Android'); | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. removed incorrect throw error |
||
| Future<String?> getDownloadsPath() async { | ||
| final List<String>? paths = | ||
| await getExternalStoragePaths(type: StorageDirectory.downloads); | ||
| return paths?.first; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -89,13 +89,9 @@ void main() { | |
| }); | ||
| } // end of for-loop | ||
|
|
||
| test('getDownloadsPath fails', () async { | ||
| try { | ||
| await pathProvider.getDownloadsPath(); | ||
| fail('should throw UnsupportedError'); | ||
| } catch (e) { | ||
| expect(e, isUnsupportedError); | ||
| } | ||
| test('getDownloadsPath succeeds', () async { | ||
| final String? path = await pathProvider.getDownloadsPath(); | ||
| expect(path, kExternalStoragePaths); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There are two code paths through the new method, success and failure. Each path needs a unit test.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i've updated the new method to return a nullable path
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You still need a test for the case where it fails (e.g., to catch the fact that your current code will, incorrectly, throw if no external storage paths are returned).
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The current function now only returns a path, one code path, so I think 1 test is enough? (getDownloadsPath succeed) Cause it no longer throws an error, hence in test we can't expect it to throw something.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
As my comment above says, there is a bug in your current implementation, which is compelling evidence that the current test is insufficient.
Please test your code with an empty return array if you don't believe me that your code can still throw. |
||
| }); | ||
| }); | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.