FakeDataSet
@UnstableApi
public class FakeDataSet
FakeAdaptiveDataSet |
Fake data set emulating the data of an adaptive media source. |
Collection of FakeData to be served by a FakeDataSource.
Multiple fake data can be defined by setData and newData methods. It's also possible to define a default data by newDefaultData.
newData and newDefaultData return a FakeData instance which can be used to define specific results during read calls.
The data that will be read from the source can be constructed by calling appendReadData Calls to read will not span the boundaries between arrays passed to successive calls, and hence the boundaries control the positions at which read requests to the source may only be partially satisfied.
Errors can be inserted by calling appendReadError. An inserted error will be thrown from the first call to read that attempts to read from the corresponding position, and from all subsequent calls to read until the source is closed. If the source is closed and re-opened having encountered an error, that error will not be thrown again.
Actions are inserted by calling appendReadAction. An actions is triggered when the reading reaches action's position. This can be used to make sure the code is in a certain state while testing.
Example usage:
// Create a FakeDataSource then add default data and two FakeData // "test_file" throws an IOException when tried to be read until closed and reopened. FakeDataSource fakeDataSource = new FakeDataSource(); fakeDataSource.getDataSet() .newDefaultData() .appendReadData(defaultData) .endData() .setData("http://1", data1) .newData("test_file") .appendReadError(new IOException()) .appendReadData(data2) .endData();
Summary
Nested types |
|---|
public final class FakeDataSet.FakeDataContainer of fake data to be served by a |
public final class FakeDataSet.FakeData.SegmentA segment of |
Public constructors |
|---|
Public methods |
|
|---|---|
ArrayList<FakeDataSet.FakeData> |
Returns a list of all data including |
@Nullable FakeDataSet.FakeData |
Returns the data for the given |
@Nullable FakeDataSet.FakeData |
Returns the data for the given |
FakeDataSet.FakeData |
Returns a new |
FakeDataSet.FakeData |
Returns a new |
FakeDataSet.FakeData |
Sets the default data, overwrites if there is one already. |
FakeDataSet |
Sets the given |
FakeDataSet |
Sets the given |
FakeDataSet |
setRandomData(String uri, int length)Sets random data with the given |
FakeDataSet |
setRandomData(Uri uri, int length)Sets random data with the given |
Public constructors
Public methods
getAllData
public ArrayList<FakeDataSet.FakeData> getAllData()
Returns a list of all data including defaultData.
getData
public @Nullable FakeDataSet.FakeData getData(String uri)
Returns the data for the given uri, or defaultData if no data is set.
getData
public @Nullable FakeDataSet.FakeData getData(Uri uri)
Returns the data for the given uri, or defaultData if no data is set.
newDefaultData
public FakeDataSet.FakeData newDefaultData()
Sets the default data, overwrites if there is one already.
setRandomData
public FakeDataSet setRandomData(String uri, int length)
Sets random data with the given length for the given uri.
setRandomData
public FakeDataSet setRandomData(Uri uri, int length)
Sets random data with the given length for the given uri.