• 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.dream;
18 
19 import android.content.Context;
20 import android.support.v7.preference.Preference;
21 import com.android.settings.testutils.SettingsRobolectricTestRunner;
22 import com.android.settings.TestConfig;
23 import com.android.settingslib.dream.DreamBackend;
24 import com.android.settingslib.dream.DreamBackend.WhenToDream;
25 import org.junit.Before;
26 import org.junit.Test;
27 import org.junit.runner.RunWith;
28 import org.mockito.Answers;
29 import org.mockito.Mock;
30 import org.mockito.MockitoAnnotations;
31 import org.robolectric.annotation.Config;
32 import org.robolectric.util.ReflectionHelpers;
33 
34 import static com.google.common.truth.Truth.assertThat;
35 import static org.mockito.Mockito.mock;
36 import static org.mockito.Mockito.verify;
37 import static org.mockito.Mockito.when;
38 
39 @RunWith(SettingsRobolectricTestRunner.class)
40 @Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
41 public class WhenToDreamPreferenceControllerTest {
42     private WhenToDreamPreferenceController mController;
43     @Mock(answer = Answers.RETURNS_DEEP_STUBS)
44     private Context mContext;
45     @Mock
46     private DreamBackend mBackend;
47 
48 
49     @Before
setup()50     public void setup() {
51         MockitoAnnotations.initMocks(this);
52         mController = new WhenToDreamPreferenceController(mContext);
53         ReflectionHelpers.setField(mController, "mBackend", mBackend);
54     }
55 
56     @Test
updateSummary()57     public void updateSummary() {
58         // Don't have to test the other settings because DreamSettings tests that all
59         // @WhenToDream values map to the correct ResId
60         final @WhenToDream int testSetting = DreamBackend.WHILE_CHARGING;
61         final Preference mockPref = mock(Preference.class);
62         when(mockPref.getContext()).thenReturn(mContext);
63         when(mBackend.getWhenToDreamSetting()).thenReturn(testSetting);
64         final String expectedString =
65                 mContext.getString(DreamSettings.getDreamSettingDescriptionResId(testSetting));
66 
67         mController.updateState(mockPref);
68         verify(mockPref).setSummary(expectedString);
69     }
70 }
71