blob: 61bfa758ad79ffe0be125b7591c89b66e8103191 [file] [log] [blame]
Jason Monk9c7844c2017-01-18 15:21:53 -05001/*
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
15package com.android.systemui;
16
17import static org.junit.Assert.assertEquals;
Jason Monk685db722017-01-23 17:36:50 -050018import static org.mockito.Matchers.any;
Jason Monk9c7844c2017-01-18 15:21:53 -050019import static org.mockito.Matchers.eq;
20import static org.mockito.Mockito.mock;
21import static org.mockito.Mockito.verify;
22
23import android.os.Looper;
Jason Monkfba8faf2017-05-23 10:42:59 -040024import android.support.test.filters.SmallTest;
Jason Monk9c7844c2017-01-18 15:21:53 -050025
Adrian Roos09c43c82017-02-09 19:58:25 +010026import com.android.systemui.Dependency.DependencyKey;
Jason Monk9c7844c2017-01-18 15:21:53 -050027import com.android.systemui.statusbar.policy.FlashlightController;
28
Jason Monke7507482017-02-02 13:00:05 -050029import org.junit.Assert;
Jason Monk9c7844c2017-01-18 15:21:53 -050030import org.junit.Test;
31
Jason Monk685db722017-01-23 17:36:50 -050032import java.io.PrintWriter;
33
Jason Monkfba8faf2017-05-23 10:42:59 -040034@SmallTest
Jason Monk9c7844c2017-01-18 15:21:53 -050035public class DependencyTest extends SysuiTestCase {
36
Adrian Roos09c43c82017-02-09 19:58:25 +010037 public static final DependencyKey<Dumpable> DUMPABLE = new DependencyKey<>("dumpable");
38 public static final DependencyKey<ConfigurationChangedReceiver> CONFIGURATION_CHANGED_RECEIVER
39 = new DependencyKey<>("config_changed_receiver");
40
Jason Monk9c7844c2017-01-18 15:21:53 -050041 @Test
42 public void testClassDependency() {
43 FlashlightController f = mock(FlashlightController.class);
Jason Monk340b0e52017-03-08 14:57:56 -050044 mDependency.injectTestDependency(FlashlightController.class, f);
Jason Monke7507482017-02-02 13:00:05 -050045 Assert.assertEquals(f, Dependency.get(FlashlightController.class));
Jason Monk9c7844c2017-01-18 15:21:53 -050046 }
47
48 @Test
49 public void testStringDependency() {
50 Looper l = Looper.getMainLooper();
Jason Monk340b0e52017-03-08 14:57:56 -050051 mDependency.injectTestDependency(Dependency.BG_LOOPER, l);
Jason Monk9c7844c2017-01-18 15:21:53 -050052 assertEquals(l, Dependency.get(Dependency.BG_LOOPER));
53 }
54
55 @Test
56 public void testDump() {
57 Dumpable d = mock(Dumpable.class);
Jason Monk340b0e52017-03-08 14:57:56 -050058 mDependency.injectTestDependency(DUMPABLE, d);
Adrian Roos09c43c82017-02-09 19:58:25 +010059 Dependency.get(DUMPABLE);
Jason Monk685db722017-01-23 17:36:50 -050060 mDependency.dump(null, mock(PrintWriter.class), null);
61 verify(d).dump(eq(null), any(), eq(null));
Jason Monk9c7844c2017-01-18 15:21:53 -050062 }
63
64 @Test
65 public void testConfigurationChanged() {
66 ConfigurationChangedReceiver d = mock(ConfigurationChangedReceiver.class);
Jason Monk340b0e52017-03-08 14:57:56 -050067 mDependency.injectTestDependency(CONFIGURATION_CHANGED_RECEIVER, d);
Adrian Roos09c43c82017-02-09 19:58:25 +010068 Dependency.get(CONFIGURATION_CHANGED_RECEIVER);
Jason Monk9c7844c2017-01-18 15:21:53 -050069 mDependency.onConfigurationChanged(null);
70 verify(d).onConfigurationChanged(eq(null));
71 }
Jason Monkc29c2022019-01-03 16:52:37 -050072
73 @Test
74 public void testInitDependency() {
75 Dependency.clearDependencies();
76 Dependency.initDependencies(mContext);
77 }
Jason Monk9c7844c2017-01-18 15:21:53 -050078}