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.connecteddevice;
17 
18 import static com.google.common.truth.Truth.assertThat;
19 
20 import org.junit.Before;
21 import org.junit.Test;
22 import org.junit.runner.RunWith;
23 import org.robolectric.RobolectricTestRunner;
24 import org.robolectric.RuntimeEnvironment;
25 
26 @RunWith(RobolectricTestRunner.class)
27 public class BluetoothDashboardFragmentTest {
28     private static final String SETTINGS_PACKAGE_NAME = "com.android.settings";
29     private static final String SYSTEMUI_PACKAGE_NAME = "com.android.systemui";
30     private static final String SLICE_ACTION = "com.android.settings.SEARCH_RESULT_TRAMPOLINE";
31     private static final String TEST_APP_NAME = "com.testapp.settings";
32     private static final String TEST_ACTION = "com.testapp.settings.ACTION_START";
33 
34     private BluetoothDashboardFragment mFragment;
35 
36     @Before
setUp()37     public void setUp() {
38         mFragment = new BluetoothDashboardFragment();
39     }
40 
41 
42     @Test
isAlwaysDiscoverable_callingAppIsNotFromSystemApp_returnsFalse()43     public void isAlwaysDiscoverable_callingAppIsNotFromSystemApp_returnsFalse() {
44         assertThat(mFragment.isAlwaysDiscoverable(TEST_APP_NAME, TEST_ACTION)).isFalse();
45     }
46 
47     @Test
isAlwaysDiscoverable_callingAppIsFromSettings_returnsTrue()48     public void isAlwaysDiscoverable_callingAppIsFromSettings_returnsTrue() {
49         assertThat(mFragment.isAlwaysDiscoverable(SETTINGS_PACKAGE_NAME, TEST_ACTION)).isTrue();
50     }
51 
52     @Test
isAlwaysDiscoverable_callingAppIsFromSystemUI_returnsTrue()53     public void isAlwaysDiscoverable_callingAppIsFromSystemUI_returnsTrue() {
54         assertThat(mFragment.isAlwaysDiscoverable(SYSTEMUI_PACKAGE_NAME, TEST_ACTION)).isTrue();
55     }
56 
57     @Test
isAlwaysDiscoverable_actionIsFromSlice_returnsFalse()58     public void isAlwaysDiscoverable_actionIsFromSlice_returnsFalse() {
59         assertThat(mFragment.isAlwaysDiscoverable(SYSTEMUI_PACKAGE_NAME, SLICE_ACTION)).isFalse();
60     }
61 }
62