1 /*
2  * Copyright (C) 2021 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 
17 package android.content.pm;
18 
19 import static com.google.common.truth.Truth.assertThat;
20 
21 import android.app.Person;
22 import android.content.ComponentName;
23 import android.content.Intent;
24 import android.util.ArraySet;
25 
26 import org.junit.Test;
27 
28 import java.util.Set;
29 
30 public class AppSearchShortcutInfoTest {
31 
32     @Test
testBuildShortcutAndGetValue()33     public void testBuildShortcutAndGetValue() {
34         final String category =
35                 "android.app.stubs.SHARE_SHORTCUT_CATEGORY";
36         final String id = "shareShortcut";
37         final String shortcutIconResName = "shortcut";
38         final ComponentName activity = new ComponentName("xxx", "s");
39         final Person person = new Person.Builder()
40                 .setBot(false)
41                 .setName("BubbleBot")
42                 .setImportant(true)
43                 .build();
44 
45         final Set<String> categorySet = new ArraySet<>();
46         categorySet.add(category);
47         final Intent shortcutIntent = new Intent(Intent.ACTION_VIEW);
48         final ShortcutInfo shortcut = new AppSearchShortcutInfo.Builder(/*packageName=*/"", id)
49                 .setActivity(activity)
50                 .setLongLabel(id)
51                 .setIconResName(shortcutIconResName)
52                 .setIntent(shortcutIntent)
53                 .setPerson(person)
54                 .setCategories(categorySet)
55                 .setFlags(ShortcutInfo.FLAG_LONG_LIVED)
56                 .build()
57                 .toShortcutInfo(0);
58 
59         assertThat(shortcut.getUserId()).isEqualTo(0);
60         assertThat(shortcut.getId()).isEqualTo(id);
61         assertThat(shortcut.getShortLabel()).isEqualTo(id);
62         assertThat(shortcut.getIconResName()).isEqualTo(shortcutIconResName);
63         assertThat(shortcut.getIntent().toString()).isEqualTo(shortcut.toString());
64         assertThat(shortcut.getPersons().length).isEqualTo(1);
65         assertThat(shortcut.getPersons()[0]).isEqualTo(person);
66         assertThat(shortcut.getCategories()).isEqualTo(categorySet);
67         assertThat(shortcut.getFlags()).isEqualTo(ShortcutInfo.FLAG_LONG_LIVED);
68         assertThat(shortcut.getActivity()).isEqualTo(activity);
69     }
70 }
71