1 /*
2  * Copyright 2020 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.connecteddevice;
17 
18 import static com.google.common.truth.Truth.assertThat;
19 
20 import android.bluetooth.BluetoothAdapter;
21 
22 import com.android.settings.testutils.shadow.ShadowBluetoothAdapter;
23 
24 import org.junit.Before;
25 import org.junit.Test;
26 import org.junit.runner.RunWith;
27 import org.mockito.MockitoAnnotations;
28 import org.robolectric.RobolectricTestRunner;
29 import org.robolectric.annotation.Config;
30 import org.robolectric.shadow.api.Shadow;
31 
32 @RunWith(RobolectricTestRunner.class)
33 @Config(shadows = ShadowBluetoothAdapter.class)
34 public class PreviouslyConnectedDeviceDashboardFragmentTest {
35 
36     private ShadowBluetoothAdapter mShadowBluetoothAdapter;
37     private PreviouslyConnectedDeviceDashboardFragment mFragment;
38 
39     @Before
setUp()40     public void setUp() {
41         MockitoAnnotations.initMocks(this);
42 
43         mShadowBluetoothAdapter = Shadow.extract(BluetoothAdapter.getDefaultAdapter());
44         mFragment = new PreviouslyConnectedDeviceDashboardFragment();
45         mFragment.mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
46     }
47 
48     @Test
onStart_bluetoothIsDisable_enableBluetooth()49     public void onStart_bluetoothIsDisable_enableBluetooth() {
50         mShadowBluetoothAdapter.setEnabled(false);
51 
52         assertThat(mFragment.mBluetoothAdapter.isEnabled()).isFalse();
53         mFragment.enableBluetoothIfNecessary();
54 
55         assertThat(mFragment.mBluetoothAdapter.isEnabled()).isTrue();
56     }
57 }
58