summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/wifitests/src/com/android/server/wifi/SoftApBackupRestoreTest.java17
-rw-r--r--tests/wifitests/src/com/android/server/wifi/SoftApStoreDataTest.java16
-rw-r--r--tests/wifitests/src/com/android/server/wifi/WifiSettingsConfigStoreTest.java31
3 files changed, 38 insertions, 26 deletions
diff --git a/tests/wifitests/src/com/android/server/wifi/SoftApBackupRestoreTest.java b/tests/wifitests/src/com/android/server/wifi/SoftApBackupRestoreTest.java
index 56ba8878f..a1b917431 100644
--- a/tests/wifitests/src/com/android/server/wifi/SoftApBackupRestoreTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/SoftApBackupRestoreTest.java
@@ -30,16 +30,14 @@ import android.util.BackupUtils;
import androidx.test.filters.SmallTest;
-import com.android.dx.mockito.inline.extended.ExtendedMockito;
import com.android.server.wifi.util.ApConfigUtil;
+import com.android.server.wifi.util.SettingsMigrationDataHolder;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
-import org.mockito.MockitoSession;
-import org.mockito.quality.Strictness;
import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
@@ -55,6 +53,7 @@ import java.util.List;
public class SoftApBackupRestoreTest extends WifiBaseTest {
@Mock private Context mContext;
+ @Mock private SettingsMigrationDataHolder mSettingsMigrationDataHolder;
@Mock private WifiMigration.SettingsMigrationData mOemMigrationData;
private SoftApBackupRestore mSoftApBackupRestore;
private final ArrayList<MacAddress> mTestBlockedList = new ArrayList<>();
@@ -72,8 +71,6 @@ public class SoftApBackupRestoreTest extends WifiBaseTest {
private static final int TEST_CHANNEL = 40;
private static final boolean TEST_HIDDEN = false;
- MockitoSession mSession;
-
/**
* Asserts that the WifiConfigurations equal to SoftApConfiguration.
* This only compares the elements saved
@@ -100,20 +97,14 @@ public class SoftApBackupRestoreTest extends WifiBaseTest {
public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
- mSession = ExtendedMockito.mockitoSession()
- .mockStatic(WifiMigration.class, withSettings().lenient())
- .strictness(Strictness.LENIENT)
- .startMocking();
- when(WifiMigration.loadFromSettings(any(Context.class)))
- .thenReturn(mOemMigrationData);
+ when(mSettingsMigrationDataHolder.retrieveData()).thenReturn(mOemMigrationData);
when(mOemMigrationData.isSoftApTimeoutEnabled()).thenReturn(true);
- mSoftApBackupRestore = new SoftApBackupRestore(mContext);
+ mSoftApBackupRestore = new SoftApBackupRestore(mContext, mSettingsMigrationDataHolder);
}
@After
public void tearDown() throws Exception {
- mSession.finishMocking();
}
/**
diff --git a/tests/wifitests/src/com/android/server/wifi/SoftApStoreDataTest.java b/tests/wifitests/src/com/android/server/wifi/SoftApStoreDataTest.java
index 04955f806..739987106 100644
--- a/tests/wifitests/src/com/android/server/wifi/SoftApStoreDataTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/SoftApStoreDataTest.java
@@ -26,7 +26,6 @@ import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
-import static org.mockito.Mockito.withSettings;
import android.content.Context;
import android.net.MacAddress;
@@ -37,8 +36,8 @@ import android.util.Xml;
import androidx.test.filters.SmallTest;
-import com.android.dx.mockito.inline.extended.ExtendedMockito;
import com.android.internal.util.FastXmlSerializer;
+import com.android.server.wifi.util.SettingsMigrationDataHolder;
import com.android.server.wifi.util.WifiConfigStoreEncryptionUtil;
import org.junit.After;
@@ -47,8 +46,6 @@ import org.junit.Test;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
-import org.mockito.MockitoSession;
-import org.mockito.quality.Strictness;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlSerializer;
@@ -187,21 +184,17 @@ public class SoftApStoreDataTest extends WifiBaseTest {
@Mock private Context mContext;
@Mock SoftApStoreData.DataSource mDataSource;
@Mock private WifiMigration.SettingsMigrationData mOemMigrationData;
- MockitoSession mSession;
+ @Mock private SettingsMigrationDataHolder mSettingsMigrationDataHolder;
SoftApStoreData mSoftApStoreData;
@Before
public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
- mSession = ExtendedMockito.mockitoSession()
- .mockStatic(WifiMigration.class, withSettings().lenient())
- .strictness(Strictness.LENIENT)
- .startMocking();
- when(WifiMigration.loadFromSettings(any(Context.class)))
+ when(mSettingsMigrationDataHolder.retrieveData())
.thenReturn(mOemMigrationData);
when(mOemMigrationData.isSoftApTimeoutEnabled()).thenReturn(true);
- mSoftApStoreData = new SoftApStoreData(mContext, mDataSource);
+ mSoftApStoreData = new SoftApStoreData(mContext, mSettingsMigrationDataHolder, mDataSource);
TEST_BLOCKEDLIST.add(MacAddress.fromString(TEST_BLOCKED_CLIENT));
TEST_ALLOWEDLIST.add(MacAddress.fromString(TEST_ALLOWED_CLIENT));
}
@@ -213,7 +206,6 @@ public class SoftApStoreDataTest extends WifiBaseTest {
public void cleanup() {
TEST_BLOCKEDLIST.clear();
TEST_ALLOWEDLIST.clear();
- mSession.finishMocking();
}
/**
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiSettingsConfigStoreTest.java b/tests/wifitests/src/com/android/server/wifi/WifiSettingsConfigStoreTest.java
index 2471e090e..e2e2575d8 100644
--- a/tests/wifitests/src/com/android/server/wifi/WifiSettingsConfigStoreTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/WifiSettingsConfigStoreTest.java
@@ -25,8 +25,10 @@ import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.validateMockitoUsage;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;
+import static org.mockito.Mockito.when;
import android.content.Context;
+import android.net.wifi.WifiMigration;
import android.os.Handler;
import android.os.test.TestLooper;
import android.util.Xml;
@@ -35,6 +37,7 @@ import androidx.test.filters.SmallTest;
import com.android.internal.util.FastXmlSerializer;
import com.android.server.wifi.WifiSettingsConfigStore.Key;
+import com.android.server.wifi.util.SettingsMigrationDataHolder;
import com.android.server.wifi.util.XmlUtil;
import org.junit.After;
@@ -61,6 +64,8 @@ public class WifiSettingsConfigStoreTest extends WifiBaseTest {
@Mock
private Context mContext;
@Mock
+ private SettingsMigrationDataHolder mSettingsMigrationDataHolder;
+ @Mock
private WifiConfigStore mWifiConfigStore;
@Mock
private WifiConfigManager mWifiConfigManager;
@@ -75,7 +80,7 @@ public class WifiSettingsConfigStoreTest extends WifiBaseTest {
mLooper = new TestLooper();
mWifiSettingsConfigStore =
new WifiSettingsConfigStore(mContext, new Handler(mLooper.getLooper()),
- mWifiConfigManager, mWifiConfigStore);
+ mSettingsMigrationDataHolder, mWifiConfigManager, mWifiConfigStore);
}
/**
@@ -124,6 +129,30 @@ public class WifiSettingsConfigStoreTest extends WifiBaseTest {
storeDataCaptor.getValue().deserializeData(in, in.getDepth(), -1, null);
assertTrue(mWifiSettingsConfigStore.get(WIFI_VERBOSE_LOGGING_ENABLED));
+ // verify that we did not trigger migration.
+ verifyNoMoreInteractions(mSettingsMigrationDataHolder);
+ }
+
+ @Test
+ public void testLoadFromMigration() throws Exception {
+ ArgumentCaptor<WifiConfigStore.StoreData> storeDataCaptor = ArgumentCaptor.forClass(
+ WifiConfigStore.StoreData.class);
+ verify(mWifiConfigStore).registerStoreData(storeDataCaptor.capture());
+ assertNotNull(storeDataCaptor.getValue());
+
+ WifiMigration.SettingsMigrationData migrationData = mock(
+ WifiMigration.SettingsMigrationData.class);
+ when(mSettingsMigrationDataHolder.retrieveData()).thenReturn(migrationData);
+ when(migrationData.isVerboseLoggingEnabled()).thenReturn(true);
+
+ // indicate that there is not data in the store file to trigger migration.
+ storeDataCaptor.getValue().resetData();
+ storeDataCaptor.getValue().deserializeData(null, -1, -1, null);
+ mLooper.dispatchAll();
+
+ assertTrue(mWifiSettingsConfigStore.get(WIFI_VERBOSE_LOGGING_ENABLED));
+ // Trigger store file write after migration.
+ verify(mWifiConfigManager).saveToStore(true);
}
private XmlPullParser createSettingsTestXmlForParsing(Key key, Object value)