Class FakeDataSet
- java.lang.Object
-
- com.google.android.exoplayer2.testutil.FakeDataSet
-
- Direct Known Subclasses:
FakeAdaptiveDataSet
public class FakeDataSet extends Object
Collection ofFakeDataSet.FakeData
to be served by aFakeDataSource
.Multiple fake data can be defined by
setData(Uri, byte[])
andnewData(Uri)
methods. It's also possible to define a default data bynewDefaultData()
.newData(Uri)
andnewDefaultData()
return aFakeDataSet.FakeData
instance which can be used to define specific results duringFakeDataSource.read(byte[], int, int)
calls.The data that will be read from the source can be constructed by calling
FakeDataSet.FakeData.appendReadData(byte[])
Calls toFakeDataSource.read(byte[], int, int)
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
FakeDataSet.FakeData.appendReadError(IOException)
. An inserted error will be thrown from the first call toFakeDataSource.read(byte[], int, int)
that attempts to read from the corresponding position, and from all subsequent calls toFakeDataSource.read(byte[], int, int)
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
FakeDataSet.FakeData.appendReadAction(Runnable)
. 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();
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
FakeDataSet.FakeData
Container of fake data to be served by aFakeDataSource
.
-
Constructor Summary
Constructors Constructor Description FakeDataSet()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ArrayList<FakeDataSet.FakeData>
getAllData()
Returns a list of all data includingdefaultData
.FakeDataSet.FakeData
getData(Uri uri)
Returns the data for the givenuri
, ordefaultData
if no data is set.FakeDataSet.FakeData
getData(String uri)
Returns the data for the givenuri
, ordefaultData
if no data is set.FakeDataSet.FakeData
newData(Uri uri)
Returns a newFakeDataSet.FakeData
with the givenuri
.FakeDataSet.FakeData
newData(String uri)
Returns a newFakeDataSet.FakeData
with the givenuri
.FakeDataSet.FakeData
newDefaultData()
Sets the default data, overwrites if there is one already.FakeDataSet
setData(Uri uri, byte[] data)
Sets the givendata
for the givenuri
.FakeDataSet
setData(String uri, byte[] data)
Sets the givendata
for the givenuri
.FakeDataSet
setRandomData(Uri uri, int length)
Sets random data with the givenlength
for the givenuri
.FakeDataSet
setRandomData(String uri, int length)
Sets random data with the givenlength
for the givenuri
.
-
-
-
Method Detail
-
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 givenlength
for the givenuri
.
-
setRandomData
public FakeDataSet setRandomData(Uri uri, int length)
Sets random data with the givenlength
for the givenuri
.
-
setData
public FakeDataSet setData(String uri, byte[] data)
Sets the givendata
for the givenuri
.
-
setData
public FakeDataSet setData(Uri uri, byte[] data)
Sets the givendata
for the givenuri
.
-
newData
public FakeDataSet.FakeData newData(String uri)
Returns a newFakeDataSet.FakeData
with the givenuri
.
-
newData
public FakeDataSet.FakeData newData(Uri uri)
Returns a newFakeDataSet.FakeData
with the givenuri
.
-
getData
@Nullable public FakeDataSet.FakeData getData(String uri)
Returns the data for the givenuri
, ordefaultData
if no data is set.
-
getData
@Nullable public FakeDataSet.FakeData getData(Uri uri)
Returns the data for the givenuri
, ordefaultData
if no data is set.
-
getAllData
public ArrayList<FakeDataSet.FakeData> getAllData()
Returns a list of all data includingdefaultData
.
-
-