blob: cca9f2834e93eca9f8f7ea8bbf424b9707b90c04 [file] [log] [blame]
Joshua Tsuji614b1df2019-03-26 13:57:05 -04001/*
2 * Copyright (C) 2019 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.systemui.statusbar.notification.collection;
18
19import static org.junit.Assert.assertEquals;
20import static org.junit.Assert.assertNull;
21import static org.mockito.Mockito.doReturn;
22import static org.mockito.Mockito.when;
23
24import android.app.Notification;
25import android.os.Bundle;
26import android.service.notification.StatusBarNotification;
27import android.testing.AndroidTestingRunner;
28import android.testing.TestableLooper;
29
30import androidx.test.filters.SmallTest;
31
32import com.android.systemui.SysuiTestCase;
33
34import org.junit.Before;
35import org.junit.Test;
36import org.junit.runner.RunWith;
37import org.mockito.Mock;
38import org.mockito.MockitoAnnotations;
39
40@SmallTest
41@RunWith(AndroidTestingRunner.class)
42@TestableLooper.RunWithLooper
43public class NotificationEntryTest extends SysuiTestCase {
44 @Mock
45 private StatusBarNotification mStatusBarNotification;
46 @Mock
47 private Notification mNotif;
48
49 private NotificationEntry mEntry;
50 private Bundle mExtras;
51
52 @Before
53 public void setUp() {
54 MockitoAnnotations.initMocks(this);
55
56 when(mStatusBarNotification.getKey()).thenReturn("key");
57 when(mStatusBarNotification.getNotification()).thenReturn(mNotif);
58
59 mExtras = new Bundle();
60 mNotif.extras = mExtras;
61
62 mEntry = new NotificationEntry(mStatusBarNotification);
63 }
64
65 @Test
66 public void testGetUpdateMessage_default() {
67 final String msg = "Hello there!";
68 doReturn(Notification.Style.class).when(mNotif).getNotificationStyle();
69 mExtras.putCharSequence(Notification.EXTRA_TEXT, msg);
70 assertEquals(msg, mEntry.getUpdateMessage(mContext));
71 }
72
73 @Test
74 public void testGetUpdateMessage_bigText() {
75 final String msg = "A big hello there!";
76 doReturn(Notification.BigTextStyle.class).when(mNotif).getNotificationStyle();
77 mExtras.putCharSequence(Notification.EXTRA_TEXT, "A small hello there.");
78 mExtras.putCharSequence(Notification.EXTRA_BIG_TEXT, msg);
79
80 // Should be big text, not the small text.
81 assertEquals(msg, mEntry.getUpdateMessage(mContext));
82 }
83
84 @Test
85 public void testGetUpdateMessage_media() {
86 doReturn(Notification.MediaStyle.class).when(mNotif).getNotificationStyle();
87
88 // Media notifs don't get update messages.
89 assertNull(mEntry.getUpdateMessage(mContext));
90 }
91
92 @Test
93 public void testGetUpdateMessage_inboxStyle() {
94 doReturn(Notification.InboxStyle.class).when(mNotif).getNotificationStyle();
95 mExtras.putCharSequenceArray(
96 Notification.EXTRA_TEXT_LINES,
97 new CharSequence[]{
98 "How do you feel about tests?",
99 "They're okay, I guess.",
100 "I hate when they're flaky.",
101 "Really? I prefer them that way."});
102
103 // Should be the last one only.
104 assertEquals("Really? I prefer them that way.", mEntry.getUpdateMessage(mContext));
105 }
106
107 @Test
108 public void testGetUpdateMessage_messagingStyle() {
109 doReturn(Notification.MessagingStyle.class).when(mNotif).getNotificationStyle();
110 mExtras.putParcelableArray(
111 Notification.EXTRA_MESSAGES,
112 new Bundle[]{
113 new Notification.MessagingStyle.Message(
114 "Hello", 0, "Josh").toBundle(),
115 new Notification.MessagingStyle.Message(
116 "Oh, hello!", 0, "Mady").toBundle()});
117
118 // Should be the last one only.
119 assertEquals("Mady: Oh, hello!", mEntry.getUpdateMessage(mContext));
120 }
121}