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.opp; 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 BluetoothOppServiceTest { 42 private BluetoothOppService 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 BluetoothOppService is not enabled", 54 mTargetContext.getResources().getBoolean(R.bool.profile_supported_opp)); 55 MockitoAnnotations.initMocks(this); 56 TestUtils.setAdapterService(mAdapterService); 57 TestUtils.startService(mServiceRule, BluetoothOppService.class); 58 mService = BluetoothOppService.getBluetoothOppService(); 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_opp)) { 68 return; 69 } 70 TestUtils.stopService(mServiceRule, BluetoothOppService.class); 71 TestUtils.clearAdapterService(mAdapterService); 72 } 73 74 @Test 75 public void testInitialize() { 76 Assert.assertNotNull(BluetoothOppService.getBluetoothOppService()); 77 } 78 } 79