• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2016 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.settings.bluetooth;
18 
19 import android.content.Context;
20 
21 import com.android.settings.SettingsRobolectricTestRunner;
22 import com.android.settings.TestConfig;
23 import com.android.settings.dashboard.SummaryLoader;
24 import com.android.settingslib.bluetooth.LocalBluetoothManager;
25 
26 import org.junit.Before;
27 import org.junit.Test;
28 import org.junit.runner.RunWith;
29 import org.mockito.Answers;
30 import org.mockito.Mock;
31 import org.mockito.MockitoAnnotations;
32 import org.robolectric.RuntimeEnvironment;
33 import org.robolectric.annotation.Config;
34 
35 import java.util.ArrayList;
36 import java.util.List;
37 
38 import static org.mockito.Mockito.verify;
39 import static org.mockito.Mockito.when;
40 
41 @RunWith(SettingsRobolectricTestRunner.class)
42 @Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
43 public class BluetoothSettingsSummaryProviderTest {
44 
45     private Context mContext;
46     @Mock(answer = Answers.RETURNS_DEEP_STUBS)
47     private LocalBluetoothManager mBluetoothManager;
48     @Mock
49     private SummaryLoader mSummaryLoader;
50 
51     private BluetoothSettings.SummaryProvider mSummaryProvider;
52 
53     @Before
setUp()54     public void setUp() {
55         MockitoAnnotations.initMocks(this);
56         mContext = RuntimeEnvironment.application.getApplicationContext();
57         mSummaryProvider = new BluetoothSettings.SummaryProvider(mContext, mSummaryLoader,
58                 mBluetoothManager);
59     }
60 
61     @Test
setListening_shouldRegister()62     public void setListening_shouldRegister() {
63         mSummaryProvider.setListening(true);
64 
65         verify(mBluetoothManager.getEventManager()).registerCallback(
66             mSummaryProvider.mSummaryUpdater);
67     }
68 
69     @Test
setNotListening_shouldUnregister()70     public void setNotListening_shouldUnregister() {
71         mSummaryProvider.setListening(false);
72 
73         verify(mBluetoothManager.getEventManager()).unregisterCallback(
74             mSummaryProvider.mSummaryUpdater);
75     }
76 
77     @Test
onSummaryChanged_shouldSetSummary()78     public void onSummaryChanged_shouldSetSummary() {
79         final String summary = "Bluetooth summary";
80         mSummaryProvider.onSummaryChanged(summary);
81 
82         verify(mSummaryLoader).setSummary(mSummaryProvider, summary);
83     }
84 
85 }
86