blob: 0d13e975e56ad0682ff9e6c242a2a791345cb66b [file] [log] [blame]
Jason Monkae7ced22018-08-22 16:56:58 -04001/*
2 * Copyright (C) 2018 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.statusbar.phone
16
17import android.support.test.filters.SmallTest
18import android.testing.AndroidTestingRunner
19import com.android.systemui.SysuiTestCase
20import com.android.systemui.statusbar.policy.ConfigurationController.ConfigurationListener
21import org.junit.Test
22import org.junit.runner.RunWith
23import org.mockito.Mockito.doAnswer
24import org.mockito.Mockito.mock
25import org.mockito.Mockito.never
26import org.mockito.Mockito.verify
27
28@RunWith(AndroidTestingRunner::class)
29@SmallTest
30class ConfigurationControllerImplTest : SysuiTestCase() {
31
32 private val mConfigurationController =
33 com.android.systemui.statusbar.phone.ConfigurationControllerImpl(mContext)
34
35 @Test
36 fun testThemeChange() {
37 val listener = mock(ConfigurationListener::class.java)
38 mConfigurationController.addCallback(listener)
39
40 mConfigurationController.notifyThemeChanged()
41 verify(listener).onThemeChanged()
42 }
43
44 @Test
45 fun testRemoveListenerDuringCallback() {
46 val listener = mock(ConfigurationListener::class.java)
47 mConfigurationController.addCallback(listener)
48 val listener2 = mock(ConfigurationListener::class.java)
49 mConfigurationController.addCallback(listener2)
50
51 doAnswer {
52 mConfigurationController.removeCallback(listener2)
53 null
54 }.`when`(listener).onThemeChanged()
55
56 mConfigurationController.notifyThemeChanged()
57 verify(listener).onThemeChanged()
58 verify(listener2, never()).onThemeChanged()
59 }
60}