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 org.junit.Test; 21 import org.junit.runner.RunWith; 22 import org.mockito.Mock; 23 import org.mockito.MockitoAnnotations; 24 import org.robolectric.RobolectricTestRunner; 25 import org.robolectric.RuntimeEnvironment; 26 27 import java.util.concurrent.TimeUnit; 28 29 import static android.content.DialogInterface.BUTTON_NEGATIVE; 30 import static com.google.common.truth.Truth.assertThat; 31 import static org.mockito.Mockito.when; 32 import static org.robolectric.util.FragmentTestUtil.startFragment; 33 34 @RunWith(RobolectricTestRunner.class) 35 public class StorageManagerUpsellDialogTest { 36 @Mock private StorageManagerUpsellDialog.Clock mClock; 37 38 @Test testNoThanksMaximumShownTimes()39 public void testNoThanksMaximumShownTimes() { 40 MockitoAnnotations.initMocks(this); 41 final Context context = RuntimeEnvironment.application; 42 StorageManagerUpsellDialog fragment = StorageManagerUpsellDialog.newInstance(0); 43 fragment.setClock(mClock); 44 45 assertThat(StorageManagerUpsellDialog.shouldShow(context, TimeUnit.DAYS.toMillis(90))) 46 .isTrue(); 47 48 startFragment(fragment); 49 fragment.onClick(null, BUTTON_NEGATIVE); 50 when(mClock.currentTimeMillis()).thenReturn(TimeUnit.DAYS.toMillis(90 * 2)); 51 assertThat(StorageManagerUpsellDialog.shouldShow(context, TimeUnit.DAYS.toMillis(90 * 2))) 52 .isTrue(); 53 54 startFragment(fragment); 55 fragment.onClick(null, BUTTON_NEGATIVE); 56 when(mClock.currentTimeMillis()).thenReturn(TimeUnit.DAYS.toMillis(90 * 3)); 57 assertThat(StorageManagerUpsellDialog.shouldShow(context, TimeUnit.DAYS.toMillis(90 * 3))) 58 .isTrue(); 59 60 startFragment(fragment); 61 fragment.onClick(null, BUTTON_NEGATIVE); 62 when(mClock.currentTimeMillis()).thenReturn(TimeUnit.DAYS.toMillis(90 * 4)); 63 assertThat(StorageManagerUpsellDialog.shouldShow(context, TimeUnit.DAYS.toMillis(90 * 4))) 64 .isTrue(); 65 66 startFragment(fragment); 67 fragment.onClick(null, BUTTON_NEGATIVE); 68 when(mClock.currentTimeMillis()).thenReturn(TimeUnit.DAYS.toMillis(90 * 5)); 69 assertThat(StorageManagerUpsellDialog.shouldShow(context, TimeUnit.DAYS.toMillis(90 * 5))) 70 .isFalse(); 71 } 72 } 73