Prefix mock file from RecordingDownloader with "generated_mock_"
Only read those files in MockDownloader
This commit is contained in:
parent
f91916c017
commit
1ea6c6ce54
|
@ -24,12 +24,14 @@ class MockDownloader extends Downloader {
|
|||
this.mocks = new HashMap<>();
|
||||
File folder = new File(path);
|
||||
for (File file : folder.listFiles()) {
|
||||
final FileReader reader = new FileReader(file);
|
||||
final TestRequestResponse response = new GsonBuilder()
|
||||
.create()
|
||||
.fromJson(reader, TestRequestResponse.class);
|
||||
reader.close();
|
||||
mocks.put(response.getRequest(), response.getResponse());
|
||||
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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -19,6 +19,8 @@ import javax.annotation.Nonnull;
|
|||
|
||||
class RecordingDownloader extends Downloader {
|
||||
|
||||
public final static String FILE_NAME_PREFIX = "generated_mock_";
|
||||
|
||||
private int index = 0;
|
||||
private final String path;
|
||||
|
||||
|
@ -37,7 +39,7 @@ class RecordingDownloader extends Downloader {
|
|||
Downloader downloader = DownloaderTestImpl.getInstance();
|
||||
Response response = downloader.execute(request);
|
||||
|
||||
File outputFile = new File(path + File.separator + index + ".json");
|
||||
File outputFile = new File(path + File.separator + FILE_NAME_PREFIX + index + ".json");
|
||||
index++;
|
||||
outputFile.createNewFile();
|
||||
FileWriter writer = new FileWriter(outputFile);
|
||||
|
|
|
@ -4,20 +4,14 @@ import org.schabi.newpipe.extractor.downloader.Request;
|
|||
import org.schabi.newpipe.extractor.downloader.Response;
|
||||
|
||||
final class TestRequestResponse {
|
||||
private final String comment;
|
||||
private final Request request;
|
||||
private final Response response;
|
||||
|
||||
public TestRequestResponse(Request request, Response response) {
|
||||
this.comment = "Auto-generated for tests. See RecordingDownloader";
|
||||
this.request = request;
|
||||
this.response = response;
|
||||
}
|
||||
|
||||
public String getComment() {
|
||||
return comment;
|
||||
}
|
||||
|
||||
public Request getRequest() {
|
||||
return request;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue