From a0288b8fd6c72bbb1f0dfb21e37753071e57ec05 Mon Sep 17 00:00:00 2001 From: XiangRongLin <41164160+XiangRongLin@users.noreply.github.com> Date: Sun, 17 Jan 2021 19:52:28 +0100 Subject: [PATCH 1/3] Echo which downloader is used during CI process --- .github/workflows/ci.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0f3ed9545..58f8d0352 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -32,7 +32,9 @@ jobs: - name: Build and run Tests run: | if [[ $GITHUB_EVENT_NAME == 'schedule' ]]; then + echo running with real downloader ./gradlew check --stacktrace -Ddownloader=REAL else + echo running with mock downloader ./gradlew check --stacktrace -Ddownloader=MOCK fi From eecfe09f2c145ec0f7256b5981cc49ba683f8b2e Mon Sep 17 00:00:00 2001 From: XiangRongLin <41164160+XiangRongLin@users.noreply.github.com> Date: Sun, 17 Jan 2021 19:52:58 +0100 Subject: [PATCH 2/3] Check for non-existent folder in MockDownloader --- .../newpipe/downloader/MockDownloader.java | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/extractor/src/test/java/org/schabi/newpipe/downloader/MockDownloader.java b/extractor/src/test/java/org/schabi/newpipe/downloader/MockDownloader.java index 21019a4ec..888d334df 100644 --- a/extractor/src/test/java/org/schabi/newpipe/downloader/MockDownloader.java +++ b/extractor/src/test/java/org/schabi/newpipe/downloader/MockDownloader.java @@ -27,15 +27,17 @@ class MockDownloader extends Downloader { public MockDownloader(@Nonnull String path) throws IOException { this.path = path; this.mocks = new HashMap<>(); - File folder = new File(path); - for (File file : folder.listFiles()) { - if (file.getName().startsWith(RecordingDownloader.FILE_NAME_PREFIX)) { - final FileReader reader = new FileReader(file); - final TestRequestResponse response = new GsonBuilder() - .create() - .fromJson(reader, TestRequestResponse.class); - reader.close(); - mocks.put(response.getRequest(), response.getResponse()); + final File[] files = new File(path).listFiles(); + if (files != null) { + for (File file : files) { + if (file.getName().startsWith(RecordingDownloader.FILE_NAME_PREFIX)) { + final FileReader reader = new FileReader(file); + final TestRequestResponse response = new GsonBuilder() + .create() + .fromJson(reader, TestRequestResponse.class); + reader.close(); + mocks.put(response.getRequest(), response.getResponse()); + } } } } From 88e4c8667be7b369e56d9ab02f2bba2d18ee019b Mon Sep 17 00:00:00 2001 From: XiangRongLin <41164160+XiangRongLin@users.noreply.github.com> Date: Sun, 17 Jan 2021 19:53:20 +0100 Subject: [PATCH 3/3] Add comments to RecordingDownloader about usage --- .../org/schabi/newpipe/downloader/RecordingDownloader.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/extractor/src/test/java/org/schabi/newpipe/downloader/RecordingDownloader.java b/extractor/src/test/java/org/schabi/newpipe/downloader/RecordingDownloader.java index bfe9e8c77..9e07959f0 100644 --- a/extractor/src/test/java/org/schabi/newpipe/downloader/RecordingDownloader.java +++ b/extractor/src/test/java/org/schabi/newpipe/downloader/RecordingDownloader.java @@ -27,6 +27,10 @@ import javax.annotation.Nonnull; * The files must be created on the local dev environment * and recreated when the requests made by a test class change. *
+ *+ * Run the test class as a whole and not each test separately. + * Make sure the requests made by a class are unique. + *
*/ class RecordingDownloader extends Downloader {