• 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 package com.android.settings.deviceinfo;
17 
18 import android.content.Context;
19 import android.net.ConnectivityManager;
20 import android.os.SystemProperties;
21 import android.support.v7.preference.Preference;
22 
23 import com.android.settings.SettingsRobolectricTestRunner;
24 import com.android.settings.TestConfig;
25 import com.android.settings.testutils.shadow.SettingsShadowSystemProperties;
26 
27 import org.junit.Before;
28 import org.junit.Test;
29 import org.junit.runner.RunWith;
30 import org.mockito.Answers;
31 import org.mockito.Mock;
32 import org.mockito.MockitoAnnotations;
33 import org.robolectric.annotation.Config;
34 import org.robolectric.shadows.ShadowSystemProperties;
35 
36 import static com.google.common.truth.Truth.assertThat;
37 import static org.mockito.Mockito.verify;
38 import static org.mockito.Mockito.when;
39 
40 @RunWith(SettingsRobolectricTestRunner.class)
41 @Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
42 public class BasebandVersionPreferenceControllerTest {
43 
44 
45     @Mock(answer = Answers.RETURNS_DEEP_STUBS)
46     private Context mContext;
47     @Mock
48     private ConnectivityManager mCm;
49     @Mock
50     private Preference mPreference;
51 
52     private BasebandVersionPreferenceController mController;
53 
54     @Before
setUp()55     public void setUp() {
56         MockitoAnnotations.initMocks(this);
57         mController = new BasebandVersionPreferenceController(mContext);
58         when(mContext.getSystemService(Context.CONNECTIVITY_SERVICE)).thenReturn(mCm);
59     }
60 
61     @Test
isAvailable_wifiOnly_shouldReturnFalse()62     public void isAvailable_wifiOnly_shouldReturnFalse() {
63         when(mCm.isNetworkSupported(ConnectivityManager.TYPE_MOBILE)).thenReturn(false);
64         assertThat(mController.isAvailable()).isFalse();
65     }
66 
67     @Test
isAvailable_hasMobile_shouldReturnTrue()68     public void isAvailable_hasMobile_shouldReturnTrue() {
69         when(mCm.isNetworkSupported(ConnectivityManager.TYPE_MOBILE)).thenReturn(true);
70         assertThat(mController.isAvailable()).isTrue();
71     }
72 
73     @Config(shadows = {SettingsShadowSystemProperties.class})
74     @Test
updateState_shouldLoadFromSysProperty()75     public void updateState_shouldLoadFromSysProperty() {
76         SettingsShadowSystemProperties.set("gsm.version.baseband", "test");
77 
78         mController.updateState(mPreference);
79 
80         verify(mPreference).setSummary("test");
81     }
82 }
83