Class DataSourceContractTest
- java.lang.Object
-
- com.google.android.exoplayer2.testutil.DataSourceContractTest
-
@RequiresApi(19) public abstract class DataSourceContractTest extends Object
A collection of contract tests forDataSource
implementations.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.Most implementations should pass all these tests. If necessary, subclasses can disable tests by overriding the
@Test
method with a no-op implementation. It's recommended (but not required) to also annotate this@Ignore
so that JUnit correctly reports the test as skipped/ignored instead of passing.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
DataSourceContractTest.FakeTransferListener
ATransferListener
that only keeps track of the transferred bytes.static class
DataSourceContractTest.TestResource
Information about a resource that can be used to test theDataSource
instance.
-
Field Summary
Fields Modifier and Type Field Description AdditionalFailureInfo
additionalFailureInfo
-
Constructor Summary
Constructors Constructor Description DataSourceContractTest()
-
Method Summary
-
-
-
Field Detail
-
additionalFailureInfo
public final AdditionalFailureInfo additionalFailureInfo
-
-
Method Detail
-
createDataSource
protected abstract DataSource createDataSource() throws Exception
Creates and returns an instance of theDataSource
.- Throws:
Exception
-
getTransferListenerDataSource
@Nullable protected DataSource getTransferListenerDataSource()
Returns theDataSource
that will be included in theTransferListener
callbacks for theDataSource
most recently created bycreateDataSource()
. If it's the sameDataSource
thennull
can be returned.
-
unboundedReadsAreIndefinite
protected boolean unboundedReadsAreIndefinite()
Returns whether theDataSource
will continue reading indefinitely for unboundedDataSpecs
.
-
getTestResources
protected abstract ImmutableList<DataSourceContractTest.TestResource> getTestResources() throws Exception
ReturnsDataSourceContractTest.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)
.- Throws:
Exception
-
getNotFoundUri
protected abstract Uri getNotFoundUri()
Returns aUri
that doesn't resolve.This is used to test how a
DataSource
handles nonexistent data.
-
unboundedDataSpec_readUntilEnd
public void unboundedDataSpec_readUntilEnd() throws Exception
- Throws:
Exception
-
dataSpecWithPosition_readUntilEnd
public void dataSpecWithPosition_readUntilEnd() throws Exception
- Throws:
Exception
-
dataSpecWithLength_readExpectedRange
public void dataSpecWithLength_readExpectedRange() throws Exception
- Throws:
Exception
-
dataSpecWithPositionAndLength_readExpectedRange
public void dataSpecWithPositionAndLength_readExpectedRange() throws Exception
- Throws:
Exception
-
dataSpecWithPositionAtEnd_readsZeroBytes
public void dataSpecWithPositionAtEnd_readsZeroBytes() throws Exception
- Throws:
Exception
-
dataSpecWithPositionAtEndAndLength_readsZeroBytes
public void dataSpecWithPositionAtEndAndLength_readsZeroBytes() throws Exception
- Throws:
Exception
-
dataSpecWithPositionOutOfRange_throwsPositionOutOfRangeException
public void dataSpecWithPositionOutOfRange_throwsPositionOutOfRangeException() throws Exception
- Throws:
Exception
-
dataSpecWithEndPositionOutOfRange_readsToEnd
public void dataSpecWithEndPositionOutOfRange_readsToEnd() throws Exception
- Throws:
Exception
-
unboundedDataSpecWithGzipFlag_readUntilEnd
public void unboundedDataSpecWithGzipFlag_readUntilEnd() throws Exception
DataSpec.FLAG_ALLOW_GZIP
should either be ignored byDataSource
implementations, or correctly handled (i.e. the data is decompressed before being returned fromDataReader.read(byte[], int, int)
).- Throws:
Exception
-
uriSchemeIsCaseInsensitive
public void uriSchemeIsCaseInsensitive() throws Exception
- Throws:
Exception
-
transferListenerCallbacks
public void transferListenerCallbacks() throws Exception
- Throws:
Exception
-
resourceNotFound_transferListenerCallbacks
public void resourceNotFound_transferListenerCallbacks() throws Exception
- Throws:
Exception
-
getUri_returnsNonNullValueOnlyWhileOpen
public void getUri_returnsNonNullValueOnlyWhileOpen() throws Exception
- Throws:
Exception
-
getUri_resourceNotFound_returnsNullIfNotOpened
public void getUri_resourceNotFound_returnsNullIfNotOpened() throws Exception
- Throws:
Exception
-
getResponseHeaders_noNullKeysOrValues
public void getResponseHeaders_noNullKeysOrValues() throws Exception
- Throws:
Exception
-
getResponseHeaders_caseInsensitive
public void getResponseHeaders_caseInsensitive() throws Exception
- Throws:
Exception
-
getResponseHeaders_isEmptyWhileNotOpen
public void getResponseHeaders_isEmptyWhileNotOpen() throws Exception
- Throws:
Exception
-
-