Home | History | Annotate | Download | only in systemui
      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;
     18 import static org.mockito.Matchers.any;
     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;
     24 
     25 import androidx.test.filters.SmallTest;
     26 
     27 import com.android.systemui.Dependency.DependencyKey;
     28 import com.android.systemui.statusbar.policy.FlashlightController;
     29 
     30 import org.junit.Assert;
     31 import org.junit.Test;
     32 
     33 import java.io.PrintWriter;
     34 
     35 @SmallTest
     36 public class DependencyTest extends SysuiTestCase {
     37 
     38     public static final DependencyKey<Dumpable> DUMPABLE = new DependencyKey<>("dumpable");
     39     public static final DependencyKey<ConfigurationChangedReceiver> CONFIGURATION_CHANGED_RECEIVER
     40             = new DependencyKey<>("config_changed_receiver");
     41 
     42     @Test
     43     public void testClassDependency() {
     44         FlashlightController f = mock(FlashlightController.class);
     45         mDependency.injectTestDependency(FlashlightController.class, f);
     46         Assert.assertEquals(f, Dependency.get(FlashlightController.class));
     47     }
     48 
     49     @Test
     50     public void testStringDependency() {
     51         Looper l = Looper.getMainLooper();
     52         mDependency.injectTestDependency(Dependency.BG_LOOPER, l);
     53         assertEquals(l, Dependency.get(Dependency.BG_LOOPER));
     54     }
     55 
     56     @Test
     57     public void testDump() {
     58         Dumpable d = mock(Dumpable.class);
     59         mDependency.injectTestDependency(DUMPABLE, d);
     60         Dependency.get(DUMPABLE);
     61         mDependency.dump(null, mock(PrintWriter.class), null);
     62         verify(d).dump(eq(null), any(), eq(null));
     63     }
     64 
     65     @Test
     66     public void testConfigurationChanged() {
     67         ConfigurationChangedReceiver d = mock(ConfigurationChangedReceiver.class);
     68         mDependency.injectTestDependency(CONFIGURATION_CHANGED_RECEIVER, d);
     69         Dependency.get(CONFIGURATION_CHANGED_RECEIVER);
     70         mDependency.onConfigurationChanged(null);
     71         verify(d).onConfigurationChanged(eq(null));
     72     }
     73 
     74     @Test
     75     public void testInitDependency() {
     76         Dependency.clearDependencies();
     77         Dependency.initDependencies(mContext);
     78     }
     79 }
     80