DataSourceContractTest


@UnstableApi
abstract class DataSourceContractTest


A collection of contract tests for DataSource implementations.

Subclasses should only include the logic necessary to construct the DataSource (overriding either createDataSource or createDataSources) and allow it to successfully read data (overriding getTestResources. 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 functions

DataSource!

Creates and returns an instance of the DataSource.

(Mutable)List<DataSource!>!

Creates and returns a list of instances of the DataSource.

abstract Uri!

Returns a Uri that doesn't resolve.

abstract ImmutableList<DataSourceContractTest.TestResource!>!

Returns TestResource instances.

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 constructors

DataSourceContractTest

DataSourceContractTest()

Public functions

dataSpecWithEndPositionOutOfRange_readsToEnd

@Test
fun dataSpecWithEndPositionOutOfRange_readsToEnd(): Unit

dataSpecWithLength_readExpectedRange

@Test
fun dataSpecWithLength_readExpectedRange(): Unit

dataSpecWithLength_readUntilEndInTwoParts

@Test
fun dataSpecWithLength_readUntilEndInTwoParts(): Unit

dataSpecWithPositionAndLength_readExpectedRange

@Test
fun dataSpecWithPositionAndLength_readExpectedRange(): Unit

dataSpecWithPositionAtEndAndLength_readsZeroBytes

@Test
fun dataSpecWithPositionAtEndAndLength_readsZeroBytes(): Unit

dataSpecWithPositionAtEnd_readsZeroBytes

@Test
fun dataSpecWithPositionAtEnd_readsZeroBytes(): Unit

dataSpecWithPositionOutOfRange_throwsPositionOutOfRangeException

@Test
fun dataSpecWithPositionOutOfRange_throwsPositionOutOfRangeException(): Unit

dataSpecWithPosition_readUntilEnd

@Test
fun dataSpecWithPosition_readUntilEnd(): Unit

getResponseHeaders_caseInsensitive

@Test
fun getResponseHeaders_caseInsensitive(): Unit

getResponseHeaders_isEmptyWhileNotOpen

@Test
fun getResponseHeaders_isEmptyWhileNotOpen(): Unit

getResponseHeaders_noNullKeysOrValues

@Test
fun getResponseHeaders_noNullKeysOrValues(): Unit

getResponseHeaders_resourceNotFound_isEmptyWhileNotOpen

@Test
fun getResponseHeaders_resourceNotFound_isEmptyWhileNotOpen(): Unit

getUri_resourceNotFound_returnsNullIfNotOpened

@Test
fun getUri_resourceNotFound_returnsNullIfNotOpened(): Unit

getUri_returnsNonNullValueOnlyWhileOpen

@Test
fun getUri_returnsNonNullValueOnlyWhileOpen(): Unit

resourceNotFound

@Test
fun resourceNotFound(): Unit

resourceNotFound_transferListenerCallbacks

@Test
fun resourceNotFound_transferListenerCallbacks(): Unit

transferListenerCallbacks

@Test
fun transferListenerCallbacks(): Unit

unboundedDataSpecWithGzipFlag_readUntilEnd

@Test
fun unboundedDataSpecWithGzipFlag_readUntilEnd(): Unit

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_readExpectedBytesWithOffset

@Test
fun unboundedDataSpec_readExpectedBytesWithOffset(): Unit

unboundedDataSpec_readUntilEnd

@Test
fun unboundedDataSpec_readUntilEnd(): Unit

uriSchemeIsCaseInsensitive

@Test
fun uriSchemeIsCaseInsensitive(): Unit

Protected functions

createDataSource

protected fun createDataSource(): DataSource!

Creates and returns an instance of the DataSource.

Only one of createDataSource and createDataSources should be implemented.

createDataSources

protected fun createDataSources(): (Mutable)List<DataSource!>!

Creates and returns a list of instances of the DataSource.

Only one of createDataSource and createDataSources should be implemented.

getNotFoundUri

protected abstract fun getNotFoundUri(): Uri!

Returns a Uri that doesn't resolve.

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

getTestResources

protected abstract fun getTestResources(): ImmutableList<DataSourceContractTest.TestResource!>!

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 fun getTransferListenerDataSource(): DataSource?

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 fun unboundedReadsAreIndefinite(): Boolean

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

Public properties

additionalFailureInfo

@Rule
val additionalFailureInfoAdditionalFailureInfo!