[Audio routing] Setup basic structure for audio routing page
* Setup UI and bridge device address into audio routing fragment Bug: 237625815 Test: make RunSettingsRoboTests ROBOTEST_FILTER=BluetoothDetailsAudioRoutingFragmentTest Test: make RunSettingsRoboTests ROBOTEST_FILTER=BluetoothDetailsAudioRoutingControllerTest Change-Id: Ia7ffe34af54011a2e3cb445fc4fbd00f991835f3
This commit is contained in:
@@ -0,0 +1,111 @@
|
||||
/*
|
||||
* Copyright (C) 2023 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.settings.bluetooth;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.bluetooth.BluetoothDevice;
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
|
||||
import androidx.test.core.app.ApplicationProvider;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.testutils.XmlTestUtils;
|
||||
import com.android.settings.testutils.shadow.ShadowBluetoothUtils;
|
||||
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
|
||||
import com.android.settingslib.bluetooth.CachedBluetoothDeviceManager;
|
||||
import com.android.settingslib.bluetooth.LocalBluetoothAdapter;
|
||||
import com.android.settingslib.bluetooth.LocalBluetoothManager;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.MockitoJUnit;
|
||||
import org.mockito.junit.MockitoRule;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/** Tests for {@link BluetoothDetailsAudioRoutingFragment}. */
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
@Config(shadows = {ShadowBluetoothUtils.class})
|
||||
public class BluetoothDetailsAudioRoutingFragmentTest {
|
||||
|
||||
@Rule
|
||||
public MockitoRule mMockitoRule = MockitoJUnit.rule();
|
||||
|
||||
private static final String TEST_ADDRESS = "55:66:77:88:99:AA";
|
||||
|
||||
private final Context mContext = ApplicationProvider.getApplicationContext();
|
||||
|
||||
private BluetoothDetailsAudioRoutingFragment mFragment;
|
||||
@Mock
|
||||
private LocalBluetoothManager mLocalBluetoothManager;
|
||||
@Mock
|
||||
private CachedBluetoothDeviceManager mCachedDeviceManager;
|
||||
@Mock
|
||||
private LocalBluetoothAdapter mLocalBluetoothAdapter;
|
||||
@Mock
|
||||
private BluetoothDevice mBluetoothDevice;
|
||||
@Mock
|
||||
private CachedBluetoothDevice mCachedDevice;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
setupEnvironment();
|
||||
|
||||
when(mLocalBluetoothAdapter.getRemoteDevice(TEST_ADDRESS)).thenReturn(mBluetoothDevice);
|
||||
when(mCachedDevice.getAddress()).thenReturn(TEST_ADDRESS);
|
||||
when(mCachedDeviceManager.findDevice(mBluetoothDevice)).thenReturn(mCachedDevice);
|
||||
|
||||
mFragment = new BluetoothDetailsAudioRoutingFragment();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onAttach_setArgumentsWithAddress_expectedCachedDeviceWithAddress() {
|
||||
final Bundle args = new Bundle();
|
||||
args.putString(BluetoothDeviceDetailsFragment.KEY_DEVICE_ADDRESS, TEST_ADDRESS);
|
||||
mFragment.setArguments(args);
|
||||
|
||||
mFragment.onAttach(mContext);
|
||||
|
||||
assertThat(mFragment.mCachedDevice.getAddress()).isEqualTo(TEST_ADDRESS);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getNonIndexableKeys_existInXmlLayout() {
|
||||
final List<String> niks = BluetoothDetailsAudioRoutingFragment.SEARCH_INDEX_DATA_PROVIDER
|
||||
.getNonIndexableKeys(mContext);
|
||||
final List<String> keys =
|
||||
XmlTestUtils.getKeysFromPreferenceXml(mContext,
|
||||
R.xml.bluetooth_audio_routing_fragment);
|
||||
|
||||
assertThat(keys).containsAtLeastElementsIn(niks);
|
||||
}
|
||||
|
||||
private void setupEnvironment() {
|
||||
ShadowBluetoothUtils.sLocalBluetoothManager = mLocalBluetoothManager;
|
||||
when(mLocalBluetoothManager.getCachedDeviceManager()).thenReturn(mCachedDeviceManager);
|
||||
when(mLocalBluetoothManager.getBluetoothAdapter()).thenReturn(mLocalBluetoothAdapter);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user