blob: 97c9f1817a640017e05ba530ac5c35fe127eff4c [file] [log] [blame]
/*
* Copyright (C) 2018 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.settingslib.bluetooth;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.when;
import static org.mockito.Mockito.verify;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothMapClient;
import android.bluetooth.BluetoothProfile;
import android.content.Context;
import com.android.settingslib.SettingsLibRobolectricTestRunner;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RuntimeEnvironment;
@RunWith(SettingsLibRobolectricTestRunner.class)
public class MapClientProfileTest {
@Mock
private LocalBluetoothAdapter mAdapter;
@Mock
private CachedBluetoothDeviceManager mDeviceManager;
@Mock
private LocalBluetoothProfileManager mProfileManager;
@Mock
private BluetoothMapClient mService;
@Mock
private CachedBluetoothDevice mCachedBluetoothDevice;
@Mock
private BluetoothDevice mBluetoothDevice;
private BluetoothProfile.ServiceListener mServiceListener;
private MapClientProfile mProfile;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
doAnswer((invocation) -> {
mServiceListener = (BluetoothProfile.ServiceListener) invocation.getArguments()[1];
return null;
}).when(mAdapter).getProfileProxy(any(Context.class),
any(BluetoothProfile.ServiceListener.class), eq(BluetoothProfile.MAP_CLIENT));
mProfile = new MapClientProfile(RuntimeEnvironment.application, mAdapter,
mDeviceManager, mProfileManager);
mServiceListener.onServiceConnected(BluetoothProfile.MAP_CLIENT, mService);
}
@Test
public void connect_shouldConnectBluetoothMapClient() {
mProfile.connect(mBluetoothDevice);
verify(mService).connect(mBluetoothDevice);
}
@Test
public void disconnect_shouldDisconnectBluetoothMapClient() {
mProfile.disconnect(mBluetoothDevice);
verify(mService).disconnect(mBluetoothDevice);
}
@Test
public void getConnectionStatus_shouldReturnConnectionState() {
when(mService.getConnectionState(mBluetoothDevice)).
thenReturn(BluetoothProfile.STATE_CONNECTED);
assertThat(mProfile.getConnectionStatus(mBluetoothDevice)).
isEqualTo(BluetoothProfile.STATE_CONNECTED);
}
}