AssetManager { @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP) @WorkerThread public void onDisplayFinished(@NonNull String scheduleId, @NonNull InAppMessage inAppMessage) { CachePolicyDelegate cachePolicyDelegate = this.cachePolicyDelegate; boolean delete = false; if (cachePolicyDelegate == null || !cachePolicyDelegate.shouldPersistCacheAfterDisplay(scheduleId, inAppMessage)) { delete = true; } assetCache.releaseAssets(scheduleId, delete); } @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)  AssetManager(@NonNull Context context); @VisibleForTesting  AssetManager(@NonNull AssetCache assetCache); void setPrepareAssetDelegate(@Nullable PrepareAssetsDelegate assetsDelegate); void setCachePolicyDelegate(@Nullable CachePolicyDelegate cachePolicyDelegate); @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP) @WorkerThread void onSchedule(@NonNull String scheduleId, @NonNull Callable<InAppMessage> extendedMessageCallable); @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP) @WorkerThread @PrepareResult int onPrepare(@NonNull String scheduleId, @NonNull InAppMessage message); @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP) @WorkerThread void onDisplayFinished(@NonNull String scheduleId, @NonNull InAppMessage inAppMessage); @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP) @WorkerThread void onFinish(@NonNull String scheduleId); @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP) @NonNull Assets getAssets(@NonNull String scheduleId); static final int PREPARE_RESULT_OK; static final int PREPARE_RESULT_RETRY; static final int PREPARE_RESULT_CANCEL; }
@Test public void testClearAssetsDisplayFinished() { when(mockCachePolicyDelegate.shouldPersistCacheAfterDisplay("some-id", MESSAGE)).thenReturn(false); assetManager.onDisplayFinished("some-id", MESSAGE); verify(mockCache).releaseAssets("some-id", true); }
@Test public void testPersistAfterDisplay() { when(mockCachePolicyDelegate.shouldPersistCacheAfterDisplay("some-id", MESSAGE)).thenReturn(true); assetManager.onDisplayFinished("some-id", MESSAGE); verifyZeroInteractions(mockAssetsDelegate); verify(mockCache).releaseAssets("some-id", false); }