Merge "Remove the obsolete bluetooth code" into pi-dev am: fa150fca3c

am: a5a338dff6

Change-Id: Icbc382b54b4bfe329aa8f2045433885997badf05
This commit is contained in:
Lei Yu
2018-03-31 03:35:30 +00:00
committed by android-build-merger
12 changed files with 13 additions and 968 deletions

View File

@@ -1,118 +0,0 @@
/*
* Copyright (C) 2017 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 static org.mockito.Matchers.any;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import android.content.Context;
import android.support.v7.preference.Preference.OnPreferenceChangeListener;
import android.support.v7.preference.PreferenceScreen;
import com.android.settings.core.InstrumentedPreferenceFragment;
import com.android.settings.testutils.FakeFeatureFactory;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settings.widget.MasterSwitchPreference;
import com.android.settingslib.bluetooth.BluetoothCallback;
import com.android.settingslib.bluetooth.LocalBluetoothManager;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Answers;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RuntimeEnvironment;
@RunWith(SettingsRobolectricTestRunner.class)
public class BluetoothMasterSwitchPreferenceControllerTest {
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
private LocalBluetoothManager mBluetoothManager;
@Mock
private PreferenceScreen mScreen;
@Mock
private MasterSwitchPreference mPreference;
@Mock
private RestrictionUtils mRestrictionUtils;
@Mock
private InstrumentedPreferenceFragment mFragment;
private Context mContext;
private BluetoothMasterSwitchPreferenceController mController;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mContext = spy(RuntimeEnvironment.application.getApplicationContext());
FakeFeatureFactory.setupForTest();
mController = new BluetoothMasterSwitchPreferenceController(
mContext, mBluetoothManager, mRestrictionUtils, mFragment);
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference);
when(mPreference.getKey()).thenReturn(mController.getPreferenceKey());
}
@Test
public void isAvailable_shouldAlwaysReturnTrue() {
assertThat(mController.isAvailable()).isTrue();
}
@Test
public void onResume_shouldRegisterCallback() {
mController.onResume();
verify(mBluetoothManager.getEventManager()).registerCallback(any(BluetoothCallback.class));
}
@Test
public void onPause_shouldUnregisterCallback() {
mController.onPause();
verify(mBluetoothManager.getEventManager())
.unregisterCallback(any(BluetoothCallback.class));
}
@Test
public void onStart_shouldRegisterPreferenceChangeListener() {
mController.displayPreference(mScreen);
mController.onStart();
verify(mPreference).setOnPreferenceChangeListener(any(OnPreferenceChangeListener.class));
}
@Test
public void onStop_shouldRegisterPreferenceChangeListener() {
mController.displayPreference(mScreen);
mController.onStart();
mController.onStop();
verify(mPreference).setOnPreferenceChangeListener(null);
}
@Test
public void onSummaryUpdated_shouldUpdatePreferenceSummary() {
mController.displayPreference(mScreen);
mController.onSummaryChanged("test summary");
verify(mPreference).setSummary("test summary");
}
}

View File

@@ -1,77 +0,0 @@
/*
* Copyright (C) 2016 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 org.mockito.Mockito.verify;
import android.content.Context;
import com.android.settings.dashboard.SummaryLoader;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settingslib.bluetooth.LocalBluetoothManager;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Answers;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RuntimeEnvironment;
@RunWith(SettingsRobolectricTestRunner.class)
public class BluetoothSettingsSummaryProviderTest {
private Context mContext;
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
private LocalBluetoothManager mBluetoothManager;
@Mock
private SummaryLoader mSummaryLoader;
private BluetoothSettings.SummaryProvider mSummaryProvider;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mContext = RuntimeEnvironment.application.getApplicationContext();
mSummaryProvider =
new BluetoothSettings.SummaryProvider(mContext, mSummaryLoader, mBluetoothManager);
}
@Test
public void setListening_shouldRegister() {
mSummaryProvider.setListening(true);
verify(mBluetoothManager.getEventManager()).registerCallback(
mSummaryProvider.mSummaryUpdater);
}
@Test
public void setNotListening_shouldUnregister() {
mSummaryProvider.setListening(false);
verify(mBluetoothManager.getEventManager()).unregisterCallback(
mSummaryProvider.mSummaryUpdater);
}
@Test
public void onSummaryChanged_shouldSetSummary() {
final String summary = "Bluetooth summary";
mSummaryProvider.onSummaryChanged(summary);
verify(mSummaryLoader).setSummary(mSummaryProvider, summary);
}
}

View File

@@ -1,155 +0,0 @@
/*
* Copyright (C) 2017 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 static org.mockito.Matchers.any;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.spy;
import android.app.Activity;
import android.content.Context;
import android.content.res.Resources;
import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceGroup;
import android.view.View;
import android.widget.TextView;
import com.android.settings.R;
import com.android.settings.testutils.FakeFeatureFactory;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settingslib.bluetooth.LocalBluetoothAdapter;
import com.android.settingslib.widget.FooterPreference;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RuntimeEnvironment;
import java.util.List;
@RunWith(SettingsRobolectricTestRunner.class)
public class BluetoothSettingsTest {
private static final String FOOTAGE_MAC_STRING = "Bluetooth mac: xxxx";
@Mock
private Resources mResource;
@Mock
private LocalBluetoothAdapter mLocalAdapter;
@Mock
private Activity mActivity;
@Mock
private PreferenceGroup mPairedDevicesCategory;
@Mock
private BluetoothPairingPreferenceController mPairingPreferenceController;
private Context mContext;
private BluetoothSettings mFragment;
private FakeFeatureFactory mFeatureFactory;
private Preference mFooterPreference;
private TextView mEmptyMessage;
private View mContainer;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mContext = spy(RuntimeEnvironment.application);
mFeatureFactory = FakeFeatureFactory.setupForTest();
mFragment = spy(new BluetoothSettings());
doReturn(mContext).when(mFragment).getContext();
doReturn(mResource).when(mFragment).getResources();
doReturn(mActivity).when(mFragment).getActivity();
mContainer = new View(mContext);
mEmptyMessage = new TextView(mContext);
doReturn(mContainer).when(mActivity).findViewById(android.R.id.list_container);
doReturn(mEmptyMessage).when(mActivity).findViewById(android.R.id.empty);
mFooterPreference = new FooterPreference(RuntimeEnvironment.application);
mFragment.setLocalBluetoothAdapter(mLocalAdapter);
mFragment.mPairingPrefController = mPairingPreferenceController;
}
@Test
public void setTextSpan_notSpannable_shouldNotCrash() {
final String str = "test";
mFragment.setTextSpan(str, "hello");
}
@Test
public void setUpdateMyDevicePreference_setTitleCorrectly() {
doReturn(FOOTAGE_MAC_STRING).when(mFragment)
.getString(eq(R.string.bluetooth_footer_mac_message), any());
mFragment.updateFooterPreference(mFooterPreference);
assertThat(mFooterPreference.getTitle()).isEqualTo(FOOTAGE_MAC_STRING);
}
@Test
public void testDisplayEmptyMessage_showEmptyMessage() {
mFragment.displayEmptyMessage(true);
assertThat(mContainer.getVisibility()).isEqualTo(View.INVISIBLE);
assertThat(mEmptyMessage.getVisibility()).isEqualTo(View.VISIBLE);
}
@Test
public void testDisplayEmptyMessage_hideEmptyMessage() {
mFragment.displayEmptyMessage(false);
assertThat(mContainer.getVisibility()).isEqualTo(View.VISIBLE);
assertThat(mEmptyMessage.getVisibility()).isEqualTo(View.GONE);
}
@Test
public void testInitPreferencesFromPreferenceScreen() {
doReturn(mPairedDevicesCategory).when(mFragment)
.findPreference(BluetoothSettings.KEY_PAIRED_DEVICES);
doReturn(mFooterPreference).when(mFragment)
.findPreference(BluetoothSettings.KEY_FOOTER_PREF);
mFragment.initPreferencesFromPreferenceScreen();
assertThat(mFragment.mPairedDevicesCategory).isEqualTo(mPairedDevicesCategory);
assertThat(mFragment.mFooterPreference).isEqualTo(mFooterPreference);
}
@Test
public void testSearchIndexProvider_pairPageEnabled_keyNotAdded() {
doReturn(true).when(mFeatureFactory.bluetoothFeatureProvider).isPairingPageEnabled();
final List<String> keys =
BluetoothSettings.SEARCH_INDEX_DATA_PROVIDER.getNonIndexableKeys(mContext);
assertThat(keys).doesNotContain(BluetoothSettings.DATA_KEY_REFERENCE);
}
@Test
public void testSearchIndexProvider_pairPageDisabled_keyAdded() {
final List<String> keys =
BluetoothSettings.SEARCH_INDEX_DATA_PROVIDER.getNonIndexableKeys(mContext);
assertThat(keys).contains(BluetoothSettings.DATA_KEY_REFERENCE);
}
}