Home | History | Annotate | Download | only in deletionhelper
      1 /*
      2  * Copyright (C) 2016 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
      5  * use this file except in compliance with the License. You may obtain a copy of
      6  * the License at
      7  *
      8  * http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
     12  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
     13  * License for the specific language governing permissions and limitations under
     14  * the License.
     15  */
     16 
     17 package com.android.storagemanager.deletionhelper;
     18 
     19 import android.content.Context;
     20 import com.android.storagemanager.testing.StorageManagerRobolectricTestRunner;
     21 import com.android.storagemanager.testing.TestingConstants;
     22 import org.junit.Test;
     23 import org.junit.runner.RunWith;
     24 import org.mockito.Mock;
     25 import org.mockito.MockitoAnnotations;
     26 import org.robolectric.annotation.Config;
     27 import org.robolectric.shadows.ShadowApplication;
     28 
     29 
     30 import java.util.concurrent.TimeUnit;
     31 
     32 import static android.content.DialogInterface.BUTTON_NEGATIVE;
     33 import static com.google.common.truth.Truth.assertThat;
     34 import static org.mockito.Mockito.when;
     35 import static org.robolectric.util.FragmentTestUtil.startFragment;
     36 
     37 @RunWith(StorageManagerRobolectricTestRunner.class)
     38 @Config(manifest= TestingConstants.MANIFEST, sdk=TestingConstants.SDK_VERSION)
     39 public class StorageManagerUpsellDialogTest {
     40     @Mock
     41     StorageManagerUpsellDialog.Clock mClock;
     42 
     43     @Test
     44     public void testNoThanksMaximumShownTimes() {
     45         MockitoAnnotations.initMocks(this);
     46         final Context context = ShadowApplication.getInstance().getApplicationContext();
     47         StorageManagerUpsellDialog fragment = StorageManagerUpsellDialog.newInstance(0);
     48         fragment.setClock(mClock);
     49 
     50         assertThat(StorageManagerUpsellDialog.shouldShow(context, TimeUnit.DAYS.toMillis(90)))
     51                 .isTrue();
     52 
     53         startFragment(fragment);
     54         fragment.onClick(null, BUTTON_NEGATIVE);
     55         when(mClock.currentTimeMillis()).thenReturn(TimeUnit.DAYS.toMillis(90 * 2));
     56         assertThat(StorageManagerUpsellDialog.shouldShow(context, TimeUnit.DAYS.toMillis(90 * 2)))
     57                 .isTrue();
     58 
     59         startFragment(fragment);
     60         fragment.onClick(null, BUTTON_NEGATIVE);
     61         when(mClock.currentTimeMillis()).thenReturn(TimeUnit.DAYS.toMillis(90 * 3));
     62         assertThat(StorageManagerUpsellDialog.shouldShow(context, TimeUnit.DAYS.toMillis(90 * 3)))
     63                 .isTrue();
     64 
     65         startFragment(fragment);
     66         fragment.onClick(null, BUTTON_NEGATIVE);
     67         when(mClock.currentTimeMillis()).thenReturn(TimeUnit.DAYS.toMillis(90 * 4));
     68         assertThat(StorageManagerUpsellDialog.shouldShow(context, TimeUnit.DAYS.toMillis(90 * 4)))
     69                 .isTrue();
     70 
     71         startFragment(fragment);
     72         fragment.onClick(null, BUTTON_NEGATIVE);
     73         when(mClock.currentTimeMillis()).thenReturn(TimeUnit.DAYS.toMillis(90 * 5));
     74         assertThat(StorageManagerUpsellDialog.shouldShow(context, TimeUnit.DAYS.toMillis(90 * 5)))
     75                 .isFalse();
     76     }
     77 }
     78