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.systemui.statusbar;
19 import static org.junit.Assert.assertFalse;
20 import static org.mockito.Mockito.when;
22 import android.os.Handler;
23 import android.os.Looper;
24 import android.support.test.filters.SmallTest;
25 import android.testing.AndroidTestingRunner;
26 import android.testing.TestableLooper;
28 import com.android.systemui.Dependency;
29 import com.android.systemui.SysuiTestCase;
30 import com.android.systemui.statusbar.phone.NotificationGroupManager;
31 import com.android.systemui.statusbar.phone.StatusBarWindowManager;
32 import com.android.systemui.statusbar.policy.HeadsUpManager;
34 import org.junit.Before;
35 import org.junit.Test;
36 import org.junit.runner.RunWith;
37 import org.mockito.Mock;
38 import org.mockito.MockitoAnnotations;
41 * Verifies that particular sets of dependencies don't have dependencies on others. For example,
42 * code managing notifications shouldn't directly depend on StatusBar, since there are platforms
43 * which want to manage notifications, but don't use StatusBar.
46 @RunWith(AndroidTestingRunner.class)
47 @TestableLooper.RunWithLooper
48 public class NonPhoneDependencyTest extends SysuiTestCase {
49 @Mock private NotificationPresenter mPresenter;
50 @Mock private NotificationListContainer mListContainer;
51 @Mock private NotificationEntryManager.Callback mEntryManagerCallback;
52 @Mock private HeadsUpManager mHeadsUpManager;
53 @Mock private RemoteInputController.Delegate mDelegate;
54 @Mock private NotificationInfo.CheckSaveListener mCheckSaveListener;
55 @Mock private NotificationGutsManager.OnSettingsClickListener mOnClickListener;
56 @Mock private NotificationRemoteInputManager.Callback mRemoteInputManagerCallback;
60 MockitoAnnotations.initMocks(this);
61 when(mPresenter.getHandler()).thenReturn(Handler.createAsync(Looper.myLooper()));
65 public void testNotificationManagementCodeHasNoDependencyOnStatusBarWindowManager() {
66 NotificationEntryManager entryManager = Dependency.get(NotificationEntryManager.class);
67 NotificationGutsManager gutsManager = Dependency.get(NotificationGutsManager.class);
68 NotificationListener notificationListener = Dependency.get(NotificationListener.class);
69 NotificationLogger notificationLogger = Dependency.get(NotificationLogger.class);
70 NotificationMediaManager mediaManager = Dependency.get(NotificationMediaManager.class);
71 NotificationRemoteInputManager remoteInputManager =
72 Dependency.get(NotificationRemoteInputManager.class);
73 NotificationLockscreenUserManager lockscreenUserManager =
74 Dependency.get(NotificationLockscreenUserManager.class);
75 NotificationViewHierarchyManager viewHierarchyManager =
76 Dependency.get(NotificationViewHierarchyManager.class);
78 when(mPresenter.getNotificationLockscreenUserManager()).thenReturn(lockscreenUserManager);
79 when(mPresenter.getGroupManager()).thenReturn(
80 Dependency.get(NotificationGroupManager.class));
82 entryManager.setUpWithPresenter(mPresenter, mListContainer, mEntryManagerCallback,
84 gutsManager.setUpWithPresenter(mPresenter, entryManager, mListContainer,
85 mCheckSaveListener, mOnClickListener);
86 notificationLogger.setUpWithEntryManager(entryManager, mListContainer);
87 mediaManager.setUpWithPresenter(mPresenter, entryManager);
88 remoteInputManager.setUpWithPresenter(mPresenter, entryManager, mRemoteInputManagerCallback,
90 lockscreenUserManager.setUpWithPresenter(mPresenter, entryManager);
91 viewHierarchyManager.setUpWithPresenter(mPresenter, entryManager, mListContainer);
92 notificationListener.setUpWithPresenter(mPresenter, entryManager);
94 assertFalse(mDependency.hasInstantiatedDependency(StatusBarWindowManager.class));