Commit 37faead2 by eguven Committed by Oliver Woodman

Rename some assert methods in CacheAsserts to better reflect what they do

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=160873280
parent 05a77eef
...@@ -29,6 +29,7 @@ import com.google.android.exoplayer2.upstream.cache.CacheDataSource; ...@@ -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 { ...@@ -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 {
int totalLength = 0; ArrayList<FakeData> allData = fakeDataSet.getAllData();
for (FakeData fakeData : fakeDataSet.getAllData()) { String[] uriStrings = new String[allData.size()];
byte[] data = fakeData.getData(); for (int i = 0; i < allData.size(); i++) {
assertCachedData(cache, fakeData.uri, data); uriStrings[i] = allData.get(i).uri;
totalLength += data.length;
} }
assertEquals(totalLength, cache.getCacheSpace()); assertCachedData(cache, fakeDataSet, uriStrings);
} }
/** /**
* Asserts that the cache content for the given {@code uriStrings} are equal to the data in the * Asserts that the cache content is equal to the given subset of data in the {@code fakeDataSet}.
* {@code fakeDataSet}.
*/ */
public static void assertCachedData(Cache cache, FakeDataSet fakeDataSet, String... uriStrings) public static void assertCachedData(Cache cache, FakeDataSet fakeDataSet, String... uriStrings)
throws IOException { throws IOException {
int totalLength = 0;
for (String uriString : uriStrings) { for (String uriString : uriStrings) {
assertCachedData(cache, uriString, fakeDataSet.getData(uriString).getData()); byte[] data = fakeDataSet.getData(uriString).getData();
assertDataCached(cache, uriString, data);
totalLength += data.length;
} }
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 uriString} is equal to the {@code public static void assertDataCached(Cache cache, FakeDataSet fakeDataSet, String... uriStrings)
* expected}. throws IOException {
*/ for (String uriString : uriStrings) {
public static void assertCachedData(Cache cache, String uriString, byte[] expected) assertDataCached(cache, uriString, fakeDataSet.getData(uriString).getData());
}
}
/** Asserts that the cache contains the given data for {@code uriString}. */
public static void assertDataCached(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 { ...@@ -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());
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment