Jason Monk | ae7ced2 | 2018-08-22 16:56:58 -0400 | [diff] [blame] | 1 | /* |
| 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 | |
| 15 | package com.android.systemui.statusbar.phone |
| 16 | |
Brett Chabot | 84151d9 | 2019-02-27 15:37:59 -0800 | [diff] [blame] | 17 | import androidx.test.filters.SmallTest |
Jason Monk | ae7ced2 | 2018-08-22 16:56:58 -0400 | [diff] [blame] | 18 | import android.testing.AndroidTestingRunner |
| 19 | import com.android.systemui.SysuiTestCase |
| 20 | import com.android.systemui.statusbar.policy.ConfigurationController.ConfigurationListener |
| 21 | import org.junit.Test |
| 22 | import org.junit.runner.RunWith |
| 23 | import org.mockito.Mockito.doAnswer |
| 24 | import org.mockito.Mockito.mock |
| 25 | import org.mockito.Mockito.never |
| 26 | import org.mockito.Mockito.verify |
| 27 | |
| 28 | @RunWith(AndroidTestingRunner::class) |
| 29 | @SmallTest |
| 30 | class 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 | } |