@Test
public void testRequestOpenValidatesStatusCode() {

  mockResponseStartSuccess();
  testUrlResponseInfo = createUrlResponseInfo(500); // statusCode
  try {
    dataSourceUnderTest.open(testDataSpec);
    fail("HttpDataSource.HttpDataSourceException expected");
  } catch (HttpDataSourceException e) {
    assertThat(e instanceof HttpDataSource.InvalidResponseCodeException).isTrue();
    // Check for connection not automatically closed.
    verify(mockUrlRequest, never()).cancel();
    verify(mockTransferListener, never())
        .onTransferStart(dataSourceUnderTest, testDataSpec, /* isNetwork= */ true);
  }
}