Skip to content

Commit eecfe09

Browse files
committed
Check for non-existent folder in MockDownloader
1 parent a0288b8 commit eecfe09

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

extractor/src/test/java/org/schabi/newpipe/downloader/MockDownloader.java

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,17 @@ class MockDownloader extends Downloader {
2727
public MockDownloader(@Nonnull String path) throws IOException {
2828
this.path = path;
2929
this.mocks = new HashMap<>();
30-
File folder = new File(path);
31-
for (File file : folder.listFiles()) {
32-
if (file.getName().startsWith(RecordingDownloader.FILE_NAME_PREFIX)) {
33-
final FileReader reader = new FileReader(file);
34-
final TestRequestResponse response = new GsonBuilder()
35-
.create()
36-
.fromJson(reader, TestRequestResponse.class);
37-
reader.close();
38-
mocks.put(response.getRequest(), response.getResponse());
30+
final File[] files = new File(path).listFiles();
31+
if (files != null) {
32+
for (File file : files) {
33+
if (file.getName().startsWith(RecordingDownloader.FILE_NAME_PREFIX)) {
34+
final FileReader reader = new FileReader(file);
35+
final TestRequestResponse response = new GsonBuilder()
36+
.create()
37+
.fromJson(reader, TestRequestResponse.class);
38+
reader.close();
39+
mocks.put(response.getRequest(), response.getResponse());
40+
}
3941
}
4042
}
4143
}

0 commit comments

Comments
 (0)