Jason Monk | 9c7844c | 2017-01-18 15:21:53 -0500 | [diff] [blame] | 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; |
| 16 | |
| 17 | import static org.junit.Assert.assertEquals; |
Jason Monk | 685db72 | 2017-01-23 17:36:50 -0500 | [diff] [blame] | 18 | import static org.mockito.Matchers.any; |
Jason Monk | 9c7844c | 2017-01-18 15:21:53 -0500 | [diff] [blame] | 19 | import static org.mockito.Matchers.eq; |
| 20 | import static org.mockito.Mockito.mock; |
| 21 | import static org.mockito.Mockito.verify; |
| 22 | |
| 23 | import android.os.Looper; |
Brett Chabot | 84151d9 | 2019-02-27 15:37:59 -0800 | [diff] [blame] | 24 | |
| 25 | import androidx.test.filters.SmallTest; |
Jason Monk | 9c7844c | 2017-01-18 15:21:53 -0500 | [diff] [blame] | 26 | |
Adrian Roos | 09c43c8 | 2017-02-09 19:58:25 +0100 | [diff] [blame] | 27 | import com.android.systemui.Dependency.DependencyKey; |
Jason Monk | 9c7844c | 2017-01-18 15:21:53 -0500 | [diff] [blame] | 28 | import com.android.systemui.statusbar.policy.FlashlightController; |
| 29 | |
Jason Monk | e750748 | 2017-02-02 13:00:05 -0500 | [diff] [blame] | 30 | import org.junit.Assert; |
Jason Monk | 9c7844c | 2017-01-18 15:21:53 -0500 | [diff] [blame] | 31 | import org.junit.Test; |
| 32 | |
Lucas Dupin | 64171fe | 2019-10-30 14:28:29 -0700 | [diff] [blame] | 33 | import java.io.FileDescriptor; |
Jason Monk | 685db72 | 2017-01-23 17:36:50 -0500 | [diff] [blame] | 34 | import java.io.PrintWriter; |
| 35 | |
Jason Monk | fba8faf | 2017-05-23 10:42:59 -0400 | [diff] [blame] | 36 | @SmallTest |
Jason Monk | 9c7844c | 2017-01-18 15:21:53 -0500 | [diff] [blame] | 37 | public class DependencyTest extends SysuiTestCase { |
| 38 | |
Adrian Roos | 09c43c8 | 2017-02-09 19:58:25 +0100 | [diff] [blame] | 39 | public static final DependencyKey<Dumpable> DUMPABLE = new DependencyKey<>("dumpable"); |
Adrian Roos | 09c43c8 | 2017-02-09 19:58:25 +0100 | [diff] [blame] | 40 | |
Jason Monk | 9c7844c | 2017-01-18 15:21:53 -0500 | [diff] [blame] | 41 | @Test |
| 42 | public void testClassDependency() { |
| 43 | FlashlightController f = mock(FlashlightController.class); |
Jason Monk | 340b0e5 | 2017-03-08 14:57:56 -0500 | [diff] [blame] | 44 | mDependency.injectTestDependency(FlashlightController.class, f); |
Jason Monk | e750748 | 2017-02-02 13:00:05 -0500 | [diff] [blame] | 45 | Assert.assertEquals(f, Dependency.get(FlashlightController.class)); |
Jason Monk | 9c7844c | 2017-01-18 15:21:53 -0500 | [diff] [blame] | 46 | } |
| 47 | |
| 48 | @Test |
| 49 | public void testStringDependency() { |
| 50 | Looper l = Looper.getMainLooper(); |
Jason Monk | 340b0e5 | 2017-03-08 14:57:56 -0500 | [diff] [blame] | 51 | mDependency.injectTestDependency(Dependency.BG_LOOPER, l); |
Jason Monk | 9c7844c | 2017-01-18 15:21:53 -0500 | [diff] [blame] | 52 | assertEquals(l, Dependency.get(Dependency.BG_LOOPER)); |
| 53 | } |
| 54 | |
| 55 | @Test |
| 56 | public void testDump() { |
| 57 | Dumpable d = mock(Dumpable.class); |
Lucas Dupin | 64171fe | 2019-10-30 14:28:29 -0700 | [diff] [blame] | 58 | String[] args = new String[0]; |
| 59 | FileDescriptor fd = mock(FileDescriptor.class); |
Jason Monk | 340b0e5 | 2017-03-08 14:57:56 -0500 | [diff] [blame] | 60 | mDependency.injectTestDependency(DUMPABLE, d); |
Adrian Roos | 09c43c8 | 2017-02-09 19:58:25 +0100 | [diff] [blame] | 61 | Dependency.get(DUMPABLE); |
Lucas Dupin | 64171fe | 2019-10-30 14:28:29 -0700 | [diff] [blame] | 62 | mDependency.dump(fd, mock(PrintWriter.class), args); |
| 63 | verify(d).dump(eq(fd), any(), eq(args)); |
Jason Monk | 9c7844c | 2017-01-18 15:21:53 -0500 | [diff] [blame] | 64 | } |
| 65 | |
| 66 | @Test |
Jason Monk | c29c202 | 2019-01-03 16:52:37 -0500 | [diff] [blame] | 67 | public void testInitDependency() { |
| 68 | Dependency.clearDependencies(); |
Dave Mankoff | eb593ae | 2019-09-04 11:31:55 -0400 | [diff] [blame] | 69 | Dependency dependency = new Dependency(); |
| 70 | SystemUIFactory |
| 71 | .getInstance().getRootComponent().createDependency().createSystemUI(dependency); |
| 72 | dependency.start(); |
Jason Monk | c29c202 | 2019-01-03 16:52:37 -0500 | [diff] [blame] | 73 | } |
Jason Monk | 9c7844c | 2017-01-18 15:21:53 -0500 | [diff] [blame] | 74 | } |