Example #1
0
 @Test
 public void diskLruCacheAsyncPut_whenEmpty_shouldReturnNull() throws Exception {
   CacheService.initialize(context);
   CacheService.putToDiskCacheAsync(key1, data1.getBytes());
   Thread.sleep(500);
   assertThat(CacheService.getFromDiskCache(key1)).isEqualTo(data1.getBytes());
 }
Example #2
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 #3
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 #4
0
 @Test
 public void diskLruCacheAsyncGet_whenEmpty_shouldReturnNull() throws Exception {
   CacheService.initialize(context);
   CacheService.getFromDiskCacheAsync(key1, diskCacheGetListener);
   semaphore.acquire();
   assertThat(getKey).isEqualTo(key1);
   assertThat(getBytes).isNull();
 }
Example #5
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 #6
0
  @Test
  public void initializeCache_withValidContext_shouldCreateNewCachesIdempotently()
      throws Exception {
    assertThat(CacheService.getDiskLruCache()).isNull();

    CacheService.initialize(context);
    DiskLruCache diskLruCache = CacheService.getDiskLruCache();
    assertThat(diskLruCache).isNotNull();

    CacheService.initialize(context);
    assertThat(diskLruCache).isEqualTo(CacheService.getDiskLruCache());
  }
    @Override
    public void prepareTest(Object test) {
      ClientMetadata.clearForTesting();

      DateAndTime.setInstance(new TestDateAndTime());
      CustomEventBannerFactory.setInstance(new TestCustomEventBannerFactory());
      CustomEventInterstitialFactory.setInstance(new TestCustomEventInterstitialFactory());
      CustomEventBannerAdapterFactory.setInstance(new TestCustomEventBannerAdapterFactory());
      MoPubViewFactory.setInstance(new TestMoPubViewFactory());
      CustomEventInterstitialAdapterFactory.setInstance(
          new TestCustomEventInterstitialAdapterFactory());
      HtmlBannerWebViewFactory.setInstance(new TestHtmlBannerWebViewFactory());
      HtmlInterstitialWebViewFactory.setInstance(new TestHtmlInterstitialWebViewFactory());
      AdViewControllerFactory.setInstance(new TestAdViewControllerFactory());
      VastManagerFactory.setInstance(new TestVastManagerFactory());
      MethodBuilderFactory.setInstance(new TestMethodBuilderFactory());
      CustomEventNativeFactory.setInstance(new TestCustomEventNativeFactory());
      MraidControllerFactory.setInstance(new TestMraidControllerFactory());

      ShadowAsyncTasks.reset();
      ShadowMoPubHttpUrlConnection.reset();
      MoPubEvents.setEventDispatcher(mock(EventDispatcher.class));
      MoPub.setLocationAwareness(LocationAwareness.NORMAL);
      MoPub.setLocationPrecision(6);

      MockitoAnnotations.initMocks(test);

      AsyncTasks.setExecutor(new RoboExecutorService());
      CacheService.clearAndNullCaches();
    }
Example #8
0
 @Test
 public void diskLruCacheGet_whenEmpty_shouldReturnNull() throws Exception {
   CacheService.initialize(context);
   assertCachesAreEmpty();
   assertThat(CacheService.getFromDiskCache(key1)).isNull();
 }
Example #9
0
 @Test
 public void diskLruCacheGet_whenPopulated_shouldReturnValue() throws Exception {
   CacheService.initialize(context);
   CacheService.putToDiskCache(key1, data1.getBytes());
   assertThat(CacheService.getFromDiskCache(key1)).isEqualTo(data1.getBytes());
 }
Example #10
0
 @Test
 public void getDiskLruCacheDirectory_shouldReturnValidCacheDirectory() throws Exception {
   File file = CacheService.getDiskCacheDirectory(context);
   String expectedPath = context.getCacheDir().toString() + "/mopub-cache";
   assertThat(file.getAbsolutePath()).isEqualTo(expectedPath);
 }
Example #11
0
 public static void assertDiskCacheIsEmpty() {
   assertThat(CacheService.getDiskLruCache()).isNotNull();
   assertThat(CacheService.getDiskLruCache().size()).isEqualTo(0);
 }
Example #12
0
 public static void assertDiskCacheIsUninitialized() {
   assertThat(CacheService.getDiskLruCache()).isNull();
 }
Example #13
0
 @Test
 public void createValidDiskLruCacheKey_withNullValue_shouldReturnEmptyString() throws Exception {
   CacheService.initialize(context);
   assertThat(CacheService.createValidDiskCacheKey(null)).isEqualTo("");
 }