@Test
public void testReadWithErrorSessionReadsNothingAndThrows() throws IOException {

  when(mockDrmSession.getState()).thenReturn(DrmSession.STATE_OPENED);
  writeTestDataWithEncryptedSections();
  assertReadFormat(/* formatRequired= */ false, FORMAT_ENCRYPTED);
  assertReadNothing(/* formatRequired= */ false);
  sampleQueue.maybeThrowError();
  when(mockDrmSession.getState()).thenReturn(DrmSession.STATE_ERROR);
  when(mockDrmSession.getError()).thenReturn(new DrmSession.DrmSessionException(new Exception()));
  assertReadNothing(/* formatRequired= */ false);
  try {
    sampleQueue.maybeThrowError();
    Assert.fail();
  } catch (IOException e) {
    // Expected.
  }
  when(mockDrmSession.getState()).thenReturn(DrmSession.STATE_OPENED_WITH_KEYS);
  assertReadEncryptedSample(/* sampleIndex= */ 0);
}