Implement getConfig() method to get WifiConfiguration
Make a duplicated function of WifiConfigController.getConfig(). This function could get a new WifiConfiguration from input AccessPoint or ScanResult. Should be removed if there is standard one in framework. Bug: 120827021 Test: RunSettingsRoboTests Change-Id: Ia5981e8d41f434c097b464a2bfe18e1356f7b087
This commit is contained in:
@@ -197,9 +197,12 @@ public class NetworkRequestDialogFragmentTest {
|
||||
accessPointList.add(new AccessPoint(mContext, bundle));
|
||||
bundle.putString(KEY_SSID, "Test AP 2");
|
||||
accessPointList.add(new AccessPoint(mContext, bundle));
|
||||
|
||||
bundle.putString(KEY_SSID, "Test AP 3");
|
||||
AccessPoint clickedAccessPoint = new AccessPoint(mContext, bundle);
|
||||
clickedAccessPoint.generateOpenNetworkConfig();
|
||||
accessPointList.add(clickedAccessPoint);
|
||||
|
||||
bundle.putString(KEY_SSID, "Test AP 4");
|
||||
accessPointList.add(new AccessPoint(mContext, bundle));
|
||||
when(networkRequestDialogFragment.getAccessPointList()).thenReturn(accessPointList);
|
||||
|
@@ -22,6 +22,16 @@ import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
|
||||
import static org.mockito.Mockito.spy;
|
||||
|
||||
import android.content.Context;
|
||||
import android.net.wifi.WifiConfiguration;
|
||||
import android.os.Bundle;
|
||||
|
||||
import com.android.settingslib.wifi.AccessPoint;
|
||||
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class WifiUtilsTest {
|
||||
|
||||
@@ -44,4 +54,23 @@ public class WifiUtilsTest {
|
||||
assertThat(WifiUtils.isHotspotPasswordValid(longPassword)).isFalse();
|
||||
assertThat(WifiUtils.isHotspotPasswordValid("")).isFalse();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getWifiConfigByAccessPoint_shouldReturnCorrectConfig() {
|
||||
String testSSID = "WifiUtilsTest";
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putString("key_ssid", testSSID);
|
||||
Context context = spy(RuntimeEnvironment.application);
|
||||
AccessPoint accessPoint = new AccessPoint(context, bundle);
|
||||
|
||||
WifiConfiguration config = WifiUtils.getWifiConfig(accessPoint, null, null);
|
||||
|
||||
assertThat(config).isNotNull();
|
||||
assertThat(config.SSID).isEqualTo(AccessPoint.convertToQuotedString(testSSID));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void getWifiConfigWithNullInput_ThrowIllegalArgumentException() {
|
||||
WifiConfiguration config = WifiUtils.getWifiConfig(null, null, null);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user