1 package com.android.settings.deletionhelper; 2 3 import static org.mockito.ArgumentMatchers.eq; 4 import static org.mockito.Mockito.verify; 5 import static org.mockito.Mockito.when; 6 7 import android.content.Context; 8 import android.provider.Settings; 9 import android.support.v7.preference.Preference; 10 import android.support.v7.preference.PreferenceScreen; 11 12 import com.android.settings.R; 13 import com.android.settings.testutils.SettingsRobolectricTestRunner; 14 15 import org.junit.Before; 16 import org.junit.Ignore; 17 import org.junit.Test; 18 import org.junit.runner.RunWith; 19 import org.mockito.Mock; 20 import org.mockito.MockitoAnnotations; 21 import org.robolectric.RuntimeEnvironment; 22 import org.robolectric.annotation.Config; 23 24 @RunWith(SettingsRobolectricTestRunner.class) 25 public class AutomaticStorageManagerDescriptionPreferenceControllerTest { 26 27 @Mock 28 private PreferenceScreen mScreen; 29 @Mock 30 private Preference mPreference; 31 private AutomaticStorageManagerDescriptionPreferenceController mController; 32 private Context mContext = RuntimeEnvironment.application; 33 34 @Before 35 public void setUp() { 36 MockitoAnnotations.initMocks(this); 37 mController = new AutomaticStorageManagerDescriptionPreferenceController(mContext); 38 when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference); 39 when(mPreference.getKey()).thenReturn(mController.getPreferenceKey()); 40 when(mPreference.getContext()).thenReturn(mContext); 41 } 42 43 @Test 44 public void displayPreference_asmDisabled_shouldHaveDescription() { 45 mController.displayPreference(mScreen); 46 47 verify(mPreference).setSummary(eq(R.string.automatic_storage_manager_text)); 48 } 49 50 @Test 51 public void displayPreference_asmEnabledButUnused_shouldHaveDescription() { 52 Settings.Secure.putInt( 53 mContext.getContentResolver(), 54 Settings.Secure.AUTOMATIC_STORAGE_MANAGER_ENABLED, 55 1); 56 57 mController.displayPreference(mScreen); 58 59 verify(mPreference).setSummary(eq(R.string.automatic_storage_manager_text)); 60 } 61 62 @Ignore("Robolectric doesn't do locale switching for date localization -- yet.") 63 @Test 64 @Config(qualifiers = "en") 65 public void displayPreference_asmEnabledAndUsed_shouldHaveDescriptionFilledOut() { 66 Settings.Secure.putInt( 67 mContext.getContentResolver(), 68 Settings.Secure.AUTOMATIC_STORAGE_MANAGER_ENABLED, 69 1); 70 Settings.Secure.putLong( 71 mContext.getContentResolver(), 72 Settings.Secure.AUTOMATIC_STORAGE_MANAGER_BYTES_CLEARED, 73 10); 74 Settings.Secure.putLong( 75 mContext.getContentResolver(), 76 Settings.Secure.AUTOMATIC_STORAGE_MANAGER_LAST_RUN, 77 43200000); // January 1, 1970 12:00:00 PM to avoid timezone issues. 78 79 mController.displayPreference(mScreen); 80 81 verify(mPreference) 82 .setSummary(eq("10.00B total made available\n\nLast ran on January 1, 1970")); 83 } 84 } 85