OSDN Git Service

Change cross profile calendar API used in robolectric test.
authoryuemingw <yuemingw@google.com>
Tue, 22 Jan 2019 20:12:42 +0000 (20:12 +0000)
committerYueming Wang <yuemingw@google.com>
Thu, 24 Jan 2019 00:59:37 +0000 (00:59 +0000)
The API changed from addCrossProfileCalendarPackage to
setCrossProfileCalendarPackages recently due to our decision
in b/121179845. Also added test for the case when
the whitelist is set to null.

Bug: 121179845
Test: make ROBOTEST_FILTER=CrossProfileCalendarPreferenceControllerTest -j40 RunSettingsRoboTests
Change-Id: I66b92aba6d26334e48207275b2d8981203598e15

tests/robotests/src/com/android/settings/accounts/CrossProfileCalendarPreferenceControllerTest.java

index bf4dec6..c6a48a8 100644 (file)
@@ -32,6 +32,7 @@ import android.content.ComponentName;
 import android.content.Context;
 import android.os.UserHandle;
 import android.provider.Settings;
+import android.util.ArraySet;
 
 import com.android.settingslib.RestrictedSwitchPreference;
 
@@ -45,6 +46,9 @@ import org.robolectric.RuntimeEnvironment;
 import org.robolectric.Shadows;
 import org.robolectric.shadows.ShadowDevicePolicyManager;
 
+import java.util.Arrays;
+import java.util.Collections;
+
 @RunWith(RobolectricTestRunner.class)
 public class CrossProfileCalendarPreferenceControllerTest {
 
@@ -123,7 +127,17 @@ public class CrossProfileCalendarPreferenceControllerTest {
     @Test
     public void updateState_somePackagesAllowed_preferenceShouldNotBeDisabled() throws Exception {
         dpm.setProfileOwner(TEST_COMPONENT_NAME);
-        dpm.addCrossProfileCalendarPackage(TEST_COMPONENT_NAME, TEST_PACKAGE_NAME);
+        dpm.setCrossProfileCalendarPackages(TEST_COMPONENT_NAME,
+                Collections.singleton(TEST_PACKAGE_NAME));
+
+        mController.updateState(mPreference);
+        verify(mPreference).setDisabledByAdmin(null);
+    }
+
+    @Test
+    public void updateState_allPackagesAllowed_preferenceShouldNotBeDisabled() throws Exception {
+        dpm.setProfileOwner(TEST_COMPONENT_NAME);
+        dpm.setCrossProfileCalendarPackages(TEST_COMPONENT_NAME, null);
 
         mController.updateState(mPreference);
         verify(mPreference).setDisabledByAdmin(null);