• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2018 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.bluetooth.pan;
17 
18 import android.bluetooth.BluetoothAdapter;
19 import android.content.Context;
20 
21 import androidx.test.InstrumentationRegistry;
22 import androidx.test.filters.MediumTest;
23 import androidx.test.rule.ServiceTestRule;
24 import androidx.test.runner.AndroidJUnit4;
25 
26 import com.android.bluetooth.R;
27 import com.android.bluetooth.TestUtils;
28 import com.android.bluetooth.btservice.AdapterService;
29 
30 import org.junit.After;
31 import org.junit.Assert;
32 import org.junit.Assume;
33 import org.junit.Before;
34 import org.junit.Rule;
35 import org.junit.Test;
36 import org.junit.runner.RunWith;
37 import org.mockito.Mock;
38 import org.mockito.MockitoAnnotations;
39 
40 @MediumTest
41 @RunWith(AndroidJUnit4.class)
42 public class PanServiceTest {
43     private PanService mService = null;
44     private BluetoothAdapter mAdapter = null;
45     private Context mTargetContext;
46 
47     @Rule public final ServiceTestRule mServiceRule = new ServiceTestRule();
48 
49     @Mock private AdapterService mAdapterService;
50 
51     @Before
setUp()52     public void setUp() throws Exception {
53         mTargetContext = InstrumentationRegistry.getTargetContext();
54         Assume.assumeTrue("Ignore test when PanService is not enabled",
55                 mTargetContext.getResources().getBoolean(R.bool.profile_supported_pan));
56         MockitoAnnotations.initMocks(this);
57         TestUtils.setAdapterService(mAdapterService);
58         TestUtils.startService(mServiceRule, PanService.class);
59         mService = PanService.getPanService();
60         Assert.assertNotNull(mService);
61         // Try getting the Bluetooth adapter
62         mAdapter = BluetoothAdapter.getDefaultAdapter();
63         Assert.assertNotNull(mAdapter);
64     }
65 
66     @After
tearDown()67     public void tearDown() throws Exception {
68         if (!mTargetContext.getResources().getBoolean(R.bool.profile_supported_pan)) {
69             return;
70         }
71         TestUtils.stopService(mServiceRule, PanService.class);
72         mService = PanService.getPanService();
73         Assert.assertNull(mService);
74         TestUtils.clearAdapterService(mAdapterService);
75     }
76 
77     @Test
testInitialize()78     public void testInitialize() {
79         Assert.assertNotNull(PanService.getPanService());
80     }
81 }
82