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

    Object val2 = mock(Object.class);
    setState(mSrc2, NOT_CLOSED, NOT_FINISHED, WITH_RESULT, val2, NOT_FAILED, null);
    subscriber2.onNewResult(mSrc2);
    mInOrder.verify(mSrc3).close();
    verifySubscriber(dataSource, mSrc2, ON_NEW_RESULT);
    verifyState(dataSource, mSrc2, NOT_CLOSED, NOT_FINISHED, WITH_RESULT, val2, NOT_FAILED, null);

    setState(mSrc2, NOT_CLOSED, FINISHED, WITH_RESULT, val2, FAILED, mock(Throwable.class));
    subscriber2.onFailure(mSrc2);
    verifySubscriber(dataSource, mSrc2, NO_INTERACTIONS);
    verifyState(dataSource, mSrc2, NOT_CLOSED, NOT_FINISHED, WITH_RESULT, val2, NOT_FAILED, null);

    Throwable throwable = mock(Throwable.class);
    setState(mSrc1, NOT_CLOSED, FINISHED, WITHOUT_RESULT, null, FAILED, throwable);
    subscriber1.onFailure(mSrc1);
    mInOrder.verify(mSrc1).close();
    verifySubscriber(dataSource, mSrc1, ON_FAILURE);
    verifyState(dataSource, mSrc2, NOT_CLOSED, FINISHED, WITH_RESULT, val2, FAILED, throwable);

    // gets ignored because DS1 failed
    // besides, this data source shouldn't have finished as it was supposed to be closed!
    setState(mSrc3, NOT_CLOSED, FINISHED, WITH_RESULT, mock(Object.class), NOT_FAILED, null);
    subscriber3.onFailure(mSrc3);
    mInOrder.verify(mSrc3).close();
    verifySubscriber(dataSource, mSrc3, NO_INTERACTIONS);
    verifyState(dataSource, mSrc2, NOT_CLOSED, FINISHED, WITH_RESULT, val2, FAILED, throwable);

    testClose(dataSource, mSrc2);
    verifyState(dataSource, null, CLOSED, FINISHED, WITHOUT_RESULT, null, FAILED, throwable);
  }
Highest-quality data source failed, result of the third data source is ignored. Second data
source produced intermediate result first, the result is preserved until closed.
fbcore/src/test/java/com/facebook/datasource/IncreasingQualityDataSourceSupplierTest.java