phweiss | 679dc24 | 2017-07-05 18:54:54 +0200 | [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.statusbar.phone; |
| 16 | |
| 17 | import static junit.framework.Assert.assertTrue; |
Jason Monk | a716bac | 2018-12-05 15:48:21 -0500 | [diff] [blame] | 18 | |
phweiss | 679dc24 | 2017-07-05 18:54:54 +0200 | [diff] [blame] | 19 | import static org.mockito.Matchers.any; |
Satoshi Sanno | 3756b09 | 2019-05-29 16:39:50 +0900 | [diff] [blame] | 20 | import static org.mockito.Matchers.eq; |
phweiss | 679dc24 | 2017-07-05 18:54:54 +0200 | [diff] [blame] | 21 | import static org.mockito.Mockito.verify; |
| 22 | |
Satoshi Sanno | 3756b09 | 2019-05-29 16:39:50 +0900 | [diff] [blame] | 23 | import android.content.BroadcastReceiver; |
phweiss | 679dc24 | 2017-07-05 18:54:54 +0200 | [diff] [blame] | 24 | import android.content.Intent; |
| 25 | import android.content.IntentFilter; |
phweiss | 679dc24 | 2017-07-05 18:54:54 +0200 | [diff] [blame] | 26 | import android.testing.AndroidTestingRunner; |
| 27 | import android.testing.TestableLooper.RunWithLooper; |
| 28 | |
Brett Chabot | 84151d9 | 2019-02-27 15:37:59 -0800 | [diff] [blame] | 29 | import androidx.test.filters.SmallTest; |
| 30 | |
phweiss | 679dc24 | 2017-07-05 18:54:54 +0200 | [diff] [blame] | 31 | import com.android.systemui.SysuiTestCase; |
Fabian Kozynski | ff5e91f | 2019-09-24 15:38:08 -0400 | [diff] [blame] | 32 | import com.android.systemui.broadcast.BroadcastDispatcher; |
phweiss | 679dc24 | 2017-07-05 18:54:54 +0200 | [diff] [blame] | 33 | |
| 34 | import org.junit.Before; |
| 35 | import org.junit.Test; |
| 36 | import org.junit.runner.RunWith; |
| 37 | import org.mockito.ArgumentCaptor; |
Fabian Kozynski | ff5e91f | 2019-09-24 15:38:08 -0400 | [diff] [blame] | 38 | import org.mockito.Mock; |
| 39 | import org.mockito.MockitoAnnotations; |
phweiss | 679dc24 | 2017-07-05 18:54:54 +0200 | [diff] [blame] | 40 | |
phweiss | 679dc24 | 2017-07-05 18:54:54 +0200 | [diff] [blame] | 41 | @RunWith(AndroidTestingRunner.class) |
Jason Monk | a716bac | 2018-12-05 15:48:21 -0500 | [diff] [blame] | 42 | @RunWithLooper |
phweiss | 679dc24 | 2017-07-05 18:54:54 +0200 | [diff] [blame] | 43 | @SmallTest |
| 44 | public class SystemUIDialogTest extends SysuiTestCase { |
| 45 | |
| 46 | private SystemUIDialog mDialog; |
Fabian Kozynski | ff5e91f | 2019-09-24 15:38:08 -0400 | [diff] [blame] | 47 | @Mock |
| 48 | private BroadcastDispatcher mBroadcastDispatcher; |
phweiss | 679dc24 | 2017-07-05 18:54:54 +0200 | [diff] [blame] | 49 | |
| 50 | @Before |
| 51 | public void setup() { |
Fabian Kozynski | ff5e91f | 2019-09-24 15:38:08 -0400 | [diff] [blame] | 52 | MockitoAnnotations.initMocks(this); |
| 53 | |
| 54 | mDependency.injectTestDependency(BroadcastDispatcher.class, mBroadcastDispatcher); |
| 55 | |
| 56 | mDialog = new SystemUIDialog(mContext); |
phweiss | 679dc24 | 2017-07-05 18:54:54 +0200 | [diff] [blame] | 57 | } |
| 58 | |
| 59 | @Test |
| 60 | public void testRegisterReceiver() { |
Satoshi Sanno | 3756b09 | 2019-05-29 16:39:50 +0900 | [diff] [blame] | 61 | final ArgumentCaptor<BroadcastReceiver> broadcastReceiverCaptor = |
| 62 | ArgumentCaptor.forClass(BroadcastReceiver.class); |
phweiss | 679dc24 | 2017-07-05 18:54:54 +0200 | [diff] [blame] | 63 | final ArgumentCaptor<IntentFilter> intentFilterCaptor = |
| 64 | ArgumentCaptor.forClass(IntentFilter.class); |
| 65 | |
Satoshi Sanno | 3756b09 | 2019-05-29 16:39:50 +0900 | [diff] [blame] | 66 | mDialog.show(); |
Fabian Kozynski | ff5e91f | 2019-09-24 15:38:08 -0400 | [diff] [blame] | 67 | verify(mBroadcastDispatcher).registerReceiver(broadcastReceiverCaptor.capture(), |
| 68 | intentFilterCaptor.capture(), eq(null), any()); |
phweiss | 679dc24 | 2017-07-05 18:54:54 +0200 | [diff] [blame] | 69 | |
| 70 | assertTrue(intentFilterCaptor.getValue().hasAction(Intent.ACTION_CLOSE_SYSTEM_DIALOGS)); |
phweiss | 679dc24 | 2017-07-05 18:54:54 +0200 | [diff] [blame] | 71 | |
Satoshi Sanno | 3756b09 | 2019-05-29 16:39:50 +0900 | [diff] [blame] | 72 | mDialog.dismiss(); |
Fabian Kozynski | ff5e91f | 2019-09-24 15:38:08 -0400 | [diff] [blame] | 73 | verify(mBroadcastDispatcher).unregisterReceiver(eq(broadcastReceiverCaptor.getValue())); |
Satoshi Sanno | 3756b09 | 2019-05-29 16:39:50 +0900 | [diff] [blame] | 74 | } |
phweiss | 679dc24 | 2017-07-05 18:54:54 +0200 | [diff] [blame] | 75 | } |