Debian Codegraph @

libs/dream/lowlight/tests/src/com.android.dream.lowlight/LowLightDreamManagerTest.java

raw symbols SCIP
1 /*
2 * Copyright (C) 2022 The Android Open Source Project
3 *
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
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
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.
15 */
16
17 package com.android.dream.lowlight;
18
19 import static com.android.dream.lowlight.LowLightDreamManager.AMBIENT_LIGHT_MODE_LOW_LIGHT;
20 import static com.android.dream.lowlight.LowLightDreamManager.AMBIENT_LIGHT_MODE_REGULAR;
21 import static com.android.dream.lowlight.LowLightDreamManager.AMBIENT_LIGHT_MODE_UNKNOWN;
22
23 import static org.mockito.ArgumentMatchers.any;
24 import static org.mockito.Mockito.clearInvocations;
25 import static org.mockito.Mockito.never;
26 import static org.mockito.Mockito.verify;
27
28 import android.app.DreamManager;
29 import android.content.ComponentName;
30 import android.testing.AndroidTestingRunner;
31
32 import androidx.test.filters.SmallTest;
33
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;
39
40 @SmallTest
41 @RunWith(AndroidTestingRunner.class)
42 public class LowLightDreamManagerTest {
43 @Mock
44 private DreamManager mDreamManager;
45
46 @Mock
47 private ComponentName mDreamComponent;
48
49 @Before
50 public void setUp() {
51 MockitoAnnotations.initMocks(this);
52 }
53
54 @Test
55 public void setAmbientLightMode_lowLight_setSystemDream() {
56 final LowLightDreamManager lowLightDreamManager = new LowLightDreamManager(mDreamManager,
57 mDreamComponent);
58
59 lowLightDreamManager.setAmbientLightMode(AMBIENT_LIGHT_MODE_LOW_LIGHT);
60
61 verify(mDreamManager).setSystemDreamComponent(mDreamComponent);
62 }
63
64 @Test
65 public void setAmbientLightMode_regularLight_clearSystemDream() {
66 final LowLightDreamManager lowLightDreamManager = new LowLightDreamManager(mDreamManager,
67 mDreamComponent);
68
69 lowLightDreamManager.setAmbientLightMode(AMBIENT_LIGHT_MODE_REGULAR);
70
71 verify(mDreamManager).setSystemDreamComponent(null);
72 }
73
74 @Test
75 public void setAmbientLightMode_defaultUnknownMode_clearSystemDream() {
76 final LowLightDreamManager lowLightDreamManager = new LowLightDreamManager(mDreamManager,
77 mDreamComponent);
78
79 // Set to low light first.
80 lowLightDreamManager.setAmbientLightMode(AMBIENT_LIGHT_MODE_LOW_LIGHT);
81 clearInvocations(mDreamManager);
82
83 // Return to default unknown mode.
84 lowLightDreamManager.setAmbientLightMode(AMBIENT_LIGHT_MODE_UNKNOWN);
85
86 verify(mDreamManager).setSystemDreamComponent(null);
87 }
88
89 @Test
90 public void setAmbientLightMode_dreamComponentNotSet_doNothing() {
91 final LowLightDreamManager lowLightDreamManager = new LowLightDreamManager(mDreamManager,
92 null /*dream component*/);
93
94 lowLightDreamManager.setAmbientLightMode(AMBIENT_LIGHT_MODE_LOW_LIGHT);
95
96 verify(mDreamManager, never()).setSystemDreamComponent(any());
97 }
98 }