@@ -0,0 +1,2769 @@
+/*%0A * Copyright (C) 2021 The Android Open Source Project%0A *%0A * Licensed under the Apache License, Version 2.0 (the %22License%22);%0A * you may not use this file except in compliance with the License.%0A * You may obtain a copy of the License at%0A *%0A *      http://www.apache.org/licenses/LICENSE-2.0%0A *%0A * Unless required by applicable law or agreed to in writing, software%0A * distributed under the License is distributed on an %22AS IS%22 BASIS,%0A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A * See the License for the specific language governing permissions and%0A * limitations under the License.%0A */%0Apackage com.google.android.exoplayer2.upstream;%0A%0Aimport android.net.Uri;%0Aimport androidx.test.core.app.ApplicationProvider;%0Aimport androidx.test.ext.junit.runners.AndroidJUnit4;%0Aimport com.google.android.exoplayer2.testutil.DataSourceContractTest;%0Aimport com.google.android.exoplayer2.testutil.TestUtil;%0Aimport com.google.android.exoplayer2.upstream.cache.CacheDataSource;%0Aimport com.google.android.exoplayer2.upstream.cache.NoOpCacheEvictor;%0Aimport com.google.android.exoplayer2.upstream.cache.SimpleCache;%0Aimport com.google.android.exoplayer2.util.Util;%0Aimport com.google.common.collect.ImmutableList;%0Aimport java.io.File;%0Aimport java.io.IOException;%0Aimport java.nio.file.Files;%0Aimport java.nio.file.Paths;%0Aimport org.junit.Before;%0Aimport org.junit.Rule;%0Aimport org.junit.rules.TemporaryFolder;%0Aimport org.junit.runner.RunWith;%0A%0A/** %7B@link DataSource%7D contract tests for %7B@link CacheDataSource%7D. */%0A@RunWith(AndroidJUnit4.class)%0Apublic class CacheDataSourceContractTest extends DataSourceContractTest %7B%0A  private static final byte%5B%5D DATA = TestUtil.buildTestData(20);%0A%0A  @Rule public final TemporaryFolder tempFolder = new TemporaryFolder();%0A%0A  private Uri simpleUri;%0A%0A  @Before%0A  public void setUp() throws IOException %7B%0A    File file = tempFolder.newFile();%0A    Files.write(Paths.get(file.getAbsolutePath()), DATA);%0A    simpleUri = Uri.fromFile(file);%0A  %7D%0A%0A  @Override%0A  protected ImmutableList%3CTestResource%3E getTestResources() %7B%0A    return ImmutableList.of(%0A        new TestResource.Builder()%0A            .setName(%22simple%22)%0A            .setUri(simpleUri)%0A            .setExpectedBytes(DATA)%0A            .build());%0A  %7D%0A%0A  @Override%0A  protected Uri getNotFoundUri() %7B%0A    return Uri.fromFile(tempFolder.getRoot().toPath().resolve(%22nonexistent%22).toFile());%0A  %7D%0A%0A  @Override%0A  protected DataSource createDataSource() throws IOException %7B%0A    File tempFolder =%0A        Util.createTempDirectory(ApplicationProvider.getApplicationContext(), %22ExoPlayerTest%22);%0A    SimpleCache cache =%0A        new SimpleCache(tempFolder, new NoOpCacheEvictor(), TestUtil.getInMemoryDatabaseProvider());%0A    return new CacheDataSource(cache, new FileDataSource());%0A  %7D%0A%7D%0A

Add contract test for CacheDataSource