Home | History | Annotate | Download | only in notification
      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_HIGH;
     20 import static android.app.NotificationManager.IMPORTANCE_LOW;
     21 
     22 import static junit.framework.Assert.assertEquals;
     23 import static junit.framework.Assert.assertNotNull;
     24 import static junit.framework.Assert.assertNull;
     25 
     26 import static org.mockito.Matchers.any;
     27 import static org.mockito.Matchers.anyInt;
     28 import static org.mockito.Matchers.eq;
     29 import static org.mockito.Mockito.when;
     30 
     31 import android.app.Notification;
     32 import android.app.NotificationChannel;
     33 import android.os.UserHandle;
     34 import android.service.notification.StatusBarNotification;
     35 
     36 import com.android.server.UiServiceTestCase;
     37 
     38 import org.junit.Before;
     39 import org.junit.Test;
     40 import org.mockito.Mock;
     41 import org.mockito.MockitoAnnotations;
     42 
     43 public class NotificationChannelExtractorTest extends UiServiceTestCase {
     44 
     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 }
     76