1 /**
2  * Copyright (C) 2022 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.settings.bluetooth;
17 
18 import static org.mockito.Mockito.doNothing;
19 import static org.mockito.Mockito.spy;
20 import static org.mockito.Mockito.verify;
21 
22 import android.content.Intent;
23 
24 import androidx.test.ext.junit.runners.AndroidJUnit4;
25 import androidx.test.platform.app.InstrumentationRegistry;
26 
27 import com.android.settingslib.bluetooth.BluetoothBroadcastUtils;
28 
29 import org.junit.Before;
30 import org.junit.Ignore;
31 import org.junit.Test;
32 import org.junit.runner.RunWith;
33 import org.mockito.Mock;
34 
35 @RunWith(AndroidJUnit4.class)
36 @Ignore("b/337418017")
37 public class QrCodeScanModeActivityTest {
38 
39     @Mock
40     private Intent mIntent;
41     private QrCodeScanModeActivity mActivity;
42 
43     @Before
setUp()44     public void setUp() {
45         mIntent = new Intent(BluetoothBroadcastUtils.ACTION_BLUETOOTH_LE_AUDIO_QR_CODE_SCANNER);
46         InstrumentationRegistry.getInstrumentation().runOnMainSync(() -> {
47             try {
48                 mActivity =
49                         spy((QrCodeScanModeActivity) InstrumentationRegistry
50                                 .getInstrumentation().newActivity(
51                                         getClass().getClassLoader(),
52                                         QrCodeScanModeActivity.class.getName(), mIntent));
53             } catch (Exception e) {
54                 throw new RuntimeException(e); // nothing to do
55             }
56         });
57     }
58 
59     @Test
handleIntent_noIntentAction_shouldFinish()60     public void handleIntent_noIntentAction_shouldFinish() {
61         mIntent = new Intent();
62         mActivity.handleIntent(mIntent);
63         verify(mActivity).finish();
64     }
65 
66     @Test
handleIntent_hasIntentExtra_shouldShowFragment()67     public void handleIntent_hasIntentExtra_shouldShowFragment() {
68         doNothing().when(mActivity).showQrCodeScannerFragment(mIntent);
69         mActivity.handleIntent(mIntent);
70         verify(mActivity).showQrCodeScannerFragment(mIntent);
71     }
72 
73 }
74