Skip to content

Commit 3455f0f

Browse files
committed
Add documentation to testing with mocks
1 parent 63c237d commit 3455f0f

3 files changed

Lines changed: 36 additions & 0 deletions

File tree

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,20 @@ public class DownloaderFactory {
1111
private final static DownloaderType DEFAULT_DOWNLOADER = DownloaderType.REAL;
1212

1313
/**
14+
* <p>
15+
* Returns a implementation of a downloader.
16+
* </p>
17+
* <p>
18+
* If the system property "downloader" is set and is one of {@link DownloaderType},
19+
* then a downloader of that type is returned.
20+
* It can be passed in with gradle by adding the argument -Ddownloader=abcd,
21+
* where abcd is one of {@link DownloaderType}
22+
* </p>
23+
* <p>
24+
* Otherwise it falls back to {@link DownloaderFactory#DEFAULT_DOWNLOADER}.
25+
* Change this during development on the local machine to use a different downloader.
26+
* </p>
27+
*
1428
* @param path The path to the folder where mocks are saved/retrieved.
1529
* Preferably starting with {@link DownloaderFactory#RESOURCE_PATH}
1630
*/

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@
1414

1515
import javax.annotation.Nonnull;
1616

17+
/**
18+
* <p>
19+
* Mocks requests by using json files created by {@link RecordingDownloader}
20+
* </p>
21+
*/
1722
class MockDownloader extends Downloader {
1823

1924
private final String path;

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,30 @@
1616

1717
import javax.annotation.Nonnull;
1818

19+
/**
20+
* <p>
21+
* Relays requests to {@link DownloaderTestImpl} and saves the request/response pair into a json file.
22+
* </p>
23+
* <p>
24+
* Those files are used by {@link MockDownloader}.
25+
* </p>
26+
* <p>
27+
* The files <b>must</b> be created on the local dev environment
28+
* and recreated when the requests made by a test class change.
29+
* </p>
30+
*/
1931
class RecordingDownloader extends Downloader {
2032

2133
public final static String FILE_NAME_PREFIX = "generated_mock_";
2234

2335
private int index = 0;
2436
private final String path;
2537

38+
/**
39+
* Creates the folder described by {@code stringPath} if it does not exists.
40+
* Deletes existing files starting with {@link RecordingDownloader#FILE_NAME_PREFIX}.
41+
* @param stringPath Path to the folder where the json files will be saved to.
42+
*/
2643
public RecordingDownloader(String stringPath) throws IOException {
2744
this.path = stringPath;
2845
Path path = Paths.get(stringPath);

0 commit comments

Comments
 (0)