aboutsummaryrefslogtreecommitdiff
path: root/src/test/java/com/android/volley/utils/CacheTestUtils.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/java/com/android/volley/utils/CacheTestUtils.java')
-rw-r--r--src/test/java/com/android/volley/utils/CacheTestUtils.java35
1 files changed, 35 insertions, 0 deletions
diff --git a/src/test/java/com/android/volley/utils/CacheTestUtils.java b/src/test/java/com/android/volley/utils/CacheTestUtils.java
index 49ab996..5980712 100644
--- a/src/test/java/com/android/volley/utils/CacheTestUtils.java
+++ b/src/test/java/com/android/volley/utils/CacheTestUtils.java
@@ -16,6 +16,11 @@
package com.android.volley.utils;
+import static org.hamcrest.Matchers.equalTo;
+import static org.hamcrest.Matchers.is;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertThat;
+
import com.android.volley.Cache;
import java.util.Random;
@@ -51,4 +56,34 @@ public class CacheTestUtils {
public static Cache.Entry makeRandomCacheEntry(byte[] data) {
return makeRandomCacheEntry(data, false, false);
}
+
+ public static void assertThatEntriesAreEqual(Cache.Entry actual, Cache.Entry expected) {
+ assertNotNull(actual);
+ assertThat(actual.data, is(equalTo(expected.data)));
+ assertThat(actual.etag, is(equalTo(expected.etag)));
+ assertThat(actual.lastModified, is(equalTo(expected.lastModified)));
+ assertThat(actual.responseHeaders, is(equalTo(expected.responseHeaders)));
+ assertThat(actual.serverDate, is(equalTo(expected.serverDate)));
+ assertThat(actual.softTtl, is(equalTo(expected.softTtl)));
+ assertThat(actual.ttl, is(equalTo(expected.ttl)));
+ }
+
+ public static Cache.Entry randomData(int length) {
+ Cache.Entry entry = new Cache.Entry();
+ byte[] data = new byte[length];
+ new Random(42).nextBytes(data); // explicit seed for reproducible results
+ entry.data = data;
+ return entry;
+ }
+
+ public static int getEntrySizeOnDisk(String key) {
+ // Header size is:
+ // 4 bytes for magic int
+ // 8 + len(key) bytes for key (long length)
+ // 8 bytes for etag (long length + 0 characters)
+ // 32 bytes for serverDate, lastModified, ttl, and softTtl longs
+ // 4 bytes for length of header list int
+ // == 56 + len(key) bytes total.
+ return 56 + key.length();
+ }
}