From 083c13d3f0755d09697b15544de6c1e4b39e0517 Mon Sep 17 00:00:00 2001 From: Zoey Chen Date: Mon, 16 May 2022 23:41:59 +0800 Subject: [PATCH] [Le Audio] Add test case for the QrCodeScanModeActivity Bug: 232365943 Test: atest QrCodeScanModeActivityTest Change-Id: I38db5957ff21608134aed2e26cd9c32f14b78eb9 --- .../bluetooth/QrCodeScanModeActivity.java | 10 ++- .../bluetooth/QrCodeScanModeActivityTest.java | 72 +++++++++++++++++++ 2 files changed, 81 insertions(+), 1 deletion(-) create mode 100644 tests/unit/src/com/android/settings/bluetooth/QrCodeScanModeActivityTest.java diff --git a/src/com/android/settings/bluetooth/QrCodeScanModeActivity.java b/src/com/android/settings/bluetooth/QrCodeScanModeActivity.java index 5c5b61f091c..690c07ec560 100644 --- a/src/com/android/settings/bluetooth/QrCodeScanModeActivity.java +++ b/src/com/android/settings/bluetooth/QrCodeScanModeActivity.java @@ -30,7 +30,15 @@ import com.android.settingslib.R; import com.android.settingslib.bluetooth.BluetoothBroadcastUtils; import com.android.settingslib.bluetooth.BluetoothUtils; -//TODO (b/232365943): Add test case for tthe QrCode UI. +/** + * Finding a broadcast through QR code. + * + * To use intent action {@link BluetoothBroadcastUtils#ACTION_BLUETOOTH_LE_AUDIO_QR_CODE_SCANNER}, + * specify the bluetooth device sink of the broadcast to be provisioned in + * {@link BluetoothBroadcastUtils#EXTRA_BLUETOOTH_DEVICE_SINK} and check the operation for all + * coordinated set members throughout one session or not by + * {@link BluetoothBroadcastUtils#EXTRA_BLUETOOTH_SINK_IS_GROUP}. + */ public class QrCodeScanModeActivity extends QrCodeScanModeBaseActivity { private static final boolean DEBUG = BluetoothUtils.D; private static final String TAG = "QrCodeScanModeActivity"; diff --git a/tests/unit/src/com/android/settings/bluetooth/QrCodeScanModeActivityTest.java b/tests/unit/src/com/android/settings/bluetooth/QrCodeScanModeActivityTest.java new file mode 100644 index 00000000000..56764e3a145 --- /dev/null +++ b/tests/unit/src/com/android/settings/bluetooth/QrCodeScanModeActivityTest.java @@ -0,0 +1,72 @@ +/** + * Copyright (C) 2022 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 org.mockito.Mockito.doNothing; +import static org.mockito.Mockito.spy; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import android.content.Intent; + +import androidx.test.ext.junit.runners.AndroidJUnit4; +import androidx.test.platform.app.InstrumentationRegistry; + +import com.android.settingslib.bluetooth.BluetoothBroadcastUtils; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; + +@RunWith(AndroidJUnit4.class) +public class QrCodeScanModeActivityTest { + + @Mock + private Intent mIntent; + private QrCodeScanModeActivity mActivity; + + @Before + public void setUp() { + mIntent = new Intent(BluetoothBroadcastUtils.ACTION_BLUETOOTH_LE_AUDIO_QR_CODE_SCANNER); + InstrumentationRegistry.getInstrumentation().runOnMainSync(() -> { + try { + mActivity = + spy((QrCodeScanModeActivity) InstrumentationRegistry + .getInstrumentation().newActivity( + getClass().getClassLoader(), + QrCodeScanModeActivity.class.getName(), mIntent)); + } catch (Exception e) { + throw new RuntimeException(e); // nothing to do + } + }); + } + + @Test + public void handleIntent_noIntentAction_shouldFinish() { + mIntent = new Intent(); + mActivity.handleIntent(mIntent); + verify(mActivity).finish(); + } + + @Test + public void handleIntent_hasIntentExtra_shouldShowFragment() { + doNothing().when(mActivity).showQrCodeScannerFragment(mIntent); + mActivity.handleIntent(mIntent); + verify(mActivity).showQrCodeScannerFragment(mIntent); + } + +}