public abstract class DataSourceContractTest extends Object
DataSource implementations.
All these tests should pass for all implementations - behaviour specific to only a subset of implementations should be tested elsewhere.
Subclasses should only include the logic necessary to construct the DataSource and allow it to
successfully read data. They shouldn't include any new @Test methods -
implementation-specific tests should be in a separate class.
If one of these tests fails for a particular DataSource implementation, that's a bug
in the implementation. The test should be overridden in the subclass and annotated Ignore, with a link to an issue to track fixing the implementation and un-ignoring the test.
| Modifier and Type | Class | Description |
|---|---|---|
static class |
DataSourceContractTest.TestResource |
Information about a resource that can be used to test the
DataSource instance. |
| Modifier and Type | Field | Description |
|---|---|---|
AdditionalFailureInfo |
additionalFailureInfo |
| Constructor | Description |
|---|---|
DataSourceContractTest() |
| Modifier and Type | Method | Description |
|---|---|---|
protected abstract DataSource |
createDataSource() |
Creates and returns an instance of the
DataSource. |
void |
dataSpecWithLength_readExpectedRange() |
|
void |
dataSpecWithPosition_readUntilEnd() |
|
void |
dataSpecWithPositionAndLength_readExpectedRange() |
|
protected abstract Uri |
getNotFoundUri() |
Returns a
Uri that doesn't resolve. |
protected abstract ImmutableList<DataSourceContractTest.TestResource> |
getTestResources() |
Returns
DataSourceContractTest.TestResource instances. |
void |
gzipFlagDoesntAffectReturnedData() |
DataSpec.FLAG_ALLOW_GZIP should either be ignored by DataSource
implementations, or correctly handled (i.e. |
void |
resourceNotFound() |
|
void |
unboundedDataSpec_readEverything() |
public final AdditionalFailureInfo additionalFailureInfo
protected abstract DataSource createDataSource() throws Exception
DataSource.Exceptionprotected abstract ImmutableList<DataSourceContractTest.TestResource> getTestResources() throws Exception
DataSourceContractTest.TestResource instances.
Each resource will be used to exercise the DataSource instance, allowing different
behaviours to be tested.
If multiple resources are returned, it's recommended to disambiguate them using DataSourceContractTest.TestResource.Builder.setName(String).
Exceptionprotected abstract Uri getNotFoundUri()
Uri that doesn't resolve.
This is used to test how a DataSource handles nonexistent data.
public void unboundedDataSpec_readEverything()
throws Exception
Exceptionpublic void dataSpecWithPosition_readUntilEnd()
throws Exception
Exceptionpublic void dataSpecWithLength_readExpectedRange()
throws Exception
Exceptionpublic void dataSpecWithPositionAndLength_readExpectedRange()
throws Exception
Exceptionpublic void gzipFlagDoesntAffectReturnedData()
throws Exception
DataSpec.FLAG_ALLOW_GZIP should either be ignored by DataSource
implementations, or correctly handled (i.e. the data is decompressed before being returned from
DataReader.read(byte[], int, int)).Exception