Skip to content

Commit a28e022

Browse files
authored
Merge pull request #519 from XiangRongLin/better_logging_error_handling
Better logging, error handling, doc for mock tests
2 parents 416cf17 + 88e4c86 commit a28e022

File tree

3 files changed

+17
-9
lines changed

3 files changed

+17
-9
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ jobs:
3232
- name: Build and run Tests
3333
run: |
3434
if [[ $GITHUB_EVENT_NAME == 'schedule' ]]; then
35+
echo running with real downloader
3536
./gradlew check --stacktrace -Ddownloader=REAL
3637
else
38+
echo running with mock downloader
3739
./gradlew check --stacktrace -Ddownloader=MOCK
3840
fi

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
}

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@
2727
* The files <b>must</b> be created on the local dev environment
2828
* and recreated when the requests made by a test class change.
2929
* </p>
30+
* <p>
31+
* Run the test class as a whole and not each test separately.
32+
* Make sure the requests made by a class are unique.
33+
* </p>
3034
*/
3135
class RecordingDownloader extends Downloader {
3236

0 commit comments

Comments
 (0)