@Test
public void mergeRequest_existingDownload_createsMergedDownload() throws IOException {

  StreamKey streamKey1 =
      new StreamKey(/* periodIndex= */ 3, /* groupIndex= */ 4, /* trackIndex= */ 5);
  StreamKey streamKey2 =
      new StreamKey(/* periodIndex= */ 0, /* groupIndex= */ 1, /* trackIndex= */ 2);
  DownloadRequest request1 =
      new DownloadRequest(
          "id",
          TYPE_PROGRESSIVE,
          Uri.parse("https://www.test.com/download1"),
          asList(streamKey1),
          /* customCacheKey= */ "key123",
          new byte[] {1, 2, 3, 4});
  DownloadRequest request2 =
      new DownloadRequest(
          "id",
          TYPE_PROGRESSIVE,
          Uri.parse("https://www.test.com/download2"),
          asList(streamKey2),
          /* customCacheKey= */ "key123",
          new byte[] {5, 4, 3, 2, 1});
  ActionFileUpgradeUtil.mergeRequest(
      request1, downloadIndex, /* addNewDownloadAsCompleted= */ false, NOW_MS);
  ActionFileUpgradeUtil.mergeRequest(
      request2, downloadIndex, /* addNewDownloadAsCompleted= */ false, NOW_MS);
  Download download = downloadIndex.getDownload(request2.id);
  assertThat(download).isNotNull();
  assertThat(download.request.type).isEqualTo(request2.type);
  assertThat(download.request.customCacheKey).isEqualTo(request2.customCacheKey);
  assertThat(download.request.data).isEqualTo(request2.data);
  assertThat(download.request.uri).isEqualTo(request2.uri);
  assertThat(download.request.streamKeys).containsExactly(streamKey1, streamKey2);
  assertThat(download.state).isEqualTo(Download.STATE_QUEUED);
}