Rename some assert methods in CacheAsserts to better reflect what they do
------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=160873280
This commit is contained in:
parent
05a77eef5d
commit
37faead26e
@ -29,6 +29,7 @@ import com.google.android.exoplayer2.upstream.cache.CacheDataSource;
|
|||||||
import com.google.android.exoplayer2.upstream.cache.CacheUtil;
|
import com.google.android.exoplayer2.upstream.cache.CacheUtil;
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
import junit.framework.Assert;
|
import junit.framework.Assert;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -38,31 +39,38 @@ public final class CacheAsserts {
|
|||||||
|
|
||||||
/** Asserts that the cache content is equal to the data in the {@code fakeDataSet}. */
|
/** Asserts that the cache content is equal to the data in the {@code fakeDataSet}. */
|
||||||
public static void assertCachedData(Cache cache, FakeDataSet fakeDataSet) throws IOException {
|
public static void assertCachedData(Cache cache, FakeDataSet fakeDataSet) throws IOException {
|
||||||
|
ArrayList<FakeData> allData = fakeDataSet.getAllData();
|
||||||
|
String[] uriStrings = new String[allData.size()];
|
||||||
|
for (int i = 0; i < allData.size(); i++) {
|
||||||
|
uriStrings[i] = allData.get(i).uri;
|
||||||
|
}
|
||||||
|
assertCachedData(cache, fakeDataSet, uriStrings);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Asserts that the cache content is equal to the given subset of data in the {@code fakeDataSet}.
|
||||||
|
*/
|
||||||
|
public static void assertCachedData(Cache cache, FakeDataSet fakeDataSet, String... uriStrings)
|
||||||
|
throws IOException {
|
||||||
int totalLength = 0;
|
int totalLength = 0;
|
||||||
for (FakeData fakeData : fakeDataSet.getAllData()) {
|
for (String uriString : uriStrings) {
|
||||||
byte[] data = fakeData.getData();
|
byte[] data = fakeDataSet.getData(uriString).getData();
|
||||||
assertCachedData(cache, fakeData.uri, data);
|
assertDataCached(cache, uriString, data);
|
||||||
totalLength += data.length;
|
totalLength += data.length;
|
||||||
}
|
}
|
||||||
assertEquals(totalLength, cache.getCacheSpace());
|
assertEquals(totalLength, cache.getCacheSpace());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/** Asserts that the cache contains the given subset of data in the {@code fakeDataSet}. */
|
||||||
* Asserts that the cache content for the given {@code uriStrings} are equal to the data in the
|
public static void assertDataCached(Cache cache, FakeDataSet fakeDataSet, String... uriStrings)
|
||||||
* {@code fakeDataSet}.
|
|
||||||
*/
|
|
||||||
public static void assertCachedData(Cache cache, FakeDataSet fakeDataSet, String... uriStrings)
|
|
||||||
throws IOException {
|
throws IOException {
|
||||||
for (String uriString : uriStrings) {
|
for (String uriString : uriStrings) {
|
||||||
assertCachedData(cache, uriString, fakeDataSet.getData(uriString).getData());
|
assertDataCached(cache, uriString, fakeDataSet.getData(uriString).getData());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/** Asserts that the cache contains the given data for {@code uriString}. */
|
||||||
* Asserts that the cache content for the given {@code uriString} is equal to the {@code
|
public static void assertDataCached(Cache cache, String uriString, byte[] expected)
|
||||||
* expected}.
|
|
||||||
*/
|
|
||||||
public static void assertCachedData(Cache cache, String uriString, byte[] expected)
|
|
||||||
throws IOException {
|
throws IOException {
|
||||||
CacheDataSource dataSource = new CacheDataSource(cache, DummyDataSource.INSTANCE, 0);
|
CacheDataSource dataSource = new CacheDataSource(cache, DummyDataSource.INSTANCE, 0);
|
||||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||||
@ -85,18 +93,14 @@ public final class CacheAsserts {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Asserts that there is no cache content for the given {@code uriStrings}. */
|
/** Asserts that there is no cache content for the given {@code uriStrings}. */
|
||||||
public static void assertNoCachedData(Cache cache, String... uriStrings) {
|
public static void assertDataNotCached(Cache cache, String... uriStrings) {
|
||||||
for (String uriString : uriStrings) {
|
for (String uriString : uriStrings) {
|
||||||
Assert.assertNull("There is cached data for '" + uriString + "',",
|
Assert.assertNull("There is cached data for '" + uriString + "',",
|
||||||
cache.getCachedSpans(CacheUtil.generateKey(Uri.parse(uriString))));
|
cache.getCachedSpans(CacheUtil.generateKey(Uri.parse(uriString))));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/** Asserts that the cache is empty. */
|
||||||
* Asserts that the cache is empty.
|
|
||||||
*
|
|
||||||
* @param cache
|
|
||||||
*/
|
|
||||||
public static void assertCacheEmpty(Cache cache) {
|
public static void assertCacheEmpty(Cache cache) {
|
||||||
assertEquals(0, cache.getCacheSpace());
|
assertEquals(0, cache.getCacheSpace());
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user