Change cross profile calendar API used in robolectric test.

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
This commit is contained in:
yuemingw
2019-01-22 20:12:42 +00:00
committed by Yueming Wang
parent d3c02d87f9
commit 264ae20256

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