1 /* 2 * Copyright (C) 2019 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.systemui.statusbar.notification.stack; 18 19 import static android.view.ViewGroup.LayoutParams.WRAP_CONTENT; 20 21 import static org.mockito.ArgumentMatchers.any; 22 import static org.mockito.Mockito.when; 23 24 import android.testing.AndroidTestingRunner; 25 import android.testing.TestableLooper; 26 import android.util.AttributeSet; 27 import android.view.View; 28 import android.view.ViewGroup; 29 30 import androidx.test.filters.SmallTest; 31 32 import com.android.systemui.SysuiTestCase; 33 import com.android.systemui.media.controls.ui.controller.KeyguardMediaController; 34 import com.android.systemui.plugins.statusbar.StatusBarStateController; 35 import com.android.systemui.statusbar.StatusBarState; 36 import com.android.systemui.statusbar.notification.NotificationSectionsFeatureManager; 37 import com.android.systemui.statusbar.notification.collection.render.MediaContainerController; 38 import com.android.systemui.statusbar.notification.collection.render.SectionHeaderController; 39 import com.android.systemui.statusbar.policy.ConfigurationController; 40 41 import org.junit.Before; 42 import org.junit.Rule; 43 import org.junit.Test; 44 import org.junit.runner.RunWith; 45 import org.mockito.Mock; 46 import org.mockito.junit.MockitoJUnit; 47 import org.mockito.junit.MockitoRule; 48 49 @SmallTest 50 @RunWith(AndroidTestingRunner.class) 51 @TestableLooper.RunWithLooper(setAsMainLooper = true) 52 public class NotificationSectionsManagerTest extends SysuiTestCase { 53 54 @Rule public final MockitoRule mockitoRule = MockitoJUnit.rule(); 55 56 @Mock private NotificationStackScrollLayout mNssl; 57 @Mock private StatusBarStateController mStatusBarStateController; 58 @Mock private ConfigurationController mConfigurationController; 59 @Mock private KeyguardMediaController mKeyguardMediaController; 60 @Mock private NotificationSectionsFeatureManager mSectionsFeatureManager; 61 @Mock private MediaContainerController mMediaContainerController; 62 @Mock private NotificationRoundnessManager mNotificationRoundnessManager; 63 @Mock private SectionHeaderController mIncomingHeaderController; 64 @Mock private SectionHeaderController mPeopleHeaderController; 65 @Mock private SectionHeaderController mAlertingHeaderController; 66 @Mock private SectionHeaderController mSilentHeaderController; 67 68 private NotificationSectionsManager mSectionsManager; 69 70 @Before setUp()71 public void setUp() { 72 when(mSectionsFeatureManager.getNumberOfBuckets()).thenAnswer( 73 invocation -> { 74 int count = 2; 75 if (mSectionsFeatureManager.isFilteringEnabled()) { 76 count = 5; 77 } 78 if (mSectionsFeatureManager.isMediaControlsEnabled()) { 79 if (!mSectionsFeatureManager.isFilteringEnabled()) { 80 count = 5; 81 } else { 82 count += 1; 83 } 84 } 85 return count; 86 }); 87 mSectionsManager = 88 new NotificationSectionsManager( 89 mConfigurationController, 90 mKeyguardMediaController, 91 mSectionsFeatureManager, 92 mMediaContainerController, 93 mNotificationRoundnessManager, 94 mIncomingHeaderController, 95 mPeopleHeaderController, 96 mAlertingHeaderController, 97 mSilentHeaderController 98 ); 99 // Required in order for the header inflation to work properly 100 when(mNssl.generateLayoutParams(any(AttributeSet.class))) 101 .thenReturn(new ViewGroup.LayoutParams(WRAP_CONTENT, WRAP_CONTENT)); 102 mSectionsManager.initialize(mNssl); 103 when(mNssl.indexOfChild(any(View.class))).thenReturn(-1); 104 when(mStatusBarStateController.getState()).thenReturn(StatusBarState.SHADE); 105 } 106 107 @Test(expected = IllegalStateException.class) testDuplicateInitializeThrows()108 public void testDuplicateInitializeThrows() { 109 mSectionsManager.initialize(mNssl); 110 } 111 112 } 113