• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
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 
17 package com.android.settings.display;
18 
19 import android.content.Context;
20 import android.provider.Settings;
21 import com.android.settings.SettingsRobolectricTestRunner;
22 import com.android.settings.TestConfig;
23 import com.android.settings.TimeoutListPreference;
24 import org.junit.Before;
25 import org.junit.Test;
26 import org.junit.runner.RunWith;
27 import org.mockito.Answers;
28 import org.mockito.Mock;
29 import org.mockito.MockitoAnnotations;
30 import org.robolectric.annotation.Config;
31 
32 import static android.provider.Settings.System.SCREEN_OFF_TIMEOUT;
33 import static com.google.common.truth.Truth.assertThat;
34 
35 @RunWith(SettingsRobolectricTestRunner.class)
36 @Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
37 public class TimeoutPreferenceControllerTest {
38     private static final int TIMEOUT = 30;
39     @Mock(answer = Answers.RETURNS_DEEP_STUBS)
40     private Context mContext;
41     @Mock
42     private TimeoutListPreference mPreference;
43     private TimeoutPreferenceController mController;
44 
45     private static final String KEY_SCREEN_TIMEOUT = "screen_timeout";
46 
47     @Before
setUp()48     public void setUp() {
49         MockitoAnnotations.initMocks(this);
50 
51         mController = new TimeoutPreferenceController(mContext, KEY_SCREEN_TIMEOUT);
52     }
53 
54     @Test
testOnPreferenceChange_SetTimeout_ReturnCorrectTimeout()55     public void testOnPreferenceChange_SetTimeout_ReturnCorrectTimeout() {
56         mController.onPreferenceChange(mPreference, Integer.toString(TIMEOUT));
57 
58         final int mode = Settings.System.getInt(mContext.getContentResolver(),
59                 SCREEN_OFF_TIMEOUT, 0);
60         assertThat(mode).isEqualTo(TIMEOUT);
61     }
62 }
63