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 static com.google.common.truth.Truth.assertThat;
19 
20 import static org.mockito.Mockito.when;
21 
22 import android.content.Context;
23 import android.os.SystemProperties;
24 
25 import androidx.preference.Preference;
26 import androidx.preference.PreferenceScreen;
27 
28 import org.junit.Before;
29 import org.junit.Test;
30 import org.junit.runner.RunWith;
31 import org.mockito.Answers;
32 import org.mockito.Mock;
33 import org.mockito.MockitoAnnotations;
34 import org.robolectric.RobolectricTestRunner;
35 
36 @RunWith(RobolectricTestRunner.class)
37 public class FccEquipmentIdPreferenceControllerTest {
38 
39     @Mock(answer = Answers.RETURNS_DEEP_STUBS)
40     private Context mContext;
41     @Mock
42     private Preference mPreference;
43     @Mock
44     private PreferenceScreen mPreferenceScreen;
45     private FccEquipmentIdPreferenceController mController;
46 
47     @Before
setUp()48     public void setUp() {
49         MockitoAnnotations.initMocks(this);
50         mController = new FccEquipmentIdPreferenceController(mContext);
51         when(mPreferenceScreen.findPreference(mController.getPreferenceKey()))
52             .thenReturn(mPreference);
53     }
54 
55     @Test
isAvailable_configEmpty_shouldReturnFalse()56     public void isAvailable_configEmpty_shouldReturnFalse() {
57         assertThat(mController.isAvailable()).isFalse();
58     }
59 
60     @Test
isAvailable_configNonEmpty_shouldReturnTrue()61     public void isAvailable_configNonEmpty_shouldReturnTrue() {
62         SystemProperties.set("ro.ril.fccid", "fcc_equipment");
63 
64         assertThat(mController.isAvailable()).isTrue();
65     }
66 }
67