Merge "Updaing ShadowAccountManager to extending from official shadow library" into main
This commit is contained in:
@@ -23,6 +23,7 @@ import static org.mockito.Mockito.doReturn;
|
|||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.spy;
|
import static org.mockito.Mockito.spy;
|
||||||
|
|
||||||
|
import android.accounts.AccountManager;
|
||||||
import android.accounts.AuthenticatorDescription;
|
import android.accounts.AuthenticatorDescription;
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.app.admin.DevicePolicyManager;
|
import android.app.admin.DevicePolicyManager;
|
||||||
@@ -35,6 +36,7 @@ import androidx.fragment.app.FragmentActivity;
|
|||||||
import androidx.preference.Preference;
|
import androidx.preference.Preference;
|
||||||
import androidx.preference.PreferenceManager;
|
import androidx.preference.PreferenceManager;
|
||||||
import androidx.preference.PreferenceScreen;
|
import androidx.preference.PreferenceScreen;
|
||||||
|
import androidx.test.core.app.ApplicationProvider;
|
||||||
|
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
import com.android.settings.core.BasePreferenceController;
|
import com.android.settings.core.BasePreferenceController;
|
||||||
@@ -44,33 +46,38 @@ import com.android.settings.testutils.shadow.ShadowRestrictedLockUtilsInternal;
|
|||||||
|
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
|
import org.junit.Rule;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.mockito.MockitoAnnotations;
|
import org.mockito.junit.MockitoJUnit;
|
||||||
|
import org.mockito.junit.MockitoRule;
|
||||||
import org.robolectric.Robolectric;
|
import org.robolectric.Robolectric;
|
||||||
import org.robolectric.RobolectricTestRunner;
|
import org.robolectric.RobolectricTestRunner;
|
||||||
import org.robolectric.RuntimeEnvironment;
|
import org.robolectric.Shadows;
|
||||||
import org.robolectric.annotation.Config;
|
import org.robolectric.annotation.Config;
|
||||||
|
|
||||||
@RunWith(RobolectricTestRunner.class)
|
@RunWith(RobolectricTestRunner.class)
|
||||||
@Config(shadows = {ShadowAccountManager.class, ShadowContentResolver.class,
|
@Config(shadows = {ShadowAccountManager.class, ShadowContentResolver.class,
|
||||||
ShadowRestrictedLockUtilsInternal.class})
|
ShadowRestrictedLockUtilsInternal.class})
|
||||||
public class ChooseAccountPreferenceControllerTest {
|
public class ChooseAccountPreferenceControllerTest {
|
||||||
|
@Rule
|
||||||
|
public final MockitoRule mMockitoRule = MockitoJUnit.rule();
|
||||||
|
|
||||||
private Context mContext;
|
private Context mContext;
|
||||||
private ChooseAccountPreferenceController mController;
|
private ChooseAccountPreferenceController mController;
|
||||||
private Activity mActivity;
|
private Activity mActivity;
|
||||||
private PreferenceManager mPreferenceManager;
|
private PreferenceManager mPreferenceManager;
|
||||||
private PreferenceScreen mPreferenceScreen;
|
private PreferenceScreen mPreferenceScreen;
|
||||||
|
private ShadowAccountManager mAccountManager;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
MockitoAnnotations.initMocks(this);
|
mContext = ApplicationProvider.getApplicationContext();
|
||||||
mContext = RuntimeEnvironment.application;
|
|
||||||
mController = spy(new ChooseAccountPreferenceController(mContext, "controller_key"));
|
mController = spy(new ChooseAccountPreferenceController(mContext, "controller_key"));
|
||||||
mActivity = Robolectric.setupActivity(FragmentActivity.class);
|
mActivity = Robolectric.setupActivity(FragmentActivity.class);
|
||||||
mPreferenceManager = new PreferenceManager(mContext);
|
mPreferenceManager = new PreferenceManager(mContext);
|
||||||
mPreferenceScreen = mPreferenceManager.createPreferenceScreen(mContext);
|
mPreferenceScreen = mPreferenceManager.createPreferenceScreen(mContext);
|
||||||
|
mAccountManager = (ShadowAccountManager) Shadows.shadowOf(AccountManager.get(mContext));
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
@After
|
||||||
@@ -108,7 +115,7 @@ public class ChooseAccountPreferenceControllerTest {
|
|||||||
final AuthenticatorDescription authDesc = new AuthenticatorDescription("com.acct1",
|
final AuthenticatorDescription authDesc = new AuthenticatorDescription("com.acct1",
|
||||||
"com.android.settings",
|
"com.android.settings",
|
||||||
R.string.header_add_an_account, 0, 0, 0, false);
|
R.string.header_add_an_account, 0, 0, 0, false);
|
||||||
ShadowAccountManager.addAuthenticator(authDesc);
|
mAccountManager.addAuthenticator(authDesc);
|
||||||
|
|
||||||
final SyncAdapterType[] syncAdapters = {new SyncAdapterType("authority" /* authority */,
|
final SyncAdapterType[] syncAdapters = {new SyncAdapterType("authority" /* authority */,
|
||||||
"com.acct1" /* accountType */, false /* userVisible */,
|
"com.acct1" /* accountType */, false /* userVisible */,
|
||||||
@@ -133,7 +140,7 @@ public class ChooseAccountPreferenceControllerTest {
|
|||||||
final AuthenticatorDescription authDesc = new AuthenticatorDescription("com.acct1",
|
final AuthenticatorDescription authDesc = new AuthenticatorDescription("com.acct1",
|
||||||
"com.android.settings",
|
"com.android.settings",
|
||||||
R.string.header_add_an_account, 0, 0, 0, false);
|
R.string.header_add_an_account, 0, 0, 0, false);
|
||||||
ShadowAccountManager.addAuthenticator(authDesc);
|
mAccountManager.addAuthenticator(authDesc);
|
||||||
|
|
||||||
final SyncAdapterType[] syncAdapters = {new SyncAdapterType("authority" /* authority */,
|
final SyncAdapterType[] syncAdapters = {new SyncAdapterType("authority" /* authority */,
|
||||||
"com.acct1" /* accountType */, false /* userVisible */,
|
"com.acct1" /* accountType */, false /* userVisible */,
|
||||||
@@ -158,7 +165,7 @@ public class ChooseAccountPreferenceControllerTest {
|
|||||||
final AuthenticatorDescription authDesc = new AuthenticatorDescription("com.acct1",
|
final AuthenticatorDescription authDesc = new AuthenticatorDescription("com.acct1",
|
||||||
"com.android.settings",
|
"com.android.settings",
|
||||||
R.string.header_add_an_account, 0, 0, 0, false);
|
R.string.header_add_an_account, 0, 0, 0, false);
|
||||||
ShadowAccountManager.addAuthenticator(authDesc);
|
mAccountManager.addAuthenticator(authDesc);
|
||||||
|
|
||||||
final SyncAdapterType[] syncAdapters = {new SyncAdapterType("authority" /* authority */,
|
final SyncAdapterType[] syncAdapters = {new SyncAdapterType("authority" /* authority */,
|
||||||
"com.acct1" /* accountType */, false /* userVisible */,
|
"com.acct1" /* accountType */, false /* userVisible */,
|
||||||
@@ -184,8 +191,8 @@ public class ChooseAccountPreferenceControllerTest {
|
|||||||
final AuthenticatorDescription authDesc2 = new AuthenticatorDescription("com.acct2",
|
final AuthenticatorDescription authDesc2 = new AuthenticatorDescription("com.acct2",
|
||||||
"com.android.settings",
|
"com.android.settings",
|
||||||
R.string.header_add_an_account, 0, 0, 0, false);
|
R.string.header_add_an_account, 0, 0, 0, false);
|
||||||
ShadowAccountManager.addAuthenticator(authDesc);
|
mAccountManager.addAuthenticator(authDesc);
|
||||||
ShadowAccountManager.addAuthenticator(authDesc2);
|
mAccountManager.addAuthenticator(authDesc2);
|
||||||
|
|
||||||
final SyncAdapterType[] syncAdapters = {new SyncAdapterType("authority" /* authority */,
|
final SyncAdapterType[] syncAdapters = {new SyncAdapterType("authority" /* authority */,
|
||||||
"com.acct1" /* accountType */, false /* userVisible */,
|
"com.acct1" /* accountType */, false /* userVisible */,
|
||||||
|
@@ -31,7 +31,7 @@ import java.util.List;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@Implements(AccountManager.class)
|
@Implements(AccountManager.class)
|
||||||
public class ShadowAccountManager {
|
public class ShadowAccountManager extends org.robolectric.shadows.ShadowAccountManager {
|
||||||
|
|
||||||
private static final Map<String, AuthenticatorDescription> sAuthenticators = new HashMap<>();
|
private static final Map<String, AuthenticatorDescription> sAuthenticators = new HashMap<>();
|
||||||
private static final Map<Integer, List<Account>> sAccountsByUserId = new HashMap<>();
|
private static final Map<Integer, List<Account>> sAccountsByUserId = new HashMap<>();
|
||||||
@@ -41,7 +41,8 @@ public class ShadowAccountManager {
|
|||||||
return sAuthenticators.values().toArray(new AuthenticatorDescription[sAuthenticators.size()]);
|
return sAuthenticators.values().toArray(new AuthenticatorDescription[sAuthenticators.size()]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void addAuthenticator(AuthenticatorDescription authenticator) {
|
@Override
|
||||||
|
public void addAuthenticator(AuthenticatorDescription authenticator) {
|
||||||
sAuthenticators.put(authenticator.type, authenticator);
|
sAuthenticators.put(authenticator.type, authenticator);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user