Class DataSourceContractTest


  • @RequiresApi(19)
    public abstract class DataSourceContractTest
    extends Object
    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 correclty reports the test as skipped/ignored instead of passing.

    • Constructor Detail

      • DataSourceContractTest

        public DataSourceContractTest()
    • Method Detail

      • unboundedReadsAreIndefinite

        protected boolean unboundedReadsAreIndefinite()
        Returns whether the DataSource will continue reading indefinitely for unbounded DataSpecs.
      • getNotFoundUri

        protected abstract Uri getNotFoundUri()
        Returns a Uri 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_throwsPositionOutOfRangeException

        public void dataSpecWithPositionAtEnd_throwsPositionOutOfRangeException()
                                                                         throws Exception
        Throws:
        Exception
      • dataSpecWithPositionAtEndAndLength_throwsPositionOutOfRangeException

        public void dataSpecWithPositionAtEndAndLength_throwsPositionOutOfRangeException()
                                                                                  throws Exception
        Throws:
        Exception
      • dataSpecWithPositionOutOfRange_throwsPositionOutOfRangeException

        public void dataSpecWithPositionOutOfRange_throwsPositionOutOfRangeException()
                                                                              throws Exception
        Throws:
        Exception
      • dataSpecWithEndPositionOutOfRange_readsToEnd

        public void dataSpecWithEndPositionOutOfRange_readsToEnd()
                                                          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_isEmptyWhileNotOpen

        public void getResponseHeaders_isEmptyWhileNotOpen()
                                                    throws Exception
        Throws:
        Exception
      • getResponseHeaders_resourceNotFound_isEmptyWhileNotOpen

        public void getResponseHeaders_resourceNotFound_isEmptyWhileNotOpen()
                                                                     throws Exception
        Throws:
        Exception