@Test
@SuppressWarnings("unchecked")
public void testTrailingCryptoInfoInitializationVectorBytesZeroed() {

  when(mockDrmSession.getState()).thenReturn(DrmSession.STATE_OPENED_WITH_KEYS);
  DrmSession<ExoMediaCrypto> mockPlaceholderDrmSession =
      (DrmSession<ExoMediaCrypto>) Mockito.mock(DrmSession.class);
  when(mockPlaceholderDrmSession.getState()).thenReturn(DrmSession.STATE_OPENED_WITH_KEYS);
  when(mockDrmSessionManager.acquirePlaceholderSession(
          ArgumentMatchers.any(), ArgumentMatchers.anyInt()))
      .thenReturn(mockPlaceholderDrmSession);
  writeFormat(ENCRYPTED_SAMPLE_FORMATS[0]);
  byte[] sampleData = new byte[] {0, 1, 2};
  byte[] initializationVector = new byte[] {7, 6, 5, 4, 3, 2, 1, 0};
  byte[] encryptedSampleData =
      TestUtil.joinByteArrays(
          new byte[] {
            0x08, // subsampleEncryption = false (1 bit), ivSize = 8 (7 bits).
          },
          initializationVector,
          sampleData);
  writeSample(
      encryptedSampleData, /* timestampUs= */ 0, BUFFER_FLAG_KEY_FRAME | BUFFER_FLAG_ENCRYPTED);
  int result =
      sampleQueue.read(
          formatHolder,
          inputBuffer,
          /* formatRequired= */ false,
          /* loadingFinished= */ false,
          /* decodeOnlyUntilUs= */ 0);
  assertThat(result).isEqualTo(RESULT_FORMAT_READ);
  // Fill cryptoInfo.iv with non-zero data. When the 8 byte initialization vector is written into
  // it, we expect the trailing 8 bytes to be zeroed.
  inputBuffer.cryptoInfo.iv = new byte[16];
  Arrays.fill(inputBuffer.cryptoInfo.iv, (byte) 1);
  result =
      sampleQueue.read(
          formatHolder,
          inputBuffer,
          /* formatRequired= */ false,
          /* loadingFinished= */ false,
          /* decodeOnlyUntilUs= */ 0);
  assertThat(result).isEqualTo(RESULT_BUFFER_READ);
  // Assert cryptoInfo.iv contains the 8-byte initialization vector and that the trailing 8 bytes
  // have been zeroed.
  byte[] expectedInitializationVector = Arrays.copyOf(initializationVector, 16);
  assertArrayEquals(expectedInitializationVector, inputBuffer.cryptoInfo.iv);
}