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