Merge "[Wi-Fi] Enhance Wifi Settings unit test cases." into rvc-dev

This commit is contained in:
TreeHugger Robot
2020-05-07 07:11:32 +00:00
committed by Android (Google) Code Review
7 changed files with 504 additions and 19 deletions

View File

@@ -22,6 +22,7 @@ import android.net.wifi.p2p.WifiP2pDevice;
import android.text.TextUtils;
import android.widget.ImageView;
import androidx.annotation.VisibleForTesting;
import androidx.preference.Preference;
import androidx.preference.PreferenceViewHolder;
@@ -29,19 +30,21 @@ import com.android.settings.R;
public class WifiP2pPeer extends Preference {
private static final int FIXED_RSSI = 60;
private static final int[] STATE_SECURED = {R.attr.state_encrypted};
public WifiP2pDevice device;
private final int mRssi;
@VisibleForTesting final int mRssi;
private ImageView mSignal;
private static final int SIGNAL_LEVELS = 4;
@VisibleForTesting
static final int SIGNAL_LEVELS = 4;
public WifiP2pPeer(Context context, WifiP2pDevice dev) {
super(context);
device = dev;
setWidgetLayoutResource(R.layout.preference_widget_wifi_signal);
mRssi = 60; //TODO: fix
mRssi = FIXED_RSSI; //TODO: fix
if (TextUtils.isEmpty(device.deviceName)) {
setTitle(device.deviceAddress);
} else {

View File

@@ -52,7 +52,8 @@ public class WifiP2pPreferenceController extends AbstractPreferenceController
};
private final IntentFilter mFilter = new IntentFilter(WifiManager.WIFI_STATE_CHANGED_ACTION);
private final LocationManager mLocationManager;
private final BroadcastReceiver mLocationReceiver = new BroadcastReceiver() {
@VisibleForTesting
final BroadcastReceiver mLocationReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
if (mWifiDirectPref != null) {

View File

@@ -91,16 +91,16 @@ public class WifiP2pSettings extends DashboardFragment
@VisibleForTesting boolean mLastGroupFormed = false;
private boolean mIsIgnoreInitConnectionInfoCallback = false;
private P2pPeerCategoryPreferenceController mPeerCategoryController;
private P2pPersistentCategoryPreferenceController mPersistentCategoryController;
private P2pThisDevicePreferenceController mThisDevicePreferenceController;
@VisibleForTesting P2pPeerCategoryPreferenceController mPeerCategoryController;
@VisibleForTesting P2pPersistentCategoryPreferenceController mPersistentCategoryController;
@VisibleForTesting P2pThisDevicePreferenceController mThisDevicePreferenceController;
@VisibleForTesting static final int DIALOG_DISCONNECT = 1;
@VisibleForTesting static final int DIALOG_CANCEL_CONNECT = 2;
@VisibleForTesting static final int DIALOG_RENAME = 3;
@VisibleForTesting static final int DIALOG_DELETE_GROUP = 4;
private static final String SAVE_DIALOG_PEER = "PEER_STATE";
@VisibleForTesting static final String SAVE_DIALOG_PEER = "PEER_STATE";
@VisibleForTesting static final String SAVE_DEVICE_NAME = "DEV_NAME";
@VisibleForTesting static final String SAVE_SELECTED_GROUP = "GROUP_NAME";

View File

@@ -83,6 +83,12 @@ public class WifiConfigController2Test {
// Valid PSK pass phrase
private static final String GOOD_PSK = "abcdefghijklmnopqrstuvwxyz";
private static final String GOOD_SSID = "abc";
private static final String VALID_HEX_PSK =
"123456789012345678901234567890123456789012345678901234567890abcd";
private static final String INVALID_HEX_PSK =
"123456789012345678901234567890123456789012345678901234567890ghij";
private static final String NUMBER_AND_CHARACTER_KEY = "123456abcd";
private static final String PARTIAL_NUMBER_AND_CHARACTER_KEY = "123456abc?";
private static final int DHCP = 0;
@Before
@@ -518,16 +524,7 @@ public class WifiConfigController2Test {
@Test
public void selectEapMethod_savedWifiEntry_shouldGetCorrectPosition() {
when(mWifiEntry.isSaved()).thenReturn(true);
when(mWifiEntry.getSecurity()).thenReturn(WifiEntry.SECURITY_EAP);
final WifiConfiguration mockWifiConfig = mock(WifiConfiguration.class);
when(mockWifiConfig.getIpConfiguration()).thenReturn(mock(IpConfiguration.class));
final WifiEnterpriseConfig mockWifiEnterpriseConfig = mock(WifiEnterpriseConfig.class);
when(mockWifiEnterpriseConfig.getEapMethod()).thenReturn(Eap.PEAP);
mockWifiConfig.enterpriseConfig = mockWifiEnterpriseConfig;
when(mWifiEntry.getWifiConfiguration()).thenReturn(mockWifiConfig);
mController = new TestWifiConfigController2(mConfigUiBase, mView, mWifiEntry,
WifiConfigUiBase2.MODE_MODIFY);
setUpModifyingSavedPeapConfigController();
final Spinner eapMethodSpinner = mView.findViewById(R.id.method);
final Spinner phase2Spinner = mView.findViewById(R.id.phase2);
WifiConfiguration wifiConfiguration;
@@ -568,4 +565,199 @@ public class WifiConfigController2Test {
assertThat(advButton.getContentDescription()).isEqualTo(
mContext.getString(R.string.wifi_advanced_toggle_description));
}
@Test
public void getWepConfig_withNumberAndCharacterKey_shouldContainTheSameKey() {
final TextView password = mView.findViewById(R.id.password);
password.setText(NUMBER_AND_CHARACTER_KEY);
mController.mWifiEntrySecurity = WifiEntry.SECURITY_WEP;
WifiConfiguration wifiConfiguration = mController.getConfig();
assertThat(wifiConfiguration.wepKeys[0]).isEqualTo(NUMBER_AND_CHARACTER_KEY);
}
@Test
public void getWepConfig_withPartialNumberAndCharacterKey_shouldContainDifferentKey() {
final TextView password = mView.findViewById(R.id.password);
password.setText(PARTIAL_NUMBER_AND_CHARACTER_KEY);
mController.mWifiEntrySecurity = WifiEntry.SECURITY_WEP;
WifiConfiguration wifiConfiguration = mController.getConfig();
assertThat(wifiConfiguration.wepKeys[0]).isNotEqualTo(PARTIAL_NUMBER_AND_CHARACTER_KEY);
}
@Test
public void getPskConfig_withValidHexKey_shouldContainTheSameKey() {
final TextView password = mView.findViewById(R.id.password);
password.setText(VALID_HEX_PSK);
mController.mWifiEntrySecurity = WifiEntry.SECURITY_PSK;
WifiConfiguration wifiConfiguration = mController.getConfig();
assertThat(wifiConfiguration.preSharedKey).isEqualTo(VALID_HEX_PSK);
}
@Test
public void getPskConfig_withInvalidHexKey_shouldContainDifferentKey() {
final TextView password = mView.findViewById(R.id.password);
password.setText(INVALID_HEX_PSK);
mController.mWifiEntrySecurity = WifiEntry.SECURITY_PSK;
WifiConfiguration wifiConfiguration = mController.getConfig();
assertThat(wifiConfiguration.preSharedKey).isNotEqualTo(INVALID_HEX_PSK);
}
@Test
public void getEapConfig_withPhase2Gtc_shouldContainGtcMethod() {
setUpModifyingSavedPeapConfigController();
// Test EAP method PEAP
final Spinner eapMethodSpinner = mView.findViewById(R.id.method);
eapMethodSpinner.setSelection(Eap.PEAP);
// Test phase2 GTC
final Spinner phase2Spinner = mView.findViewById(R.id.phase2);
phase2Spinner.setSelection(WifiConfigController2.WIFI_PEAP_PHASE2_GTC);
WifiConfiguration wifiConfiguration = mController.getConfig();
assertThat(wifiConfiguration.enterpriseConfig.getPhase2Method()).isEqualTo(Phase2.GTC);
}
@Test
public void getEapConfig_withPhase2Sim_shouldContainSimMethod() {
setUpModifyingSavedPeapConfigController();
// Test EAP method PEAP
final Spinner eapMethodSpinner = mView.findViewById(R.id.method);
eapMethodSpinner.setSelection(Eap.PEAP);
// Test phase2 SIM
final Spinner phase2Spinner = mView.findViewById(R.id.phase2);
phase2Spinner.setSelection(WifiConfigController2.WIFI_PEAP_PHASE2_SIM);
WifiConfiguration wifiConfiguration = mController.getConfig();
assertThat(wifiConfiguration.enterpriseConfig.getPhase2Method()).isEqualTo(Phase2.SIM);
}
@Test
public void getEapConfig_withPhase2Aka_shouldContainAkaMethod() {
setUpModifyingSavedPeapConfigController();
// Test EAP method PEAP
final Spinner eapMethodSpinner = mView.findViewById(R.id.method);
eapMethodSpinner.setSelection(Eap.PEAP);
// Test phase2 AKA
final Spinner phase2Spinner = mView.findViewById(R.id.phase2);
phase2Spinner.setSelection(WifiConfigController2.WIFI_PEAP_PHASE2_AKA);
WifiConfiguration wifiConfiguration = mController.getConfig();
assertThat(wifiConfiguration.enterpriseConfig.getPhase2Method()).isEqualTo(Phase2.AKA);
}
@Test
public void getEapConfig_withPhase2AkaPrime_shouldContainAkaPrimeMethod() {
setUpModifyingSavedPeapConfigController();
// Test EAP method PEAP
final Spinner eapMethodSpinner = mView.findViewById(R.id.method);
eapMethodSpinner.setSelection(Eap.PEAP);
// Test phase2 AKA PRIME
final Spinner phase2Spinner = mView.findViewById(R.id.phase2);
phase2Spinner.setSelection(WifiConfigController2.WIFI_PEAP_PHASE2_AKA_PRIME);
WifiConfiguration wifiConfiguration = mController.getConfig();
assertThat(wifiConfiguration.enterpriseConfig.getPhase2Method()).isEqualTo(
Phase2.AKA_PRIME);
}
@Test
public void getEapConfig_withPeapPhase2Unknown_shouldContainNoneMethod() {
setUpModifyingSavedPeapConfigController();
// Test EAP method PEAP
final Spinner eapMethodSpinner = mView.findViewById(R.id.method);
eapMethodSpinner.setSelection(Eap.PEAP);
// Test phase2 Unknown
final Spinner phase2Spinner = mView.findViewById(R.id.phase2);
phase2Spinner.setSelection(-1);
WifiConfiguration wifiConfiguration = mController.getConfig();
assertThat(wifiConfiguration.enterpriseConfig.getPhase2Method()).isEqualTo(Phase2.NONE);
}
@Test
public void getEapConfig_withTTLSPhase2Pap_shouldContainPapMethod() {
setUpModifyingSavedPeapConfigController();
// Test EAP method TTLS
final Spinner eapMethodSpinner = mView.findViewById(R.id.method);
eapMethodSpinner.setSelection(Eap.TTLS);
// Test phase2 PAP
final Spinner phase2Spinner = mView.findViewById(R.id.phase2);
phase2Spinner.setSelection(WifiConfigController2.WIFI_TTLS_PHASE2_PAP);
WifiConfiguration wifiConfiguration = mController.getConfig();
assertThat(wifiConfiguration.enterpriseConfig.getPhase2Method()).isEqualTo(Phase2.PAP);
}
@Test
public void getEapConfig_withTTLSPhase2Mschap_shouldContainMschapMethod() {
setUpModifyingSavedPeapConfigController();
// Test EAP method TTLS
final Spinner eapMethodSpinner = mView.findViewById(R.id.method);
eapMethodSpinner.setSelection(Eap.TTLS);
// Test phase2 MSCHAP
final Spinner phase2Spinner = mView.findViewById(R.id.phase2);
phase2Spinner.setSelection(WifiConfigController2.WIFI_TTLS_PHASE2_MSCHAP);
WifiConfiguration wifiConfiguration = mController.getConfig();
assertThat(wifiConfiguration.enterpriseConfig.getPhase2Method()).isEqualTo(Phase2.MSCHAP);
}
@Test
public void getEapConfig_withTTLSPhase2Gtc_shouldContainGtcMethod() {
setUpModifyingSavedPeapConfigController();
// Test EAP method TTLS
final Spinner eapMethodSpinner = mView.findViewById(R.id.method);
eapMethodSpinner.setSelection(Eap.TTLS);
// Test phase2 GTC
final Spinner phase2Spinner = mView.findViewById(R.id.phase2);
phase2Spinner.setSelection(WifiConfigController2.WIFI_TTLS_PHASE2_GTC);
WifiConfiguration wifiConfiguration = mController.getConfig();
assertThat(wifiConfiguration.enterpriseConfig.getPhase2Method()).isEqualTo(Phase2.GTC);
}
private void setUpModifyingSavedPeapConfigController() {
when(mWifiEntry.isSaved()).thenReturn(true);
when(mWifiEntry.getSecurity()).thenReturn(WifiEntry.SECURITY_EAP);
final WifiConfiguration mockWifiConfig = mock(WifiConfiguration.class);
when(mockWifiConfig.getIpConfiguration()).thenReturn(mock(IpConfiguration.class));
final WifiEnterpriseConfig mockWifiEnterpriseConfig = mock(WifiEnterpriseConfig.class);
when(mockWifiEnterpriseConfig.getEapMethod()).thenReturn(Eap.PEAP);
mockWifiConfig.enterpriseConfig = mockWifiEnterpriseConfig;
when(mWifiEntry.getWifiConfiguration()).thenReturn(mockWifiConfig);
mController = new TestWifiConfigController2(mConfigUiBase, mView, mWifiEntry,
WifiConfigUiBase2.MODE_MODIFY);
}
}

View File

@@ -39,7 +39,6 @@ import androidx.lifecycle.LifecycleOwner;
import androidx.preference.Preference;
import androidx.preference.PreferenceScreen;
import com.android.settings.dashboard.DashboardFragment;
import com.android.settingslib.core.lifecycle.Lifecycle;
import org.junit.Before;
@@ -132,4 +131,17 @@ public class WifiP2PPreferenceControllerTest {
mController.displayPreference(mScreen);
verify(mWifiDirectPreference, times(2)).setEnabled(false);
}
@Test
public void updateState_withLocationDisabled_preferenceShouldBeDisable() {
when(mWifiManager.isWifiEnabled()).thenReturn(true);
when(mLocationManager.isLocationEnabled()).thenReturn(true);
Intent dummyIntent = new Intent();
mController.displayPreference(mScreen);
verify(mWifiDirectPreference).setEnabled(true);
when(mLocationManager.isLocationEnabled()).thenReturn(false);
mController.mLocationReceiver.onReceive(mContext, dummyIntent);
verify(mWifiDirectPreference).setEnabled(false);
}
}

View File

@@ -0,0 +1,120 @@
/*
* Copyright (C) 2020 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.wifi.p2p;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.mock;
import android.content.Context;
import android.net.wifi.WifiManager;
import android.net.wifi.p2p.WifiP2pDevice;
import androidx.preference.Preference;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
@RunWith(RobolectricTestRunner.class)
public class WifiP2pPeerTest {
private static final String DEVICE_NAME = "fakeName";
private static final String OTHER_NAME = "otherName";
private static final String MAC_ADDRESS = "00:11:22:33:44:55";
private Context mContext;
private WifiP2pPeer mPreference;
@Mock
private WifiP2pDevice mWifiP2pDevice;
@Mock
private WifiP2pPeer mOtherWifiP2pPeer;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mContext = RuntimeEnvironment.application;
}
@Test
public void compareTo_withSameDeviceName_shouldBeZero() {
setupOneOtherP2pPeer(DEVICE_NAME, null /* address */);
mWifiP2pDevice.deviceName = DEVICE_NAME;
mPreference = new WifiP2pPeer(mContext, mWifiP2pDevice);
assertThat(mPreference.compareTo(mOtherWifiP2pPeer)).isEqualTo(0);
}
@Test
public void compareTo_withDifferentDeviceName_shouldNotZero() {
setupOneOtherP2pPeer(DEVICE_NAME, null /* address */);
mWifiP2pDevice.deviceName = OTHER_NAME;
mPreference = new WifiP2pPeer(mContext, mWifiP2pDevice);
assertThat(mPreference.compareTo(mOtherWifiP2pPeer)).isNotEqualTo(0);
}
@Test
public void compareTo_withSameDeviceAddress_shouldBeZero() {
setupOneOtherP2pPeer(null /* name */, MAC_ADDRESS);
mWifiP2pDevice.deviceAddress = MAC_ADDRESS;
mPreference = new WifiP2pPeer(mContext, mWifiP2pDevice);
assertThat(mPreference.compareTo(mOtherWifiP2pPeer)).isEqualTo(0);
}
@Test
public void compareTo_withLowerDeviceStatus_shouldBeOne() {
setupOneOtherP2pPeer(DEVICE_NAME, null /* address */);
mWifiP2pDevice.status = WifiP2pDevice.FAILED;
mPreference = new WifiP2pPeer(mContext, mWifiP2pDevice);
assertThat(mPreference.compareTo(mOtherWifiP2pPeer)).isEqualTo(1);
}
@Test
public void compareTo_withNotPeerParameter_shouldBeOne() {
final Preference fakePreference = mock(Preference.class);
setupOneOtherP2pPeer(DEVICE_NAME, null /* address */);
mPreference = new WifiP2pPeer(mContext, mWifiP2pDevice);
assertThat(mPreference.compareTo(fakePreference)).isEqualTo(1);
}
@Test
public void signalLevel_afterNewPreference_shouldBeExpected() {
mPreference = new WifiP2pPeer(mContext, mWifiP2pDevice);
final int expectSignalLevel = WifiManager.calculateSignalLevel(mPreference.mRssi,
WifiP2pPeer.SIGNAL_LEVELS);
assertThat(mPreference.getLevel()).isEqualTo(expectSignalLevel);
}
private void setupOneOtherP2pPeer(String name, String address) {
final WifiP2pDevice wifiP2pDevice = mock(WifiP2pDevice.class);
wifiP2pDevice.status = WifiP2pDevice.CONNECTED;
wifiP2pDevice.deviceAddress = address;
wifiP2pDevice.deviceName = name;
mOtherWifiP2pPeer.device = wifiP2pDevice;
}
}

View File

@@ -21,6 +21,7 @@ import static com.google.common.truth.Truth.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
@@ -33,6 +34,7 @@ import android.net.NetworkInfo;
import android.net.wifi.p2p.WifiP2pDevice;
import android.net.wifi.p2p.WifiP2pDeviceList;
import android.net.wifi.p2p.WifiP2pGroup;
import android.net.wifi.p2p.WifiP2pGroupList;
import android.net.wifi.p2p.WifiP2pInfo;
import android.net.wifi.p2p.WifiP2pManager;
import android.os.Bundle;
@@ -360,6 +362,161 @@ public class WifiP2pSettingsTest {
assertThat(mFragment.getDialogMetricsCategory(-1 /* dialogId */)).isEqualTo(0);
}
@Test
public void onSaveInstanceState_withWiFiPeer_shouldGetP2pDeviceType() {
setupOneP2pPeer(WifiP2pDevice.CONNECTED);
mFragment.onPreferenceTreeClick(mWifiP2pPeer);
final Bundle outBundle = new Bundle();
mFragment.onSaveInstanceState(outBundle);
final Object object = outBundle.getParcelable(WifiP2pSettings.SAVE_DIALOG_PEER);
assertThat(object instanceof WifiP2pDevice).isTrue();
}
@Test
public void onSaveInstanceState_withDeviceNameText_shouldSaveName() {
final String fakeDeviceName = "fakeName";
final Bundle createBundle = new Bundle();
createBundle.putString(WifiP2pSettings.SAVE_DEVICE_NAME, fakeDeviceName);
mFragment.onActivityCreated(createBundle);
final Bundle outBundle = new Bundle();
final Dialog dialog = mFragment.onCreateDialog(WifiP2pSettings.DIALOG_RENAME);
mFragment.onSaveInstanceState(outBundle);
final String string = outBundle.getString(WifiP2pSettings.SAVE_DEVICE_NAME);
assertThat(string).isEqualTo(fakeDeviceName);
}
@Test
public void onSaveInstanceState_withSelectedGroup_shouldSaveGroupName() {
final String fakeGroupName = "fakeGroupName";
final WifiP2pPersistentGroup wifiP2pPersistentGroup = spy(
new WifiP2pPersistentGroup(mContext,
mWifiP2pGroup));
doReturn(fakeGroupName).when(wifiP2pPersistentGroup).getGroupName();
mFragment.mSelectedGroup = wifiP2pPersistentGroup;
final Bundle outBundle = new Bundle();
mFragment.onSaveInstanceState(outBundle);
assertThat(outBundle.getString(WifiP2pSettings.SAVE_SELECTED_GROUP)).isEqualTo(
fakeGroupName);
}
@Test
public void persistentController_withOneGroup_shouldBeAvailable() {
final String fakeGroupName = new String("fakeGroupName");
doReturn(fakeGroupName).when(mWifiP2pGroup).getNetworkName();
final List<WifiP2pGroup> groupList = new ArrayList<>();
groupList.add(mWifiP2pGroup);
final WifiP2pGroupList wifiP2pGroupList = mock(WifiP2pGroupList.class);
doReturn(groupList).when(wifiP2pGroupList).getGroupList();
final Bundle bundle = new Bundle();
bundle.putString(WifiP2pSettings.SAVE_SELECTED_GROUP, fakeGroupName);
mFragment.onActivityCreated(bundle);
mFragment.onPersistentGroupInfoAvailable(wifiP2pGroupList);
assertThat(mFragment.mPersistentCategoryController.isAvailable()).isTrue();
}
@Test
public void persistentController_withNoGroup_shouldBeUnavailable() {
final WifiP2pGroupList wifiP2pGroupList = mock(WifiP2pGroupList.class);
final List<WifiP2pGroup> groupList = new ArrayList<>();
doReturn(groupList).when(wifiP2pGroupList).getGroupList();
mFragment.onPersistentGroupInfoAvailable(wifiP2pGroupList);
assertThat(mFragment.mPersistentCategoryController.isAvailable()).isFalse();
}
@Test
public void peersCategoryController_withOnePeerDevice_shouldBeAvailable() {
final WifiP2pDevice wifiP2pDevice = mock(WifiP2pDevice.class);
final ArrayList<WifiP2pDevice> deviceList = new ArrayList<>();
deviceList.add(wifiP2pDevice);
final WifiP2pDeviceList peers = mock(WifiP2pDeviceList.class);
doReturn(deviceList).when(peers).getDeviceList();
mFragment.onPeersAvailable(peers);
assertThat(mFragment.mPeerCategoryController.isAvailable()).isTrue();
}
@Test
public void peersCategoryController_withNoPeerDevice_shouldBeUnavailable() {
final ArrayList<WifiP2pDevice> deviceList = new ArrayList<>();
final WifiP2pDeviceList peers = mock(WifiP2pDeviceList.class);
doReturn(deviceList).when(peers).getDeviceList();
mFragment.onPeersAvailable(peers);
assertThat(mFragment.mPeerCategoryController.isAvailable()).isFalse();
}
@Test
public void thisDeviceController_onDeviceInfoAvailable_shouldUpdateDeviceName() {
final WifiP2pDevice wifiP2pDevice = mock(WifiP2pDevice.class);
final P2pThisDevicePreferenceController thisDevicePreferenceController = mock(
P2pThisDevicePreferenceController.class);
mFragment.mThisDevicePreferenceController = thisDevicePreferenceController;
mFragment.onDeviceInfoAvailable(wifiP2pDevice);
verify(thisDevicePreferenceController, times(1)).updateDeviceName(any());
}
@Test
public void p2pThisDeviceChange_shouldRequestDeviceInfoAgain() {
final Intent intent = new Intent(WifiP2pManager.WIFI_P2P_THIS_DEVICE_CHANGED_ACTION);
mFragment.mReceiver.onReceive(mContext, intent);
verify(mWifiP2pManager, times(2)).requestDeviceInfo(any(), any());
}
@Test
public void p2pPersistentGroupChange_shouldRequestGroupInfo() {
final Intent intent = new Intent(WifiP2pManager.ACTION_WIFI_P2P_PERSISTENT_GROUPS_CHANGED);
mFragment.mReceiver.onReceive(mContext, intent);
verify(mWifiP2pManager, times(1)).requestPersistentGroupInfo(any(), any());
}
@Test
public void onActivityCreate_withNullP2pManager_shouldGetP2pManagerAgain() {
mFragment.mWifiP2pManager = null;
mFragment.onActivityCreated(new Bundle());
assertThat(mFragment.mWifiP2pManager).isNotNull();
}
@Test
public void onActivityCreate_withNullChannel_shouldSetP2pManagerNull() {
doReturn(null).when(mWifiP2pManager).initialize(any(), any(), any());
mFragment.onActivityCreated(new Bundle());
assertThat(mFragment.mWifiP2pManager).isNull();
}
@Test
public void clickNegativeButton_whenDeleteGroupDialogShow_shouldSetGroupNull() {
final WifiP2pPersistentGroup wifiP2pPersistentGroup = new WifiP2pPersistentGroup(mContext,
mWifiP2pGroup);
mFragment.mSelectedGroup = wifiP2pPersistentGroup;
final Dialog dialog = mFragment.onCreateDialog(WifiP2pSettings.DIALOG_DELETE_GROUP);
mFragment.mDeleteGroupListener.onClick(dialog, DialogInterface.BUTTON_NEGATIVE);
assertThat(mFragment.mSelectedGroup).isNull();
}
private void setupOneP2pPeer(int status) {
final WifiP2pDevice wifiP2pDevice = mock(WifiP2pDevice.class);
wifiP2pDevice.status = status;