Files
app_Settings/tests/robotests/src/com/android/settings/bluetooth/BluetoothNameDialogFragmentTest.java
jackqdyulei 5b7fc8f3a5 Fix null pointer crash in BT renaming dialog
The dialog may become null after onDestroy has been invoked, so
we need to catch this case.

This CL also moves the listener outside to make it easy to test.

Change-Id: I4ce640c5bdaf1f201f9fecb14b3e5e38e10d4b79
Fixes: 115679393
Test: RunSettingsRoboTests
2018-09-18 14:41:37 -07:00

83 lines
2.3 KiB
Java

/*
* Copyright (C) 2018 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.settings.bluetooth;
import static com.google.common.truth.Truth.assertThat;
import android.view.inputmethod.EditorInfo;
import android.widget.TextView;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.MockitoAnnotations;
import org.robolectric.RuntimeEnvironment;
@RunWith(SettingsRobolectricTestRunner.class)
public class BluetoothNameDialogFragmentTest {
private TestBluetoothNameDialogFragment mBluetoothNameDialogFragment;
private TextView mTextView;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mBluetoothNameDialogFragment = new TestBluetoothNameDialogFragment();
mTextView = new TextView(RuntimeEnvironment.application);
}
@Test
public void onEditorAction_dialogNull_shouldNotCrash() {
mBluetoothNameDialogFragment.mAlertDialog = null;
// Should not crash
assertThat(
mBluetoothNameDialogFragment.onEditorAction(mTextView, EditorInfo.IME_ACTION_DONE,
null)).isTrue();
}
/**
* Test fragment for {@link BluetoothNameDialogFragment} to test common methods
*/
public static class TestBluetoothNameDialogFragment extends BluetoothNameDialogFragment {
@Override
protected int getDialogTitle() {
return 0;
}
@Override
protected String getDeviceName() {
return null;
}
@Override
protected void setDeviceName(String deviceName) {
}
@Override
public int getMetricsCategory() {
return 0;
}
}
}