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