Refactoring DoubleTwistPreferenceController.
Made the availability and setting logic static so that it can be invoked without creating a controller. Bug: 62022517 Test: robotests Change-Id: I3a51c61849e6ba8b8aa850ca22d666a9f84d252f
This commit is contained in:
@@ -41,11 +41,12 @@ import java.util.List;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.mockito.Matchers.anyInt;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import com.android.settings.testutils.shadow.ShadowDoubleTwistPreferenceController;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public class DoubleTwistPreferenceControllerTest {
|
||||
@@ -102,14 +103,16 @@ public class DoubleTwistPreferenceControllerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Config(shadows = {ShadowSecureSettings.class})
|
||||
@Config(shadows = {
|
||||
ShadowDoubleTwistPreferenceController.class,
|
||||
ShadowSecureSettings.class})
|
||||
public void onPreferenceChange_hasWorkProfile_shouldUpdateSettingForWorkProfileUser() {
|
||||
final int managedId = 2;
|
||||
ShadowSecureSettings.putIntForUser(
|
||||
null, Settings.Secure.CAMERA_DOUBLE_TWIST_TO_FLIP_ENABLED, 0, managedId);
|
||||
DoubleTwistPreferenceController controller =
|
||||
spy(new DoubleTwistPreferenceController(mContext, null, KEY_DOUBLE_TWIST));
|
||||
doReturn(managedId).when(controller).getManagedProfileUserId();
|
||||
ShadowDoubleTwistPreferenceController.setManagedProfileId(managedId);
|
||||
|
||||
// enable the gesture
|
||||
controller.onPreferenceChange(null, true);
|
||||
|
@@ -0,0 +1,28 @@
|
||||
package com.android.settings.testutils.shadow;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.UserHandle;
|
||||
import android.os.UserManager;
|
||||
|
||||
import com.android.settings.gestures.DoubleTwistPreferenceController;
|
||||
|
||||
import org.robolectric.annotation.Implementation;
|
||||
import org.robolectric.annotation.Implements;
|
||||
|
||||
@Implements(DoubleTwistPreferenceController.class)
|
||||
public class ShadowDoubleTwistPreferenceController {
|
||||
private static int sManagedProfileId = UserHandle.USER_NULL;
|
||||
@Implementation
|
||||
public static boolean isGestureAvailable(Context context) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Implementation
|
||||
public static int getManagedProfileId(UserManager userManager) {
|
||||
return sManagedProfileId;
|
||||
}
|
||||
|
||||
public static void setManagedProfileId(int managedProfileId) {
|
||||
sManagedProfileId = managedProfileId;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user