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