• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2017 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 static com.google.common.truth.Truth.assertThat;
20 import static org.mockito.Matchers.any;
21 import static org.mockito.Mockito.doNothing;
22 import static org.mockito.Mockito.spy;
23 import static org.mockito.Mockito.verify;
24 import static org.mockito.Mockito.when;
25 
26 import android.content.Context;
27 import android.content.Intent;
28 import android.support.v7.preference.Preference;
29 
30 import com.android.settings.R;
31 import com.android.settings.dashboard.DashboardFragment;
32 import com.android.settings.testutils.SettingsRobolectricTestRunner;
33 
34 import org.junit.Before;
35 import org.junit.Test;
36 import org.junit.runner.RunWith;
37 import org.mockito.Answers;
38 import org.mockito.Mock;
39 import org.mockito.MockitoAnnotations;
40 import org.robolectric.RuntimeEnvironment;
41 
42 @RunWith(SettingsRobolectricTestRunner.class)
43 public class BluetoothPairingPreferenceControllerTest {
44 
45     private static final int ORDER = 1;
46 
47     @Mock(answer = Answers.RETURNS_DEEP_STUBS)
48     private DashboardFragment mFragment;
49 
50     private Context mContext;
51     private Preference mPreference;
52 
53     private BluetoothPairingPreferenceController mController;
54 
55     @Before
setUp()56     public void setUp() {
57         MockitoAnnotations.initMocks(this);
58 
59         mContext = spy(RuntimeEnvironment.application);
60         when(mFragment.getPreferenceScreen().getContext()).thenReturn(mContext);
61 
62         mPreference = new Preference(mContext);
63         mPreference.setKey(BluetoothPairingPreferenceController.KEY_PAIRING);
64 
65         mController = new BluetoothPairingPreferenceController(mContext, mFragment);
66     }
67 
68     @Test
testCreateBluetoothPairingPreference()69     public void testCreateBluetoothPairingPreference() {
70         Preference pref = mController.createBluetoothPairingPreference(ORDER);
71 
72         assertThat(pref.getKey()).isEqualTo(BluetoothPairingPreferenceController.KEY_PAIRING);
73         assertThat(pref.getIcon()).isEqualTo(mContext.getDrawable(R.drawable.ic_menu_add));
74         assertThat(pref.getOrder()).isEqualTo(ORDER);
75         assertThat(pref.getTitle())
76             .isEqualTo(mContext.getString(R.string.bluetooth_pairing_pref_title));
77     }
78 
79     @Test
testHandlePreferenceTreeClick_startFragment()80     public void testHandlePreferenceTreeClick_startFragment() {
81         doNothing().when(mContext).startActivity(any(Intent.class));
82 
83         mController.handlePreferenceTreeClick(mPreference);
84 
85         verify(mContext).startActivity(any(Intent.class));
86     }
87 }
88