• 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.development;
18 
19 import static com.android.settings.development.BluetoothSnoopLogPreferenceController.BLUETOOTH_BTSNOOP_ENABLE_PROPERTY;
20 import static com.google.common.truth.Truth.assertThat;
21 import static org.mockito.Mockito.verify;
22 import static org.mockito.Mockito.when;
23 
24 import android.content.Context;
25 import android.os.SystemProperties;
26 import android.support.v14.preference.SwitchPreference;
27 import android.support.v7.preference.PreferenceScreen;
28 
29 import com.android.settings.testutils.SettingsRobolectricTestRunner;
30 
31 import org.junit.Before;
32 import org.junit.Test;
33 import org.junit.runner.RunWith;
34 import org.mockito.Mock;
35 import org.mockito.MockitoAnnotations;
36 
37 @RunWith(SettingsRobolectricTestRunner.class)
38 public class BluetoothSnoopLogPreferenceControllerTest {
39 
40     @Mock
41     private Context mContext;
42     @Mock
43     private SwitchPreference mPreference;
44     @Mock
45     private PreferenceScreen mPreferenceScreen;
46     private BluetoothSnoopLogPreferenceController mController;
47 
48     @Before
setup()49     public void setup() {
50         MockitoAnnotations.initMocks(this);
51         mController = new BluetoothSnoopLogPreferenceController(mContext);
52         when(mPreferenceScreen.findPreference(mController.getPreferenceKey()))
53             .thenReturn(mPreference);
54         mController.displayPreference(mPreferenceScreen);
55     }
56 
57     @Test
onPreferenceChanged_turnOnBluetoothSnoopLog()58     public void onPreferenceChanged_turnOnBluetoothSnoopLog() {
59         mController.onPreferenceChange(null, true);
60 
61         final boolean mode = SystemProperties.getBoolean(BLUETOOTH_BTSNOOP_ENABLE_PROPERTY, false);
62 
63         assertThat(mode).isTrue();
64     }
65 
66     @Test
onPreferenceChanged_turnOffBluetoothSnoopLog()67     public void onPreferenceChanged_turnOffBluetoothSnoopLog() {
68         mController.onPreferenceChange(null, false);
69 
70         final boolean mode = SystemProperties.getBoolean(BLUETOOTH_BTSNOOP_ENABLE_PROPERTY, false);
71 
72         assertThat(mode).isFalse();
73     }
74 
75     @Test
updateState_preferenceShouldBeChecked()76     public void updateState_preferenceShouldBeChecked() {
77         SystemProperties.set(BLUETOOTH_BTSNOOP_ENABLE_PROPERTY, Boolean.toString(true));
78         mController.updateState(mPreference);
79 
80         verify(mPreference).setChecked(true);
81     }
82 
83     @Test
updateState_preferenceShouldNotBeChecked()84     public void updateState_preferenceShouldNotBeChecked() {
85         SystemProperties.set(BLUETOOTH_BTSNOOP_ENABLE_PROPERTY, Boolean.toString(false));
86         mController.updateState(mPreference);
87 
88         verify(mPreference).setChecked(false);
89     }
90 
91     @Test
onDeveloperOptionsDisabled_shouldDisablePreference()92     public void onDeveloperOptionsDisabled_shouldDisablePreference() {
93         mController.onDeveloperOptionsDisabled();
94 
95         verify(mPreference).setEnabled(false);
96         verify(mPreference).setChecked(false);
97     }
98 }
99