blob: 94bfd8f22de28388e218a25fee62f69b36c514e1 [file] [log] [blame]
Tony Mantlerc48ba6a2017-07-31 10:58:53 -07001/*
2 * Copyright (C) 2017 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of 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,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.settingslib.development;
18
19import static org.mockito.Mockito.doReturn;
20import static org.mockito.Mockito.verify;
21
22import android.os.SystemProperties;
23import android.support.v7.preference.ListPreference;
24import android.support.v7.preference.PreferenceScreen;
25
26import com.android.settingslib.R;
27import com.android.settingslib.SettingsLibRobolectricTestRunner;
28import com.android.settingslib.TestConfig;
29
30import org.junit.Before;
31import org.junit.Test;
32import org.junit.runner.RunWith;
33import org.mockito.Mock;
34import org.mockito.MockitoAnnotations;
35import org.robolectric.RuntimeEnvironment;
36import org.robolectric.annotation.Config;
37
38@RunWith(SettingsLibRobolectricTestRunner.class)
39@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION,
40 shadows = SystemPropertiesTestImpl.class)
41public class LogdSizePreferenceControllerTest {
42
43 @Mock
44 private ListPreference mListPreference;
45 @Mock
46 private PreferenceScreen mPreferenceScreen;
47
48 private AbstractLogdSizePreferenceController mController;
49
50 @Before
51 public void setUp() {
52 MockitoAnnotations.initMocks(this);
53 mController = new AbstractLogdSizePreferenceController(RuntimeEnvironment.application) {};
54
55 doReturn(mListPreference).when(mPreferenceScreen)
56 .findPreference(mController.getPreferenceKey());
57
58 mController.displayPreference(mPreferenceScreen);
59 }
60
61 @Test
62 public void testUpateLogdSizeValues_lowRamEntries() {
63 SystemProperties.set("ro.config.low_ram", "true");
64 mController.updateLogdSizeValues();
65 verify(mListPreference).setEntries(R.array.select_logd_size_lowram_titles);
66 }
67
68 @Test
69 public void testUpdateLogdSizeValues_silence() {
70 SystemProperties.set(
71 AbstractLogdSizePreferenceController.SELECT_LOGD_TAG_PROPERTY,
72 AbstractLogdSizePreferenceController.SELECT_LOGD_TAG_SILENCE);
73 SystemProperties.set(
74 AbstractLogdSizePreferenceController.SELECT_LOGD_SIZE_PROPERTY,
75 AbstractLogdSizePreferenceController.SELECT_LOGD_DEFAULT_SIZE_VALUE);
76 mController.updateLogdSizeValues();
77 verify(mListPreference).setValue(
78 AbstractLogdSizePreferenceController.SELECT_LOGD_OFF_SIZE_MARKER_VALUE);
79 }
80}