@Test
  public void testLifecycle_F2_F1_S3_C() {
    DataSource<Object> dataSource = getAndSubscribe();
    DataSubscriber<Object> subscriber1 = verifyGetAndSubscribeM(mDataSourceSupplier1, mSrc1);
    DataSubscriber<Object> subscriber2 = verifyGetAndSubscribeM(mDataSourceSupplier2, mSrc2);
    DataSubscriber<Object> subscriber3 = verifyGetAndSubscribeM(mDataSourceSupplier3, mSrc3);

    setState(mSrc2, NOT_CLOSED, FINISHED, WITHOUT_RESULT, null, FAILED, mock(Throwable.class));
    subscriber2.onFailure(mSrc2);
    mInOrder.verify(mSrc2).close();
    verifySubscriber(dataSource, mSrc2, NO_INTERACTIONS);
    verifyState(dataSource, null, NOT_CLOSED, NOT_FINISHED, WITHOUT_RESULT, null, NOT_FAILED, null);

    // src1 is closed and failure cause stored, but dataSource is not failed
    Throwable throwable = mock(Throwable.class);
    setState(mSrc1, NOT_CLOSED, FINISHED, WITHOUT_RESULT, null, FAILED, throwable);
    subscriber1.onFailure(mSrc1);
    mInOrder.verify(mSrc1).close();
    mInOrder.verify(mSrc1).getFailureCause();
    verifySubscriber(dataSource, mSrc1, NO_INTERACTIONS);
    verifyState(dataSource, null, NOT_CLOSED, NOT_FINISHED, WITHOUT_RESULT, null, NOT_FAILED, null);

    // src3's result is used but datasource is marked failed with the original cause from src1
    final Object result = mock(Object.class);
    setState(mSrc3, NOT_CLOSED, FINISHED, WITH_RESULT, result, NOT_FAILED, null);
    subscriber3.onNewResult(mSrc3);
    mInOrder.verify(mDataSubscriber).onNewResult(dataSource);
    mInOrder.verify(mDataSubscriber).onFailure(dataSource);
    verifyState(dataSource, mSrc3, NOT_CLOSED, FINISHED, WITH_RESULT, result, FAILED, throwable);

    testClose(dataSource, mSrc3);
    verifyState(dataSource, null, CLOSED, FINISHED, WITHOUT_RESULT, null, FAILED, throwable);
  }
Highest-quality data source failed second, result of the third data source is ignored.
fbcore/src/test/java/com/facebook/datasource/IncreasingQualityDataSourceSupplierTest.java