@Test
  public void testLifecycle_I1_F1_I2_C() {
    DataSource<Object> dataSource = getAndSubscribe();
    DataSubscriber<Object> subscriber1 = verifyGetAndSubscribe(mDataSourceSupplier1, mSrc1);

    Object val1 = mock(Object.class);
    setState(mSrc1, NOT_CLOSED, NOT_FINISHED, WITH_RESULT, val1, NOT_FAILED, null);
    subscriber1.onNewResult(mSrc1);
    verifySubscriber(dataSource, mSrc1, ON_NEW_RESULT);
    verifyState(dataSource, mSrc1, NOT_CLOSED, NOT_FINISHED, WITH_RESULT, val1, NOT_FAILED, null);

    setState(mSrc1, NOT_CLOSED, FINISHED, WITH_RESULT, val1, FAILED, mock(Throwable.class));
    subscriber1.onFailure(mSrc1);
    DataSubscriber<Object> subscriber2 = verifyGetAndSubscribe(mDataSourceSupplier2, mSrc2);
    verifyState(dataSource, mSrc1, NOT_CLOSED, NOT_FINISHED, WITH_RESULT, val1, NOT_FAILED, null);

    // I2 gets ignored because we already have I1
    Object val2 = mock(Object.class);
    setState(mSrc2, NOT_CLOSED, NOT_FINISHED, WITH_RESULT, val2, NOT_FAILED, null);
    subscriber2.onNewResult(mSrc2);
    verifySubscriber(dataSource, mSrc2, NO_INTERACTIONS);
    verifyState(dataSource, mSrc1, NOT_CLOSED, NOT_FINISHED, WITH_RESULT, val1, NOT_FAILED, null);

    testClose(dataSource, mSrc1, mSrc2);
    verifySubscriber(dataSource, null, ON_CANCELLATION);
    verifyState(dataSource, null, CLOSED, NOT_FINISHED, WITHOUT_RESULT, null, NOT_FAILED, null);
  }
First data source failed with intermediate results, second had intermediate results but closed.
fbcore/src/test/java/com/facebook/datasource/FirstAvailableDataSourceSupplierTest.java