Java 类org.robolectric.shadows.ShadowAccountManager 实例源码

项目:materialistic    文件:DrawerActivityLoginTest.java   
@Test
public void testExistingAccount() {
    ShadowAccountManager.get(activity).addAccountExplicitly(new Account("existing",
            BuildConfig.APPLICATION_ID), "password", null);
    drawerAccount.performClick();
    AlertDialog alertDialog = ShadowAlertDialog.getLatestAlertDialog();
    assertNotNull(alertDialog);
    assertThat(alertDialog.getListView().getAdapter()).hasCount(1);
    shadowOf(alertDialog).clickOnItem(0);
    alertDialog.getButton(DialogInterface.BUTTON_POSITIVE).performClick();
    assertThat(alertDialog).isNotShowing();
    assertThat(drawerAccount).hasText("existing");
    assertThat(drawerLogout).isVisible();
    drawerAccount.performClick();
    alertDialog = ShadowAlertDialog.getLatestAlertDialog();
    assertThat(alertDialog.getListView().getAdapter()).hasCount(1);
}
项目:materialistic    文件:DrawerActivityLoginTest.java   
@Test
public void testAddAccount() {
    ShadowAccountManager.get(activity).addAccountExplicitly(new Account("existing",
            BuildConfig.APPLICATION_ID), "password", null);
    drawerAccount.performClick();
    AlertDialog alertDialog = ShadowAlertDialog.getLatestAlertDialog();
    assertNotNull(alertDialog);
    assertThat(alertDialog.getListView().getAdapter()).hasCount(1);
    alertDialog.getButton(DialogInterface.BUTTON_NEGATIVE).performClick();
    assertThat(alertDialog).isNotShowing();
    ((ShadowSupportDrawerLayout) ShadowExtractor.extract(activity.findViewById(R.id.drawer_layout)))
            .getDrawerListeners().get(0)
            .onDrawerClosed(activity.findViewById(R.id.drawer));
    assertThat(shadowOf(activity).getNextStartedActivity())
            .hasComponent(activity, LoginActivity.class);
}
项目:materialistic    文件:UserServicesClientTest.java   
@Before
public void setUp() {
    MockitoAnnotations.initMocks(this);
    call = mock(Call.class);
    Call.Factory callFactory = mock(Call.Factory.class);
    when(callFactory.newCall(any(Request.class))).thenReturn(call);
    userServices = new UserServicesClient(callFactory, Schedulers.immediate());
    Preferences.setUsername(RuntimeEnvironment.application, "username");
    account = new Account("username", BuildConfig.APPLICATION_ID);
    ShadowAccountManager.get(RuntimeEnvironment.application)
            .addAccountExplicitly(account, "password", null);
}
项目:materialistic    文件:UserServicesClientTest.java   
@Test
public void testVoteNoAccount() throws IOException {
    ShadowAccountManager.get(RuntimeEnvironment.application)
            .removeAccount(account, null, null);
    UserServices.Callback callback = mock(UserServices.Callback.class);
    assertFalse(userServices.voteUp(RuntimeEnvironment.application, "1", callback));
    verify(call, never()).enqueue(any(Callback.class));
}
项目:materialistic    文件:UserServicesClientTest.java   
@Test
public void testSubmitNoAccount() throws IOException {
    ShadowAccountManager.get(RuntimeEnvironment.application)
            .removeAccount(account, null, null);
    UserServices.Callback callback = mock(UserServices.Callback.class);
    userServices.submit(RuntimeEnvironment.application, "title", "content", true, callback);
    verify(call, never()).enqueue(any(Callback.class));
    verify(callback).onDone(eq(false));
}
项目:materialistic    文件:DrawerActivityLoginTest.java   
@Config(sdk = 21)
@Test
public void testRemoveAccount() {
    ShadowAccountManager.get(activity).addAccountExplicitly(new Account("existing",
            BuildConfig.APPLICATION_ID), "password", null);
    Preferences.setUsername(activity, "existing");
    drawerAccount.performClick();
    AlertDialog alertDialog = ShadowAlertDialog.getLatestAlertDialog();
    assertNotNull(alertDialog);
    assertThat(alertDialog.getListView().getAdapter()).hasCount(1);
    alertDialog.getButton(DialogInterface.BUTTON_NEUTRAL).performClick();
    assertThat(alertDialog).isNotShowing();
    assertThat(ShadowAccountManager.get(activity).getAccounts()).isEmpty();
}
项目:materialistic    文件:AppUtilsTest.java   
@Test
public void testLoginStaleAccount() {
    Preferences.setUsername(RuntimeEnvironment.application, "username");
    shadowOf(ShadowAccountManager.get(RuntimeEnvironment.application))
            .addAccount(new Account("username", BuildConfig.APPLICATION_ID));
    AppUtils.showLogin(RuntimeEnvironment.application, null);
    assertThat(shadowOf(RuntimeEnvironment.application).getNextStartedActivity())
            .hasComponent(RuntimeEnvironment.application, LoginActivity.class);
}
项目:materialistic    文件:AppUtilsTest.java   
@Test
public void testLoginShowChooser() {
    TestApplication.applicationGraph.inject(this);
    shadowOf(ShadowAccountManager.get(RuntimeEnvironment.application))
            .addAccount(new Account("username", BuildConfig.APPLICATION_ID));
    AppUtils.showLogin(RuntimeEnvironment.application, alertDialogBuilder);
    assertNotNull(ShadowAlertDialog.getLatestAlertDialog());
}
项目:materialistic    文件:LoginActivityTest.java   
@Test
public void testLoginSuccessful() {
    ((EditText) activity.findViewById(R.id.edittext_username)).setText("username");
    ((EditText) activity.findViewById(R.id.edittext_password)).setText("password");
    activity.findViewById(R.id.login_button).performClick();
    assertNull(((TextInputLayout) activity.findViewById(R.id.textinput_username)).getError());
    assertNull(((TextInputLayout) activity.findViewById(R.id.textinput_password)).getError());
    verify(userServices).login(eq("username"), eq("password"), eq(false), callback.capture());
    callback.getValue().onDone(true);
    assertThat(activity).isFinishing();
    assertEquals(activity.getString(R.string.welcome, "username"), ShadowToast.getTextOfLatestToast());
    assertThat(ShadowAccountManager.get(activity).getAccounts()).hasSize(1);
    assertEquals("username", Preferences.getUsername(activity));
}
项目:materialistic    文件:TestActivityModule.java   
@Provides
public AccountManager provideAccountManager() {
    return ShadowAccountManager.get(RuntimeEnvironment.application);
}
项目:FullRobolectricTestSample    文件:Robolectric.java   
public static ShadowAccountManager shadowOf(AccountManager instance) {
  return (ShadowAccountManager) shadowOf_(instance);
}