use of android.content.ContextWrapper in project Bolts-Android by BoltsFramework.
the class AppLinkTest method setUp.
@Override
protected void setUp() throws Exception {
super.setUp();
openedIntents = new ArrayList<>();
instrumentation = InstrumentationRegistry.getInstrumentation();
activityInterceptor = new ContextWrapper(instrumentation.getTargetContext()) {
@Override
public void startActivity(Intent intent) {
openedIntents.add(intent);
}
};
}
use of android.content.ContextWrapper in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class ExternalSourcesDetailsTest method refreshUi_bothUnknownSourcesUserRestrictions_disableSwitchPreference.
@Test
public void refreshUi_bothUnknownSourcesUserRestrictions_disableSwitchPreference() {
// Mocks set up
final ExternalSourcesDetails fragment = new ExternalSourcesDetails();
final ContextWrapper context = RuntimeEnvironment.application;
final UserManager userManager = (UserManager) context.getSystemService(Context.USER_SERVICE);
final ShadowUserManager shadowUserManager = Shadow.extract(userManager);
ReflectionHelpers.setField(fragment, "mSwitchPref", mSwitchPref);
ReflectionHelpers.setField(fragment, "mPackageInfo", mPackageInfo);
mPackageInfo.applicationInfo = new ApplicationInfo();
ReflectionHelpers.setField(fragment, "mUserManager", userManager);
ReflectionHelpers.setField(mSwitchPref, "mHelper", mHelper);
final AppStateInstallAppsBridge appBridge = mock(AppStateInstallAppsBridge.class);
ReflectionHelpers.setField(fragment, "mAppBridge", appBridge);
when(appBridge.createInstallAppsStateFor(nullable(String.class), anyInt())).thenReturn(mock(InstallAppsState.class));
// Test restriction set up
shadowUserManager.setUserRestriction(UserHandle.of(UserHandle.myUserId()), UserManager.DISALLOW_INSTALL_UNKNOWN_SOURCES_GLOBALLY, true);
shadowUserManager.setUserRestriction(UserHandle.of(UserHandle.myUserId()), UserManager.DISALLOW_INSTALL_UNKNOWN_SOURCES, true);
doAnswer((answer) -> {
when(mSwitchPref.isDisabledByAdmin()).thenReturn(true);
return null;
}).when(mSwitchPref).checkRestrictionAndSetDisabled(UserManager.DISALLOW_INSTALL_UNKNOWN_SOURCES_GLOBALLY);
// Code execution
assertThat(fragment.refreshUi()).isTrue();
// Assertions
assertThat(userManager.hasUserRestriction(UserManager.DISALLOW_INSTALL_UNKNOWN_SOURCES_GLOBALLY, UserHandle.of(UserHandle.myUserId()))).isTrue();
assertThat(userManager.hasUserRestriction(UserManager.DISALLOW_INSTALL_UNKNOWN_SOURCES, UserHandle.of(UserHandle.myUserId()))).isTrue();
assertThat(mSwitchPref.isDisabledByAdmin()).isTrue();
}
use of android.content.ContextWrapper in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class ExternalSourcesDetailsTest method refreshUi_userRestrictionsUnknownSourcesGlobally_disablesSwitchPreference.
@Test
public void refreshUi_userRestrictionsUnknownSourcesGlobally_disablesSwitchPreference() {
// Mocks set up
final ExternalSourcesDetails fragment = new ExternalSourcesDetails();
final ContextWrapper context = RuntimeEnvironment.application;
final UserManager userManager = (UserManager) context.getSystemService(Context.USER_SERVICE);
final ShadowUserManager shadowUserManager = Shadow.extract(userManager);
ReflectionHelpers.setField(fragment, "mSwitchPref", mSwitchPref);
ReflectionHelpers.setField(fragment, "mPackageInfo", mPackageInfo);
mPackageInfo.applicationInfo = new ApplicationInfo();
ReflectionHelpers.setField(fragment, "mUserManager", userManager);
ReflectionHelpers.setField(mSwitchPref, "mHelper", mHelper);
final AppStateInstallAppsBridge appBridge = mock(AppStateInstallAppsBridge.class);
ReflectionHelpers.setField(fragment, "mAppBridge", appBridge);
when(appBridge.createInstallAppsStateFor(nullable(String.class), anyInt())).thenReturn(mock(InstallAppsState.class));
// Test restriction set up
shadowUserManager.setUserRestriction(UserHandle.of(UserHandle.myUserId()), UserManager.DISALLOW_INSTALL_UNKNOWN_SOURCES_GLOBALLY, true);
doAnswer((answer) -> {
when(mSwitchPref.isDisabledByAdmin()).thenReturn(true);
return null;
}).when(mSwitchPref).checkRestrictionAndSetDisabled(UserManager.DISALLOW_INSTALL_UNKNOWN_SOURCES_GLOBALLY);
// Code execution
assertThat(fragment.refreshUi()).isTrue();
// Assertions
assertThat(userManager.hasUserRestriction(UserManager.DISALLOW_INSTALL_UNKNOWN_SOURCES_GLOBALLY, UserHandle.of(UserHandle.myUserId()))).isTrue();
assertThat(mSwitchPref.isDisabledByAdmin()).isTrue();
}
use of android.content.ContextWrapper in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class ExternalSourcesDetailsTest method refreshUi_userRestrictionsUnknownSources_disablesSwitchPreference.
@Test
public void refreshUi_userRestrictionsUnknownSources_disablesSwitchPreference() {
// Mocks set up
final ExternalSourcesDetails fragment = new ExternalSourcesDetails();
final ContextWrapper context = RuntimeEnvironment.application;
final UserManager userManager = (UserManager) context.getSystemService(Context.USER_SERVICE);
final ShadowUserManager shadowUserManager = Shadow.extract(userManager);
ReflectionHelpers.setField(fragment, "mSwitchPref", mSwitchPref);
ReflectionHelpers.setField(fragment, "mPackageInfo", mPackageInfo);
mPackageInfo.applicationInfo = new ApplicationInfo();
ReflectionHelpers.setField(fragment, "mUserManager", userManager);
ReflectionHelpers.setField(mSwitchPref, "mHelper", mHelper);
final AppStateInstallAppsBridge appBridge = mock(AppStateInstallAppsBridge.class);
ReflectionHelpers.setField(fragment, "mAppBridge", appBridge);
when(appBridge.createInstallAppsStateFor(nullable(String.class), anyInt())).thenReturn(mock(InstallAppsState.class));
// Test restriction set up
shadowUserManager.setUserRestriction(UserHandle.of(UserHandle.myUserId()), UserManager.DISALLOW_INSTALL_UNKNOWN_SOURCES, true);
doAnswer((answer) -> {
when(mSwitchPref.isDisabledByAdmin()).thenReturn(true);
return null;
}).when(mSwitchPref).checkRestrictionAndSetDisabled(UserManager.DISALLOW_INSTALL_UNKNOWN_SOURCES);
// Code execution
assertThat(fragment.refreshUi()).isTrue();
// Assertions
assertThat(userManager.hasUserRestriction(UserManager.DISALLOW_INSTALL_UNKNOWN_SOURCES, UserHandle.of(UserHandle.myUserId()))).isTrue();
assertThat(mSwitchPref.isDisabledByAdmin()).isTrue();
}
use of android.content.ContextWrapper in project Presentation by StanKocken.
the class BasePresenterTest method testShouldReturnActivityFromContextWrapper.
@Test
public void testShouldReturnActivityFromContextWrapper() {
ContextWrapper contextWrapper = Mockito.mock(ContextWrapper.class);
Activity activity = Mockito.mock(Activity.class);
TestDef.IView view = Mockito.mock(TestDef.IView.class);
when(view.getContext()).thenReturn(contextWrapper);
when(contextWrapper.getBaseContext()).thenReturn(activity);
TestPresenter presenter = new TestPresenter();
presenter.setView(view);
assertEquals(contextWrapper, presenter.getContext());
assertEquals(activity, presenter.getActivity());
}
Aggregations