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.statusbar.phone; 16 17 import static org.mockito.ArgumentMatchers.eq; 18 import static org.mockito.Mockito.mock; 19 import static org.mockito.Mockito.verify; 20 21 import android.support.test.filters.SmallTest; 22 import android.testing.AndroidTestingRunner; 23 import android.testing.TestableLooper.RunWithLooper; 24 import android.view.ViewGroup; 25 import android.widget.LinearLayout; 26 27 import com.android.internal.statusbar.StatusBarIcon; 28 import com.android.systemui.statusbar.StatusBarIconView; 29 import com.android.systemui.statusbar.phone.StatusBarIconController.DarkIconManager; 30 import com.android.systemui.statusbar.phone.StatusBarIconController.IconManager; 31 import com.android.systemui.statusbar.policy.DarkIconDispatcher; 32 import com.android.systemui.utils.leaks.LeakCheckedTest; 33 34 import org.junit.Before; 35 import org.junit.Test; 36 import org.junit.runner.RunWith; 37 38 @RunWith(AndroidTestingRunner.class) 39 @RunWithLooper 40 @SmallTest 41 public class StatusBarIconControllerTest extends LeakCheckedTest { 42 43 @Before 44 public void setup() { 45 injectLeakCheckedDependencies(ALL_SUPPORTED_CLASSES); 46 mDependency.injectMockDependency(DarkIconDispatcher.class); 47 } 48 49 @Test 50 public void testSetCalledOnAdd_IconManager() { 51 LinearLayout layout = new LinearLayout(mContext); 52 TestIconManager manager = new TestIconManager(layout); 53 StatusBarIcon icon = mock(StatusBarIcon.class); 54 55 manager.onIconAdded(0, "test_slot", false, icon); 56 verify(manager.mMock).set(eq(icon)); 57 } 58 59 @Test 60 public void testSetCalledOnAdd_DarkIconManager() { 61 LinearLayout layout = new LinearLayout(mContext); 62 TestDarkIconManager manager = new TestDarkIconManager(layout); 63 StatusBarIcon icon = mock(StatusBarIcon.class); 64 65 manager.onIconAdded(0, "test_slot", false, icon); 66 verify(manager.mMock).set(eq(icon)); 67 } 68 69 private static class TestDarkIconManager extends DarkIconManager { 70 71 private final StatusBarIconView mMock; 72 73 public TestDarkIconManager(LinearLayout group) { 74 super(group); 75 mMock = mock(StatusBarIconView.class); 76 } 77 78 @Override 79 protected StatusBarIconView onCreateStatusBarIconView(String slot, boolean blocked) { 80 return mMock; 81 } 82 } 83 84 private static class TestIconManager extends IconManager { 85 86 private final StatusBarIconView mMock; 87 88 public TestIconManager(ViewGroup group) { 89 super(group); 90 mMock = mock(StatusBarIconView.class); 91 } 92 93 @Override 94 protected StatusBarIconView onCreateStatusBarIconView(String slot, boolean blocked) { 95 return mMock; 96 } 97 } 98 99 } 100