blob: d1e37f6e945b4615c026176b1e6c65366e32baba [file] [log] [blame]
timhypenge745e4a2018-04-08 13:55:08 +08001/*
2 * Copyright 2018 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 */
16package com.android.settingslib.bluetooth;
17
18import static org.mockito.Mockito.verify;
19
20import android.bluetooth.BluetoothHeadset;
21import android.content.Context;
22import android.content.Intent;
23
24import android.telephony.TelephonyManager;
25import org.junit.Before;
26import org.junit.Test;
27import org.junit.runner.RunWith;
28import org.mockito.Mock;
29import org.mockito.MockitoAnnotations;
30import org.robolectric.RobolectricTestRunner;
31import org.robolectric.RuntimeEnvironment;
32
33@RunWith(RobolectricTestRunner.class)
34public class BluetoothEventManagerTest {
35
36 @Mock
37 private LocalBluetoothAdapter mLocalAdapter;
38 @Mock
39 private CachedBluetoothDeviceManager mCachedDeviceManager;
40 @Mock
41 private BluetoothCallback mBluetoothCallback;
42
43 private Context mContext;
44 private Intent mIntent;
45 private BluetoothEventManager mBluetoothEventManager;
46
47 @Before
48 public void setUp() {
49 MockitoAnnotations.initMocks(this);
50 mContext = RuntimeEnvironment.application;
51
52 mBluetoothEventManager = new BluetoothEventManager(mLocalAdapter,
53 mCachedDeviceManager, mContext);
54 }
55
56 /**
57 * Intent ACTION_AUDIO_STATE_CHANGED should dispatch to callback.
58 */
59 @Test
60 public void intentWithExtraState_audioStateChangedShouldDispatchToRegisterCallback() {
61 mBluetoothEventManager.registerCallback(mBluetoothCallback);
62 mIntent = new Intent(BluetoothHeadset.ACTION_AUDIO_STATE_CHANGED);
63
64 mContext.sendBroadcast(mIntent);
65
66 verify(mBluetoothCallback).onAudioModeChanged();
67 }
68
69 /**
70 * Intent ACTION_PHONE_STATE_CHANGED should dispatch to callback.
71 */
72 @Test
73 public void intentWithExtraState_phoneStateChangedShouldDispatchToRegisterCallback() {
74 mBluetoothEventManager.registerCallback(mBluetoothCallback);
75 mIntent = new Intent(TelephonyManager.ACTION_PHONE_STATE_CHANGED);
76
77 mContext.sendBroadcast(mIntent);
78
79 verify(mBluetoothCallback).onAudioModeChanged();
80 }
81}