1 /* 2 * Copyright (C) 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 */ 16 17 package com.android.settings.bluetooth; 18 19 import static com.google.common.truth.Truth.assertThat; 20 21 import static org.mockito.Mockito.doReturn; 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.app.AlertDialog; 27 import android.content.Context; 28 import android.view.View; 29 import android.view.inputmethod.InputMethodManager; 30 31 import com.android.settings.R; 32 import com.android.settings.testutils.SettingsRobolectricTestRunner; 33 import com.android.settingslib.bluetooth.LocalBluetoothAdapter; 34 import com.android.settingslib.bluetooth.LocalBluetoothManager; 35 36 import org.junit.Before; 37 import org.junit.Test; 38 import org.junit.runner.RunWith; 39 import org.mockito.Mock; 40 import org.mockito.MockitoAnnotations; 41 import org.robolectric.RuntimeEnvironment; 42 import org.robolectric.shadows.ShadowAlertDialog; 43 import org.robolectric.util.FragmentTestUtil; 44 import org.robolectric.util.ReflectionHelpers; 45 46 @RunWith(SettingsRobolectricTestRunner.class) 47 public class LocalDeviceNameDialogFragmentTest { 48 @Mock 49 private LocalBluetoothManager mManager; 50 @Mock 51 private LocalBluetoothAdapter mAdapter; 52 @Mock 53 private InputMethodManager mInputMethodManager; 54 55 private Context mContext; 56 private LocalDeviceNameDialogFragment mFragment; 57 58 @Before setUp()59 public void setUp() { 60 MockitoAnnotations.initMocks(this); 61 mContext = spy(RuntimeEnvironment.application); 62 doReturn(mInputMethodManager).when(mContext).getSystemService(Context.INPUT_METHOD_SERVICE); 63 ReflectionHelpers.setStaticField(LocalBluetoothManager.class, "sInstance", mManager); 64 when(mManager.getBluetoothAdapter()).thenReturn(mAdapter); 65 66 mFragment = spy(LocalDeviceNameDialogFragment.newInstance()); 67 when(mFragment.getContext()).thenReturn(mContext); 68 } 69 70 @Test diaglogTriggersShowSoftInput()71 public void diaglogTriggersShowSoftInput() { 72 FragmentTestUtil.startFragment(mFragment); 73 AlertDialog dialog = ShadowAlertDialog.getLatestAlertDialog(); 74 assertThat(dialog).isNotNull(); 75 View view = dialog.findViewById(R.id.edittext); 76 verify(mInputMethodManager).showSoftInput(view, InputMethodManager.SHOW_IMPLICIT); 77 } 78 } 79