summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorIsaac Chiou <isaacchiou@google.com>2020-08-25 02:42:22 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2020-08-25 02:42:22 +0000
commit82964ba1e58639a818884cf0191ef24d05192f2e (patch)
tree00729e31cf3ede0146b3deba972339bb0ed3fcc3 /tests
parentafba1edfcf5b569b0b90a57d4340d7748f62845f (diff)
parentc86dbb70981712b48af042e1f4c4670b83f60f6a (diff)
Merge "Wifi: Set package name on the intent" into rvc-qpr-dev
Diffstat (limited to 'tests')
-rw-r--r--tests/wifitests/src/com/android/server/wifi/EapFailureNotifierTest.java29
1 files changed, 28 insertions, 1 deletions
diff --git a/tests/wifitests/src/com/android/server/wifi/EapFailureNotifierTest.java b/tests/wifitests/src/com/android/server/wifi/EapFailureNotifierTest.java
index d2a3ac0dc..26391334c 100644
--- a/tests/wifitests/src/com/android/server/wifi/EapFailureNotifierTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/EapFailureNotifierTest.java
@@ -21,12 +21,17 @@ import static com.android.dx.mockito.inline.extended.ExtendedMockito.mockitoSess
import static org.junit.Assert.*;
import static org.mockito.Mockito.*;
+import android.app.ActivityManager;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Intent;
+import android.content.pm.ActivityInfo;
+import android.content.pm.PackageManager;
+import android.content.pm.ResolveInfo;
import android.content.res.Resources;
import android.net.wifi.WifiConfiguration;
+import android.os.UserHandle;
import android.provider.Settings;
import android.service.notification.StatusBarNotification;
import android.telephony.SubscriptionManager;
@@ -42,13 +47,18 @@ import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.mockito.MockitoSession;
+import java.util.Arrays;
+
/**
* Unit tests for {@link com.android.server.wifi.EapFailureNotifier}.
*/
@SmallTest
public class EapFailureNotifierTest extends WifiBaseTest {
+ private static final String TEST_SETTINGS_PACKAGE = "android";
+
@Mock WifiContext mContext;
@Mock Resources mResources;
+ @Mock PackageManager mPackageManager;
@Mock NotificationManager mNotificationManager;
@Mock FrameworkFacade mFrameworkFacade;
@Mock Notification mNotification;
@@ -65,6 +75,7 @@ public class EapFailureNotifierTest extends WifiBaseTest {
private static final String UNDEFINED_ERROR_RESOURCE_NAME = "wifi_eap_error_message_code_12345";
private MockitoSession mStaticMockSession = null;
+
EapFailureNotifier mEapFailureNotifier;
/**
@@ -73,15 +84,26 @@ public class EapFailureNotifierTest extends WifiBaseTest {
@Before
public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
+ ResolveInfo settingsResolveInfo = new ResolveInfo();
+ settingsResolveInfo.activityInfo = new ActivityInfo();
+ settingsResolveInfo.activityInfo.packageName = TEST_SETTINGS_PACKAGE;
+ when(mPackageManager.queryIntentActivitiesAsUser(
+ argThat(((intent) -> intent.getAction().equals(Settings.ACTION_WIFI_SETTINGS))),
+ anyInt(), any()))
+ .thenReturn(Arrays.asList(settingsResolveInfo));
+ // static mocking
mStaticMockSession = mockitoSession()
.mockStatic(SubscriptionManager.class)
+ .mockStatic(ActivityManager.class, withSettings().lenient())
.startMocking();
+ when(ActivityManager.getCurrentUser()).thenReturn(UserHandle.USER_SYSTEM);
when(mContext.getSystemService(NotificationManager.class))
.thenReturn(mNotificationManager);
when(mWifiCarrierInfoManager.getBestMatchSubscriptionId(mWifiConfiguration)).thenReturn(0);
lenient().when(SubscriptionManager.getResourcesForSubId(eq(mContext), anyInt()))
.thenReturn(mResources);
when(mContext.getResources()).thenReturn(mResources);
+ when(mContext.getPackageManager()).thenReturn(mPackageManager);
when(mResources.getIdentifier(eq(DEFINED_ERROR_RESOURCE_NAME), anyString(),
anyString())).thenReturn(1);
when(mResources.getIdentifier(eq(UNDEFINED_ERROR_RESOURCE_NAME), anyString(),
@@ -97,7 +119,10 @@ public class EapFailureNotifierTest extends WifiBaseTest {
@After
public void cleanUp() throws Exception {
- mStaticMockSession.finishMocking();
+ validateMockitoUsage();
+ if (mStaticMockSession != null) {
+ mStaticMockSession.finishMocking();
+ }
}
/**
@@ -120,6 +145,7 @@ public class EapFailureNotifierTest extends WifiBaseTest {
ArgumentCaptor<Intent> intent = ArgumentCaptor.forClass(Intent.class);
verify(mFrameworkFacade).getActivity(
eq(mContext), eq(0), intent.capture(), eq(PendingIntent.FLAG_UPDATE_CURRENT));
+ assertEquals(TEST_SETTINGS_PACKAGE, intent.getValue().getPackage());
assertEquals(Settings.ACTION_WIFI_SETTINGS, intent.getValue().getAction());
}
@@ -146,6 +172,7 @@ public class EapFailureNotifierTest extends WifiBaseTest {
ArgumentCaptor<Intent> intent = ArgumentCaptor.forClass(Intent.class);
verify(mFrameworkFacade).getActivity(
eq(mContext), eq(0), intent.capture(), eq(PendingIntent.FLAG_UPDATE_CURRENT));
+ assertEquals(TEST_SETTINGS_PACKAGE, intent.getValue().getPackage());
assertEquals(Settings.ACTION_WIFI_SETTINGS, intent.getValue().getAction());
}