Commit ed060a8f by eguven Committed by Oliver Woodman

Add FakeDataSource.setTestData() to simplify adding random test data

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=159676653
parent 40039ed0
......@@ -343,26 +343,36 @@ public final class FakeDataSource implements DataSource {
dataMap = new HashMap<>();
}
/** Sets the default data, overwrites if there is one already. */
public FakeData newDefaultData() {
defaultData = new FakeData(this, null);
return defaultData;
}
public FakeData newData(String uri) {
FakeData data = new FakeData(this, uri);
dataMap.put(uri, data);
return data;
/** Sets random data with the given {@code length} for the given {@code uri}. */
public FakeDataSet setRandomData(String uri, int length) {
return setData(uri, TestUtil.buildTestData(length));
}
/** Sets the given {@code data} for the given {@code uri}. */
public FakeDataSet setData(String uri, byte[] data) {
return newData(uri).appendReadData(data).endData();
}
/** Returns a new {@link FakeData} with the given {@code uri}. */
public FakeData newData(String uri) {
FakeData data = new FakeData(this, uri);
dataMap.put(uri, data);
return data;
}
/** Returns the data for the given {@code uri}, or {@code defaultData} if no data is set. */
public FakeData getData(String uri) {
FakeData data = dataMap.get(uri);
return data != null ? data : defaultData;
}
/** Returns a list of all data including {@code defaultData}. */
public ArrayList<FakeData> getAllData() {
ArrayList<FakeData> fakeDatas = new ArrayList<>(dataMap.values());
if (defaultData != null) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment