@Test
public void testCacheUnknownLengthPartialCaching() throws Exception {

  FakeDataSet fakeDataSet = new FakeDataSet().newData("test_data")
      .setSimulateUnknownLength(true)
      .appendReadData(TestUtil.buildTestData(100)).endData();
  FakeDataSource dataSource = new FakeDataSource(fakeDataSet);
  Uri testUri = Uri.parse("test_data");
  DataSpec dataSpec = new DataSpec(testUri, 10, 20, null);
  CachingCounters counters = new CachingCounters();
  CacheUtil.cache(
      dataSpec, cache, /* cacheKeyFactory= */ null, dataSource, counters, /* isCanceled= */ null);
  counters.assertValues(0, 20, 20);
  counters.reset();
  CacheUtil.cache(
      new DataSpec(testUri),
      cache,
      /* cacheKeyFactory= */ null,
      dataSource,
      counters,
      /* isCanceled= */ null);
  counters.assertValues(20, 80, 100);
  assertCachedData(cache, fakeDataSet);
}