@Test
public void testReadEncryptedSectionsPopulatesDrmSession() {

  when(mockDrmSession.getState()).thenReturn(DrmSession.STATE_OPENED_WITH_KEYS);
  writeTestDataWithEncryptedSections();
  int result =
      sampleQueue.read(
          formatHolder,
          inputBuffer,
          /* formatRequired= */ false,
          /* loadingFinished= */ false,
          /* decodeOnlyUntilUs= */ 0);
  assertThat(result).isEqualTo(RESULT_FORMAT_READ);
  assertThat(formatHolder.drmSession).isSameInstanceAs(mockDrmSession);
  assertReadEncryptedSample(/* sampleIndex= */ 0);
  assertReadEncryptedSample(/* sampleIndex= */ 1);
  formatHolder.clear();
  assertThat(formatHolder.drmSession).isNull();
  result =
      sampleQueue.read(
          formatHolder,
          inputBuffer,
          /* formatRequired= */ false,
          /* loadingFinished= */ false,
          /* decodeOnlyUntilUs= */ 0);
  assertThat(result).isEqualTo(RESULT_FORMAT_READ);
  assertThat(formatHolder.drmSession).isNull();
  assertReadEncryptedSample(/* sampleIndex= */ 2);
  result =
      sampleQueue.read(
          formatHolder,
          inputBuffer,
          /* formatRequired= */ false,
          /* loadingFinished= */ false,
          /* decodeOnlyUntilUs= */ 0);
  assertThat(result).isEqualTo(RESULT_FORMAT_READ);
  assertThat(formatHolder.drmSession).isSameInstanceAs(mockDrmSession);
}