DataSourceContractTest


@RequiresApi(value = 19)
@UnstableApi
public abstract class DataSourceContractTest


A collection of contract tests for DataSource 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.

Summary

Nested types

A TransferListener that only keeps track of the transferred bytes.

Information about a resource that can be used to test the DataSource instance.

Builder for TestResource instances.

Public constructors

Protected methods

abstract DataSource

Creates and returns an instance of the DataSource.

abstract Uri

Returns a Uri that doesn't resolve.

abstract ImmutableList<DataSourceContractTest.TestResource>

Returns TestResource instances.

@Nullable DataSource

Returns the DataSource that will be included in the TransferListener callbacks for the DataSource most recently created by createDataSource.

boolean

Returns whether the DataSource will continue reading indefinitely for unbounded DataSpecs.

Public fields

additionalFailureInfo

@Rule
public final AdditionalFailureInfo additionalFailureInfo

Public constructors

DataSourceContractTest

public DataSourceContractTest()

Public methods

dataSpecWithEndPositionOutOfRange_readsToEnd

@Test
public void dataSpecWithEndPositionOutOfRange_readsToEnd()

dataSpecWithLength_readExpectedRange

@Test
public void dataSpecWithLength_readExpectedRange()

dataSpecWithPositionAndLength_readExpectedRange

@Test
public void dataSpecWithPositionAndLength_readExpectedRange()

dataSpecWithPositionAtEndAndLength_readsZeroBytes

@Test
public void dataSpecWithPositionAtEndAndLength_readsZeroBytes()

dataSpecWithPositionAtEnd_readsZeroBytes

@Test
public void dataSpecWithPositionAtEnd_readsZeroBytes()

dataSpecWithPositionOutOfRange_throwsPositionOutOfRangeException

@Test
public void dataSpecWithPositionOutOfRange_throwsPositionOutOfRangeException()

dataSpecWithPosition_readUntilEnd

@Test
public void dataSpecWithPosition_readUntilEnd()

getResponseHeaders_caseInsensitive

@Test
public void getResponseHeaders_caseInsensitive()

getResponseHeaders_isEmptyWhileNotOpen

@Test
public void getResponseHeaders_isEmptyWhileNotOpen()

getResponseHeaders_noNullKeysOrValues

@Test
public void getResponseHeaders_noNullKeysOrValues()

getResponseHeaders_resourceNotFound_isEmptyWhileNotOpen

@Test
public void getResponseHeaders_resourceNotFound_isEmptyWhileNotOpen()

getUri_resourceNotFound_returnsNullIfNotOpened

@Test
public void getUri_resourceNotFound_returnsNullIfNotOpened()

getUri_returnsNonNullValueOnlyWhileOpen

@Test
public void getUri_returnsNonNullValueOnlyWhileOpen()

resourceNotFound

@Test
public void resourceNotFound()

resourceNotFound_transferListenerCallbacks

@Test
public void resourceNotFound_transferListenerCallbacks()

transferListenerCallbacks

@Test
public void transferListenerCallbacks()

unboundedDataSpecWithGzipFlag_readUntilEnd

@Test
public void unboundedDataSpecWithGzipFlag_readUntilEnd()

FLAG_ALLOW_GZIP should either be ignored by DataSource implementations, or correctly handled (i.e. the data is decompressed before being returned from read).

unboundedDataSpec_readUntilEnd

@Test
public void unboundedDataSpec_readUntilEnd()

uriSchemeIsCaseInsensitive

@Test
public void uriSchemeIsCaseInsensitive()

Protected methods

createDataSource

protected abstract DataSource createDataSource()

Creates and returns an instance of the DataSource.

getNotFoundUri

protected abstract Uri getNotFoundUri()

Returns a Uri that doesn't resolve.

This is used to test how a DataSource handles nonexistent data.

getTestResources

protected abstract ImmutableList<DataSourceContractTest.TestResourcegetTestResources()

Returns 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 setName.

getTransferListenerDataSource

protected @Nullable DataSource getTransferListenerDataSource()

Returns the DataSource that will be included in the TransferListener callbacks for the DataSource most recently created by createDataSource. If it's the same DataSource then null can be returned.

unboundedReadsAreIndefinite

protected boolean unboundedReadsAreIndefinite()

Returns whether the DataSource will continue reading indefinitely for unbounded DataSpecs.