blob: eb45960bc82f7e908c13aa38f9bd8a2874095958 [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
Julia Reynoldseb3dca72017-07-11 10:39:58 -040019import static android.app.NotificationManager.IMPORTANCE_HIGH;
20import static android.app.NotificationManager.IMPORTANCE_LOW;
21
22import static junit.framework.Assert.assertEquals;
23import static junit.framework.Assert.assertNotNull;
24import static junit.framework.Assert.assertNull;
25
26import static org.mockito.Matchers.any;
27import static org.mockito.Matchers.anyInt;
28import static org.mockito.Matchers.eq;
29import static org.mockito.Mockito.when;
30
31import android.app.Notification;
32import android.app.NotificationChannel;
Julia Reynoldseb3dca72017-07-11 10:39:58 -040033import android.os.UserHandle;
34import android.service.notification.StatusBarNotification;
35
Jason Monk74f5e362017-12-06 08:56:33 -050036import com.android.server.UiServiceTestCase;
37
Julia Reynoldseb3dca72017-07-11 10:39:58 -040038import org.junit.Before;
39import org.junit.Test;
40import org.mockito.Mock;
41import org.mockito.MockitoAnnotations;
42
Jason Monk74f5e362017-12-06 08:56:33 -050043public class NotificationChannelExtractorTest extends UiServiceTestCase {
Julia Reynoldseb3dca72017-07-11 10:39:58 -040044
45 @Mock RankingConfig mConfig;
46
47 @Before
48 public void setUp() {
49 MockitoAnnotations.initMocks(this);
50 }
51
52 @Test
53 public void testExtractsUpdatedChannel() {
54 NotificationChannelExtractor extractor = new NotificationChannelExtractor();
55 extractor.setConfig(mConfig);
56
57 NotificationChannel channel = new NotificationChannel("a", "a", IMPORTANCE_LOW);
58 final Notification.Builder builder = new Notification.Builder(getContext())
59 .setContentTitle("foo")
60 .setSmallIcon(android.R.drawable.sym_def_app_icon);
61 Notification n = builder.build();
62 StatusBarNotification sbn = new StatusBarNotification("", "", 0, "", 0,
63 0, n, UserHandle.ALL, null, System.currentTimeMillis());
64 NotificationRecord r = new NotificationRecord(getContext(), sbn, channel);
65
66 NotificationChannel updatedChannel =
67 new NotificationChannel("a", "", IMPORTANCE_HIGH);
68 when(mConfig.getNotificationChannel(any(), anyInt(), eq("a"), eq(false)))
69 .thenReturn(updatedChannel);
70
71 assertNull(extractor.process(r));
72 assertEquals(updatedChannel, r.getChannel());
73 }
74
75}