Merge "[Audiosharing] Fix tests when flag is on." into main
diff --git a/tests/robotests/src/com/android/settings/connecteddevice/ConnectedDeviceDashboardFragmentTest.java b/tests/robotests/src/com/android/settings/connecteddevice/ConnectedDeviceDashboardFragmentTest.java
index a3348ca..09f7a38 100644
--- a/tests/robotests/src/com/android/settings/connecteddevice/ConnectedDeviceDashboardFragmentTest.java
+++ b/tests/robotests/src/com/android/settings/connecteddevice/ConnectedDeviceDashboardFragmentTest.java
@@ -25,8 +25,6 @@
 
 import android.content.Context;
 import android.content.pm.PackageManager;
-import android.platform.test.annotations.RequiresFlagsDisabled;
-import android.platform.test.annotations.RequiresFlagsEnabled;
 import android.platform.test.flag.junit.CheckFlagsRule;
 import android.platform.test.flag.junit.DeviceFlagsValueProvider;
 import android.provider.SearchIndexableResource;
@@ -34,7 +32,6 @@
 import com.android.settings.R;
 import com.android.settings.core.BasePreferenceController;
 import com.android.settings.core.PreferenceControllerListHelper;
-import com.android.settings.flags.Flags;
 import com.android.settings.slices.SlicePreferenceController;
 import com.android.settings.testutils.shadow.ShadowBluetoothAdapter;
 import com.android.settings.testutils.shadow.ShadowConnectivityManager;
@@ -53,8 +50,12 @@
 import java.util.List;
 
 @RunWith(RobolectricTestRunner.class)
-@Config(shadows = {ShadowUserManager.class,
-        ShadowConnectivityManager.class, ShadowBluetoothAdapter.class})
+@Config(
+        shadows = {
+            ShadowUserManager.class,
+            ShadowConnectivityManager.class,
+            ShadowBluetoothAdapter.class
+        })
 public class ConnectedDeviceDashboardFragmentTest {
     @Rule
     public final CheckFlagsRule mCheckFlagsRule = DeviceFlagsValueProvider.createCheckFlagsRule();
@@ -98,7 +99,6 @@
     }
 
     @Test
-    @RequiresFlagsEnabled(Flags.FLAG_ENABLE_LE_AUDIO_SHARING)
     public void nonIndexableKeys_existInXmlLayout() {
         final List<String> niks =
                 ConnectedDeviceDashboardFragment.SEARCH_INDEX_DATA_PROVIDER.getNonIndexableKeys(
@@ -112,24 +112,6 @@
                         KEY_DISCOVERABLE_FOOTER,
                         KEY_SAVED_DEVICE_SEE_ALL,
                         KEY_FAST_PAIR_DEVICE_SEE_ALL,
-                        KEY_AUDIO_SHARING_SETTINGS);
-    }
-
-    @Test
-    @RequiresFlagsDisabled(Flags.FLAG_ENABLE_LE_AUDIO_SHARING)
-    public void nonIndexableKeys_existInXmlLayout_flagOff() {
-        final List<String> niks =
-                ConnectedDeviceDashboardFragment.SEARCH_INDEX_DATA_PROVIDER.getNonIndexableKeys(
-                        mContext);
-
-        assertThat(niks)
-                .containsExactly(
-                        KEY_CONNECTED_DEVICES,
-                        KEY_AVAILABLE_DEVICES,
-                        KEY_NEARBY_DEVICES,
-                        KEY_DISCOVERABLE_FOOTER,
-                        KEY_SAVED_DEVICE_SEE_ALL,
-                        KEY_FAST_PAIR_DEVICE_SEE_ALL,
                         KEY_AUDIO_SHARING_DEVICE_LIST,
                         KEY_AUDIO_SHARING_SETTINGS);
     }
@@ -160,10 +142,12 @@
                 PreferenceControllerListHelper.getPreferenceControllersFromXml(
                         mContext, R.xml.connected_devices);
 
-        assertThat(controllers
-                .stream()
-                .filter(controller -> controller instanceof SlicePreferenceController)
-                .count())
+        assertThat(
+                        controllers.stream()
+                                .filter(
+                                        controller ->
+                                                controller instanceof SlicePreferenceController)
+                                .count())
                 .isEqualTo(1);
     }
 }
diff --git a/tests/robotests/src/com/android/settings/connecteddevice/audiosharing/AudioSharingDialogFragmentTest.java b/tests/robotests/src/com/android/settings/connecteddevice/audiosharing/AudioSharingDialogFragmentTest.java
index fa6cc6c..757964b 100644
--- a/tests/robotests/src/com/android/settings/connecteddevice/audiosharing/AudioSharingDialogFragmentTest.java
+++ b/tests/robotests/src/com/android/settings/connecteddevice/audiosharing/AudioSharingDialogFragmentTest.java
@@ -158,7 +158,9 @@
     @Test
     @RequiresFlagsEnabled(Flags.FLAG_ENABLE_LE_AUDIO_SHARING)
     public void onCreateDialog_singleConnectedDevice_dialogDismiss() {
-        mFragment.show(mParent, new ArrayList<>(), (item) -> {});
+        ArrayList<AudioSharingDeviceItem> list = new ArrayList<>();
+        list.add(TEST_DEVICE_ITEM1);
+        mFragment.show(mParent, list, (item) -> {});
         shadowMainLooper().idle();
         AlertDialog dialog = ShadowAlertDialogCompat.getLatestAlertDialog();
         ShadowAlertDialogCompat shadowDialog = ShadowAlertDialogCompat.shadowOf(dialog);
@@ -170,10 +172,12 @@
     @Test
     @RequiresFlagsEnabled(Flags.FLAG_ENABLE_LE_AUDIO_SHARING)
     public void onCreateDialog_singleConnectedDevice_shareClicked() {
+        ArrayList<AudioSharingDeviceItem> list = new ArrayList<>();
+        list.add(TEST_DEVICE_ITEM1);
         AtomicBoolean isShareBtnClicked = new AtomicBoolean(false);
         mFragment.show(
                 mParent,
-                new ArrayList<>(),
+                list,
                 (item) -> {
                     isShareBtnClicked.set(true);
                 });
diff --git a/tests/robotests/src/com/android/settings/connecteddevice/audiosharing/AudioSharingSwitchBarControllerTest.java b/tests/robotests/src/com/android/settings/connecteddevice/audiosharing/AudioSharingSwitchBarControllerTest.java
index 0b94061..11e8ec9 100644
--- a/tests/robotests/src/com/android/settings/connecteddevice/audiosharing/AudioSharingSwitchBarControllerTest.java
+++ b/tests/robotests/src/com/android/settings/connecteddevice/audiosharing/AudioSharingSwitchBarControllerTest.java
@@ -18,7 +18,6 @@
 
 import static com.google.common.truth.Truth.assertThat;
 
-import static org.mockito.Mockito.verify;
 import static org.robolectric.Shadows.shadowOf;
 
 import android.bluetooth.BluetoothAdapter;
@@ -71,6 +70,7 @@
     @Test
     @RequiresFlagsEnabled(Flags.FLAG_ENABLE_LE_AUDIO_SHARING)
     public void bluetoothOff_switchDisabled() {
+        assertThat(mSwitchBar.isEnabled()).isTrue();
         mContext.registerReceiver(
                 mController.mReceiver,
                 mController.mIntentFilter,
@@ -79,7 +79,7 @@
         intent.putExtra(BluetoothAdapter.EXTRA_STATE, BluetoothAdapter.STATE_OFF);
         mContext.sendBroadcast(intent);
         shadowOf(Looper.getMainLooper()).idle();
-        verify(mSwitch).setEnabled(false);
+        assertThat(mSwitchBar.isEnabled()).isFalse();
         assertThat(mOnSwitchBarChanged).isTrue();
     }
 }