blob: 05a9a80e262ca5b1d071148d1e0f7896a6309bc5 [file] [log] [blame]
Danning Chena1bf86d2020-01-14 16:09:24 -08001/*
2 * Copyright (C) 2020 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
17package com.android.server.people.data;
18
19import static org.junit.Assert.assertEquals;
20import static org.junit.Assert.assertFalse;
21import static org.junit.Assert.assertNull;
22import static org.junit.Assert.assertTrue;
23
24import android.content.LocusId;
25import android.content.pm.ShortcutInfo;
26import android.net.Uri;
27
28import org.junit.Test;
29import org.junit.runner.RunWith;
30import org.junit.runners.JUnit4;
31
32@RunWith(JUnit4.class)
33public final class ConversationInfoTest {
34
35 private static final String SHORTCUT_ID = "abc";
36 private static final LocusId LOCUS_ID = new LocusId("def");
37 private static final Uri CONTACT_URI = Uri.parse("tel:+1234567890");
38 private static final String PHONE_NUMBER = "+1234567890";
39 private static final String NOTIFICATION_CHANNEL_ID = "test : abc";
40
41 @Test
42 public void testBuild() {
43 ConversationInfo conversationInfo = new ConversationInfo.Builder()
44 .setShortcutId(SHORTCUT_ID)
45 .setLocusId(LOCUS_ID)
46 .setContactUri(CONTACT_URI)
47 .setContactPhoneNumber(PHONE_NUMBER)
48 .setNotificationChannelId(NOTIFICATION_CHANNEL_ID)
49 .setShortcutFlags(ShortcutInfo.FLAG_LONG_LIVED)
50 .setVip(true)
51 .setNotificationSilenced(true)
52 .setBubbled(true)
53 .setDemoted(true)
54 .setPersonImportant(true)
55 .setPersonBot(true)
56 .setContactStarred(true)
57 .build();
58
59 assertEquals(SHORTCUT_ID, conversationInfo.getShortcutId());
60 assertEquals(LOCUS_ID, conversationInfo.getLocusId());
61 assertEquals(CONTACT_URI, conversationInfo.getContactUri());
62 assertEquals(PHONE_NUMBER, conversationInfo.getContactPhoneNumber());
63 assertEquals(NOTIFICATION_CHANNEL_ID, conversationInfo.getNotificationChannelId());
64 assertTrue(conversationInfo.isShortcutLongLived());
65 assertTrue(conversationInfo.isVip());
66 assertTrue(conversationInfo.isNotificationSilenced());
67 assertTrue(conversationInfo.isBubbled());
68 assertTrue(conversationInfo.isDemoted());
69 assertTrue(conversationInfo.isPersonImportant());
70 assertTrue(conversationInfo.isPersonBot());
71 assertTrue(conversationInfo.isContactStarred());
72 }
73
74 @Test
75 public void testBuildEmpty() {
76 ConversationInfo conversationInfo = new ConversationInfo.Builder()
77 .setShortcutId(SHORTCUT_ID)
78 .build();
79
80 assertEquals(SHORTCUT_ID, conversationInfo.getShortcutId());
81 assertNull(conversationInfo.getLocusId());
82 assertNull(conversationInfo.getContactUri());
83 assertNull(conversationInfo.getContactPhoneNumber());
84 assertNull(conversationInfo.getNotificationChannelId());
85 assertFalse(conversationInfo.isShortcutLongLived());
86 assertFalse(conversationInfo.isVip());
87 assertFalse(conversationInfo.isNotificationSilenced());
88 assertFalse(conversationInfo.isBubbled());
89 assertFalse(conversationInfo.isDemoted());
90 assertFalse(conversationInfo.isPersonImportant());
91 assertFalse(conversationInfo.isPersonBot());
92 assertFalse(conversationInfo.isContactStarred());
93 }
94
95 @Test
96 public void testBuildFromAnotherConversationInfo() {
97 ConversationInfo source = new ConversationInfo.Builder()
98 .setShortcutId(SHORTCUT_ID)
99 .setLocusId(LOCUS_ID)
100 .setContactUri(CONTACT_URI)
101 .setContactPhoneNumber(PHONE_NUMBER)
102 .setNotificationChannelId(NOTIFICATION_CHANNEL_ID)
103 .setShortcutFlags(ShortcutInfo.FLAG_LONG_LIVED)
104 .setVip(true)
105 .setNotificationSilenced(true)
106 .setBubbled(true)
107 .setPersonImportant(true)
108 .setPersonBot(true)
109 .setContactStarred(true)
110 .build();
111
112 ConversationInfo destination = new ConversationInfo.Builder(source)
113 .setVip(false)
114 .setContactStarred(false)
115 .build();
116
117 assertEquals(SHORTCUT_ID, destination.getShortcutId());
118 assertEquals(LOCUS_ID, destination.getLocusId());
119 assertEquals(CONTACT_URI, destination.getContactUri());
120 assertEquals(PHONE_NUMBER, destination.getContactPhoneNumber());
121 assertEquals(NOTIFICATION_CHANNEL_ID, destination.getNotificationChannelId());
122 assertTrue(destination.isShortcutLongLived());
123 assertFalse(destination.isVip());
124 assertTrue(destination.isNotificationSilenced());
125 assertTrue(destination.isBubbled());
126 assertTrue(destination.isPersonImportant());
127 assertTrue(destination.isPersonBot());
128 assertFalse(destination.isContactStarred());
129 }
130}