OSDN Git Service

Send less ranking reconsiderations and updates
[android-x86/frameworks-base.git] / services / tests / notification / src / com / android / server / notification / NotificationChannelExtractorTest.java
1 /*
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
17 package com.android.server.notification;
18
19 import static android.app.NotificationManager.IMPORTANCE_DEFAULT;
20 import static android.app.NotificationManager.IMPORTANCE_HIGH;
21 import static android.app.NotificationManager.IMPORTANCE_LOW;
22
23 import static junit.framework.Assert.assertEquals;
24 import static junit.framework.Assert.assertNotNull;
25 import static junit.framework.Assert.assertNull;
26
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;
31
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;
38
39 import org.junit.Before;
40 import org.junit.Test;
41 import org.mockito.Mock;
42 import org.mockito.MockitoAnnotations;
43
44 public 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 }