• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2024 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.bluetooth;
18 
19 import static com.android.settings.bluetooth.BluetoothAutoOnPreferenceController.PREF_KEY;
20 import static com.android.settings.core.BasePreferenceController.AVAILABLE;
21 import static com.android.settings.core.BasePreferenceController.UNSUPPORTED_ON_DEVICE;
22 
23 import static com.google.common.truth.Truth.assertThat;
24 
25 import static org.mockito.Mockito.doReturn;
26 import static org.mockito.Mockito.spy;
27 
28 import android.bluetooth.BluetoothAdapter;
29 import android.content.ContentResolver;
30 import android.content.Context;
31 
32 import androidx.test.core.app.ApplicationProvider;
33 
34 import org.junit.Before;
35 import org.junit.Test;
36 import org.junit.runner.RunWith;
37 import org.robolectric.RobolectricTestRunner;
38 
39 @RunWith(RobolectricTestRunner.class)
40 public class BluetoothAutoOnPreferenceControllerTest {
41     private Context mContext;
42     private ContentResolver mContentResolver;
43     private BluetoothAutoOnPreferenceController mController;
44     private BluetoothAdapter mBluetoothAdapter;
45 
46     @Before
setUp()47     public void setUp() {
48         mContext = spy(ApplicationProvider.getApplicationContext());
49         mContentResolver = mContext.getContentResolver();
50         mController = new BluetoothAutoOnPreferenceController(mContext, PREF_KEY);
51         mBluetoothAdapter = spy(BluetoothAdapter.getDefaultAdapter());
52         mController.mBluetoothAdapter = mBluetoothAdapter;
53     }
54 
55     @Test
getAvailability_valueUnset_returnUnsupported()56     public void getAvailability_valueUnset_returnUnsupported() {
57         doReturn(false).when(mBluetoothAdapter).isAutoOnSupported();
58 
59         assertThat(mController.getAvailabilityStatus()).isEqualTo(UNSUPPORTED_ON_DEVICE);
60     }
61 
62     @Test
getAvailability_valueSet_returnAvailable()63     public void getAvailability_valueSet_returnAvailable() {
64         doReturn(true).when(mBluetoothAdapter).isAutoOnSupported();
65 
66         assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE);
67     }
68 
69     @Test
isChecked_valueEnabled_returnTrue()70     public void isChecked_valueEnabled_returnTrue() {
71         doReturn(true).when(mBluetoothAdapter).isAutoOnSupported();
72         doReturn(true).when(mBluetoothAdapter).isAutoOnEnabled();
73 
74         assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE);
75         assertThat(mController.isChecked()).isEqualTo(true);
76     }
77 }
78