Example #1
0
 @Test
 public void diskLruCachePut_withEmptyStringKey_shouldPutCorrectly() throws Exception {
   // this works because an empty string sha1 hashes to a valid key
   CacheService.initialize(context);
   CacheService.putToDiskCache("", data1.getBytes());
   assertThat(CacheService.getFromDiskCache("")).isEqualTo(data1.getBytes());
 }
Example #2
0
 @Test
 public void diskLruCachePut_withNullKey_shouldNotPut() throws Exception {
   // null value produces empty string key which is invalid for disk lru cache
   CacheService.initialize(context);
   assertCachesAreEmpty();
   CacheService.putToDiskCache(null, data1.getBytes());
   assertCachesAreEmpty();
 }
Example #3
0
 @Test
 public void diskLruCacheAsyncGet_whenPopulated_shouldReturnValue() throws Exception {
   CacheService.initialize(context);
   assertCachesAreEmpty();
   CacheService.putToDiskCache(key1, data1.getBytes());
   CacheService.getFromDiskCacheAsync(key1, diskCacheGetListener);
   semaphore.acquire();
   assertThat(getKey).isEqualTo(key1);
   assertThat(getBytes).isEqualTo(data1.getBytes());
 }
Example #4
0
 @Test
 public void diskLruCacheGet_whenPopulated_shouldReturnValue() throws Exception {
   CacheService.initialize(context);
   CacheService.putToDiskCache(key1, data1.getBytes());
   assertThat(CacheService.getFromDiskCache(key1)).isEqualTo(data1.getBytes());
 }