blob: d75213c3e7731bde2840b9cb49f5165150fd3853 [file] [log] [blame]
Julia Reynoldseb3dca72017-07-11 10:39:58 -04001/*
2 * Copyright (C) 2017 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.notification;
18
19import static android.app.NotificationManager.IMPORTANCE_DEFAULT;
20import static android.app.NotificationManager.IMPORTANCE_HIGH;
21import static android.app.NotificationManager.IMPORTANCE_LOW;
22
23import static junit.framework.Assert.assertEquals;
24import static junit.framework.Assert.assertNotNull;
25import static junit.framework.Assert.assertNull;
26
27import static org.mockito.Matchers.any;
28import static org.mockito.Matchers.anyInt;
29import static org.mockito.Matchers.eq;
30import static org.mockito.Mockito.when;
31
32import android.app.Notification;
33import android.app.NotificationChannel;
34import android.app.PendingIntent;
35import android.content.Intent;
36import android.os.UserHandle;
37import android.service.notification.StatusBarNotification;
38
39import org.junit.Before;
40import org.junit.Test;
41import org.mockito.Mock;
42import org.mockito.MockitoAnnotations;
43
44public class NotificationChannelExtractorTest extends NotificationTestCase {
45
46 @Mock RankingConfig mConfig;
47
48 @Before
49 public void setUp() {
50 MockitoAnnotations.initMocks(this);
51 }
52
53 @Test
54 public void testExtractsUpdatedChannel() {
55 NotificationChannelExtractor extractor = new NotificationChannelExtractor();
56 extractor.setConfig(mConfig);
57
58 NotificationChannel channel = new NotificationChannel("a", "a", IMPORTANCE_LOW);
59 final Notification.Builder builder = new Notification.Builder(getContext())
60 .setContentTitle("foo")
61 .setSmallIcon(android.R.drawable.sym_def_app_icon);
62 Notification n = builder.build();
63 StatusBarNotification sbn = new StatusBarNotification("", "", 0, "", 0,
64 0, n, UserHandle.ALL, null, System.currentTimeMillis());
65 NotificationRecord r = new NotificationRecord(getContext(), sbn, channel);
66
67 NotificationChannel updatedChannel =
68 new NotificationChannel("a", "", IMPORTANCE_HIGH);
69 when(mConfig.getNotificationChannel(any(), anyInt(), eq("a"), eq(false)))
70 .thenReturn(updatedChannel);
71
72 assertNull(extractor.process(r));
73 assertEquals(updatedChannel, r.getChannel());
74 }
75
76}