2 * Copyright (C) 2017 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package com.android.server.notification;
19 import static android.app.NotificationManager.IMPORTANCE_DEFAULT;
20 import static android.app.NotificationManager.IMPORTANCE_HIGH;
21 import static android.app.NotificationManager.IMPORTANCE_LOW;
23 import static junit.framework.Assert.assertEquals;
24 import static junit.framework.Assert.assertNotNull;
25 import static junit.framework.Assert.assertNull;
27 import static org.mockito.Matchers.any;
28 import static org.mockito.Matchers.anyInt;
29 import static org.mockito.Matchers.eq;
30 import static org.mockito.Mockito.when;
32 import android.app.Notification;
33 import android.app.NotificationChannel;
34 import android.app.PendingIntent;
35 import android.content.Intent;
36 import android.os.UserHandle;
37 import android.service.notification.StatusBarNotification;
39 import org.junit.Before;
40 import org.junit.Test;
41 import org.mockito.Mock;
42 import org.mockito.MockitoAnnotations;
44 public class NotificationChannelExtractorTest extends NotificationTestCase {
46 @Mock RankingConfig mConfig;
50 MockitoAnnotations.initMocks(this);
54 public void testExtractsUpdatedChannel() {
55 NotificationChannelExtractor extractor = new NotificationChannelExtractor();
56 extractor.setConfig(mConfig);
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);
67 NotificationChannel updatedChannel =
68 new NotificationChannel("a", "", IMPORTANCE_HIGH);
69 when(mConfig.getNotificationChannel(any(), anyInt(), eq("a"), eq(false)))
70 .thenReturn(updatedChannel);
72 assertNull(extractor.process(r));
73 assertEquals(updatedChannel, r.getChannel());