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:
cosmohsieh
2018-12-12 10:14:54 +08:00
committed by Cosmo Hsieh
parent 3f80d1b64b
commit 64b894f81d
4 changed files with 186 additions and 3 deletions

View File

@@ -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);

View File

@@ -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);
}
}