1 /* 2 * Copyright (C) 2017 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file 5 * except in compliance with the License. You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software distributed under the 10 * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 11 * KIND, either express or implied. See the License for the specific language governing 12 * permissions and limitations under the License. 13 */ 14 15 package com.android.systemui.util; 16 17 import static org.junit.Assert.assertEquals; 18 import static org.junit.Assert.assertTrue; 19 import static org.mockito.Mockito.mock; 20 import static org.mockito.Mockito.verify; 21 22 import android.app.NotificationChannel; 23 import android.app.NotificationManager; 24 import android.content.Context; 25 import android.test.suitebuilder.annotation.SmallTest; 26 import android.util.ArraySet; 27 28 import androidx.test.runner.AndroidJUnit4; 29 30 import com.android.systemui.SysuiTestCase; 31 32 import org.junit.Before; 33 import org.junit.Test; 34 import org.junit.runner.RunWith; 35 import org.mockito.ArgumentCaptor; 36 37 import java.util.Arrays; 38 import java.util.List; 39 import java.util.Set; 40 41 @SmallTest 42 @RunWith(AndroidJUnit4.class) 43 public class NotificationChannelsTest extends SysuiTestCase { 44 private final NotificationManager mMockNotificationManager = mock(NotificationManager.class); 45 46 @Before setup()47 public void setup() throws Exception { 48 mContext.addMockSystemService(Context.NOTIFICATION_SERVICE, mMockNotificationManager); 49 } 50 51 @Test testChannelSetup()52 public void testChannelSetup() { 53 Set<String> ALL_CHANNELS = new ArraySet<>(Arrays.asList( 54 NotificationChannels.ALERTS, 55 NotificationChannels.SCREENSHOTS_HEADSUP, 56 NotificationChannels.STORAGE, 57 NotificationChannels.INSTANT, 58 NotificationChannels.BATTERY, 59 NotificationChannels.HINTS, 60 NotificationChannels.SETUP 61 )); 62 NotificationChannels.createAll(mContext); 63 ArgumentCaptor<List> captor = ArgumentCaptor.forClass(List.class); 64 verify(mMockNotificationManager).createNotificationChannels(captor.capture()); 65 final List<NotificationChannel> list = captor.getValue(); 66 assertEquals(ALL_CHANNELS.size(), list.size()); 67 list.forEach((chan) -> assertTrue(ALL_CHANNELS.contains(chan.getId()))); 68 } 69 70 @Test testChannelCleanup()71 public void testChannelCleanup() { 72 new NotificationChannels(mContext).start(); 73 ArgumentCaptor<String> captor = ArgumentCaptor.forClass(String.class); 74 verify(mMockNotificationManager).deleteNotificationChannel(captor.capture()); 75 assertEquals(NotificationChannels.GENERAL, captor.getValue()); 76 } 77 } 78