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

项目:materialistic    文件:FavoriteActivityTest.java   
@Test
public void testOptionsMenuClear() {
    assertTrue(shadowOf(activity).getOptionsMenu().findItem(R.id.menu_clear).isVisible());
    shadowOf(activity).clickMenuItem(R.id.menu_clear);
    AlertDialog dialog = ShadowAlertDialog.getLatestAlertDialog();
    dialog.getButton(DialogInterface.BUTTON_NEGATIVE).performClick();
    assertEquals(2, adapter.getItemCount());

    shadowOf(activity).clickMenuItem(R.id.menu_clear);
    dialog = ShadowAlertDialog.getLatestAlertDialog();
    dialog.getButton(DialogInterface.BUTTON_POSITIVE).performClick();
    verify(favoriteManager).clear(any(Context.class), any());
    when(favoriteManager.getSize()).thenReturn(0);
    observerCaptor.getValue().onChanged();
    assertEquals(0, adapter.getItemCount());
}
项目:materialistic    文件:FavoriteActivityTest.java   
@Test
public void testDelete() {
    RecyclerView.ViewHolder holder = shadowAdapter.getViewHolder(0);
    holder.itemView.performLongClick();

    ActionMode actionMode = mock(ActionMode.class);
    activity.actionModeCallback.onActionItemClicked(actionMode, new RoboMenuItem(R.id.menu_clear));
    AlertDialog dialog = ShadowAlertDialog.getLatestAlertDialog();
    dialog.getButton(DialogInterface.BUTTON_NEGATIVE).performClick();
    assertEquals(2, adapter.getItemCount());

    activity.actionModeCallback.onActionItemClicked(actionMode, new RoboMenuItem(R.id.menu_clear));
    dialog = ShadowAlertDialog.getLatestAlertDialog();
    dialog.getButton(DialogInterface.BUTTON_POSITIVE).performClick();
    verify(favoriteManager).remove(any(Context.class), selection.capture());
    assertThat(selection.getValue()).contains("1");
    verify(actionMode).finish();

    when(favoriteManager.getSize()).thenReturn(1);
    observerCaptor.getValue().onChanged();
    assertEquals(1, adapter.getItemCount());
}
项目:materialistic    文件:DrawerActivityLoginTest.java   
@Test
public void testNoExistingAccount() {
    assertThat(drawerAccount).hasText(R.string.login);
    assertThat(drawerLogout).isNotVisible();
    assertThat(drawerUser).isNotVisible();
    Preferences.setUsername(activity, "username");
    assertThat(drawerAccount).hasText("username");
    assertThat(drawerLogout).isVisible();
    assertThat(drawerUser).isVisible();
    drawerLogout.performClick();
    AlertDialog alertDialog = ShadowAlertDialog.getLatestAlertDialog();
    assertNotNull(alertDialog);
    alertDialog.getButton(DialogInterface.BUTTON_POSITIVE).performClick();
    assertThat(drawerAccount).hasText(R.string.login);
    assertThat(drawerLogout).isNotVisible();
}
项目: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    文件:SubmitActivityTest.java   
@Test
public void testSubmitError() {
    ((EditText) activity.findViewById(R.id.edittext_title)).setText("title");
    ((EditText) activity.findViewById(R.id.edittext_content)).setText("http://example.com");
    shadowOf(activity).clickMenuItem(R.id.menu_send);
    ShadowAlertDialog.getLatestAlertDialog().getButton(DialogInterface.BUTTON_POSITIVE)
            .performClick();
    verify(userServices).submit(any(Context.class), eq("title"), eq("http://example.com"),
            eq(true), submitCallback.capture());
    Uri redirect = Uri.parse(BuildConfig.APPLICATION_ID + "://item?id=1234");
    UserServices.Exception exception = new UserServices.Exception(R.string.item_exist);
    exception.data = redirect;
    submitCallback.getValue().onError(exception);
    assertEquals(activity.getString(R.string.item_exist), ShadowToast.getTextOfLatestToast());
    assertThat(shadowOf(activity).getNextStartedActivity())
            .hasAction(Intent.ACTION_VIEW)
            .hasData(redirect);
}
项目:materialistic    文件:AppUtilsTest.java   
@Test
public void testOpenExternalComment() {
    ActivityController<TestListActivity> controller = Robolectric.buildActivity(TestListActivity.class);
    TestListActivity activity = controller.create().start().resume().get();
    AppUtils.openExternal(activity, mock(PopupMenu.class),
            new View(activity), new TestHnItem(1), null);
    assertNull(ShadowAlertDialog.getLatestAlertDialog());
    AppUtils.openExternal(activity, mock(PopupMenu.class),
            new View(activity), new TestHnItem(1) {
                @Override
                public String getUrl() {
                    return String.format(HackerNewsClient.WEB_ITEM_PATH, "1");
                }
            }, null);
    assertNull(ShadowAlertDialog.getLatestAlertDialog());
    controller.destroy();
}
项目:bikeon-android-app    文件:WelcomeActivityTest.java   
@Test
public void whenLocationIsDisabledItShouldShowError() throws Exception {
    // given
    shadowLocationManager.setProviderEnabled(LocationManager.GPS_PROVIDER, false);
    shadowLocationManager.setProviderEnabled(LocationManager.NETWORK_PROVIDER, false);
    welcomeActivity = Robolectric.setupActivity(WelcomeActivity.class);

    String expectedMessage = welcomeActivity.getString(R.string.message_error_location);

    // when
    welcomeActivity.onResume();

    AlertDialog dialog = ShadowAlertDialog.getLatestAlertDialog();
    ShadowAlertDialog shadowAlertDialog = shadowOf(dialog);

    // then
    assertEquals(expectedMessage, shadowAlertDialog.getMessage().toString());
}
项目:Fabric-Example-App-Android    文件:MraidNativeCommandHandlerTest.java   
@Ignore("Mraid 2.0")
@Test
public void showUserDownloadImageAlert_withActivityContext_shouldDisplayAlertDialog() throws Exception {
    response = new TestHttpResponseWithHeaders(200, FAKE_IMAGE_DATA);

    subject.storePicture(context, IMAGE_URI_VALUE, mraidCommandFailureListener);

    AlertDialog alertDialog = ShadowAlertDialog.getLatestAlertDialog();
    ShadowAlertDialog shadowAlertDialog = shadowOf(alertDialog);

    assertThat(alertDialog.isShowing());

    assertThat(shadowAlertDialog.getTitle()).isEqualTo("Save Image");
    assertThat(shadowAlertDialog.getMessage()).isEqualTo("Download image to Picture gallery?");
    assertThat(shadowAlertDialog.isCancelable()).isTrue();

    assertThat(alertDialog.getButton(BUTTON_POSITIVE).hasOnClickListeners());
    assertThat(alertDialog.getButton(BUTTON_NEGATIVE)).isNotNull();
}
项目:Fabric-Example-App-Android    文件:MraidNativeCommandHandlerTest.java   
@Ignore("Mraid 2.0")
@Test
public void showUserDownloadImageAlert_whenCancelClicked_shouldDismissDialog() throws Exception {
    response = new TestHttpResponseWithHeaders(200, FAKE_IMAGE_DATA);

    subject.storePicture(context, IMAGE_URI_VALUE, mraidCommandFailureListener);

    AlertDialog alertDialog = ShadowAlertDialog.getLatestAlertDialog();
    ShadowAlertDialog shadowAlertDialog = shadowOf(alertDialog);

    alertDialog.getButton(BUTTON_NEGATIVE).performClick();
    assertThat(shadowAlertDialog.hasBeenDismissed()).isTrue();

    assertThat(expectedFile.exists()).isFalse();
    assertThat(expectedFile.length()).isEqualTo(0);
}
项目:loafers    文件:ConceptTest.java   
@Test
public void buildingAMagic8Ball() throws Exception {
  Activity app = Robolectric.setupActivity(EightBall.class);

  LinearLayout layout = Helper.fetchAppLayout(app);
  android.widget.TextView text = (TextView) layout.getChildAt(0);
  android.widget.EditText editText = (EditText) layout.getChildAt(1);
  android.widget.Button button = (android.widget.Button) layout.getChildAt(2);

  assertEquals(app.getTitle(), "Magic 8-Ball");
  assertEquals("Ask the 8-Ball a question:", text.getText());
  assertEquals("", editText.getText().toString());
  assertEquals("Shake", button.getText());

  button.performClick();
  ShadowAlertDialog popup = (shadowOf((AlertDialog) ShadowDialog.getLatestDialog()));
  assertTrue(Arrays.asList("Yes!", "No!", "Maybe?").contains(popup.getTitle()));
}
项目:droid-stealth    文件:DirectoryChooserFragmentTest.java   
@Test
public void testCreateDirectoryDialog() {
    final String directoryName = "mydir";
    final DirectoryChooserFragment fragment = DirectoryChooserFragment.newInstance(
            directoryName, null);

    startFragment(fragment, DirectoryChooserActivityMock.class);

    fragment.onOptionsItemSelected(new TestMenuItem() {
        @Override
        public int getItemId() {
            return R.id.new_folder_item;
        }
    });

    final AlertDialog dialog = (AlertDialog) ShadowDialog.getLatestDialog();
    final ShadowAlertDialog shadowAlertDialog = Robolectric.shadowOf(dialog);
    assertEquals(shadowAlertDialog.getTitle(), "Create folder");
    assertEquals(shadowAlertDialog.getMessage(), "Create new folder with name \"mydir\"?");
}
项目:akvo-caddisfly    文件:ChamberTest.java   
@Test
public void textExternalWithoutPermission() {

    Intent intent = new Intent(AppConfig.FLOW_ACTION_CADDISFLY);

    Bundle data = new Bundle();
    data.putString(CADDISFLY_RESOURCE_ID, Constants.FLUORIDE_ID);
    data.putString(CADDISFLY_QUESTION_ID, "123");
    data.putString(CADDISFLY_QUESTION_TITLE, "Fluoride");
    data.putString(CADDISFLY_LANGUAGE, "en");

    intent.putExtras(data);
    intent.setType("text/plain");

    ActivityController controller = Robolectric.buildActivity(TestActivity.class, intent).create();

    controller.start();

    AlertDialog alert = ShadowAlertDialog.getLatestAlertDialog();
    ShadowAlertDialog sAlert = shadowOf(alert);

    assertEquals(sAlert.getMessage(), "Calibration for Water - Fluoride is incomplete\n" +
            "\n" +
            "Do you want to calibrate now?");

}
项目:ello-android    文件:NoInternetActivityTest.java   
@Test
public void tapRefreshShowsAlertWhenInternetNotPresent()
{
    when(reachability.isNetworkConnected()).thenReturn(false);

    button.performClick();
    AlertDialog alert = ShadowAlertDialog.getLatestAlertDialog();
    ShadowAlertDialog sAlert = shadowOf(alert);

    assertThat(sAlert.getTitle().toString(),
            equalTo(activity.getString(R.string.error)));
    assertThat(sAlert.getMessage().toString(),
            equalTo(activity.getString(R.string.couldnt_connect_error)));
}
项目:weex-analyzer-android    文件:JSExceptionCatcherTest.java   
@Test
public void catchException() throws Exception {
    String fakeErrCode = "fake_error_code";
    String fakeMsg = "fake_msg";
    AlertDialog dialog = JSExceptionCatcher.catchException(RuntimeEnvironment.application,null,null,fakeErrCode,fakeMsg);

    assertNotNull(dialog);
    ShadowAlertDialog shadowAlertDialog = shadowOf(dialog);
    assertEquals(dialog.isShowing(),true);
    assertEquals(ShadowAlertDialog.getLatestAlertDialog(),dialog);

    assertEquals("WeexAnalyzer捕捉到异常",shadowAlertDialog.getTitle());
}
项目:Triango    文件:DirectoryChooserFragmentTest.java   
@Test
public void testCreateDirectoryDialogAllowFolderNameModification() {
    final String directoryName = "mydir";
    final DirectoryChooserFragment fragment = DirectoryChooserFragment.newInstance(
            DirectoryChooserConfig.builder()
                    .newDirectoryName(directoryName)
                    .initialDirectory("")
                    .allowReadOnlyDirectory(false)
                    .allowNewDirectoryNameModification(true)
                    .build());

    startFragment(fragment, DirectoryChooserActivityMock.class);

    fragment.onOptionsItemSelected(new TestMenuItem() {
        @Override
        public int getItemId() {
            return R.id.new_folder_item;
        }
    });

    final AlertDialog dialog = (AlertDialog) ShadowDialog.getLatestDialog();
    final ShadowAlertDialog shadowAlertDialog = Shadows.shadowOf(dialog);
    assertThat(shadowAlertDialog.getTitle()).isEqualTo("Create folder");
    assertThat(ShadowDialog.getShownDialogs()).contains(dialog);

    final TextView msgView = (TextView) dialog.findViewById(R.id.msgText);
    assertThat(msgView).hasText("Create new folder with name \"mydir\"?");

    final EditText editText = (EditText) dialog.findViewById(R.id.editText);
    assertThat(editText).isVisible();
    assertThat(editText).hasTextString(directoryName);
}
项目:Triango    文件:DirectoryChooserFragmentTest.java   
@Test
public void testCreateDirectoryDialogDisallowFolderNameModification() {
    final String directoryName = "mydir";
    final DirectoryChooserFragment fragment = DirectoryChooserFragment.newInstance(
            DirectoryChooserConfig.builder()
                    .newDirectoryName(directoryName)
                    .initialDirectory("")
                    .allowReadOnlyDirectory(false)
                    .allowNewDirectoryNameModification(false)
                    .build());

    startFragment(fragment, DirectoryChooserActivityMock.class);

    fragment.onOptionsItemSelected(new TestMenuItem() {
        @Override
        public int getItemId() {
            return R.id.new_folder_item;
        }
    });

    final AlertDialog dialog = (AlertDialog) ShadowDialog.getLatestDialog();
    final ShadowAlertDialog shadowAlertDialog = Shadows.shadowOf(dialog);
    assertThat(shadowAlertDialog.getTitle()).isEqualTo("Create folder");
    assertThat(ShadowDialog.getShownDialogs()).contains(dialog);

    final TextView msgView = (TextView) dialog.findViewById(R.id.msgText);
    assertThat(msgView).hasText("Create new folder with name \"mydir\"?");

    final EditText editText = (EditText) dialog.findViewById(R.id.editText);
    assertThat(editText).isGone();
}
项目: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    文件:SubmitActivityTest.java   
@Test
public void testOnBackPressed() {
    shadowOf(activity).clickMenuItem(android.R.id.home);
    AlertDialog alertDialog = ShadowAlertDialog.getLatestAlertDialog();
    assertNotNull(alertDialog);
    alertDialog.getButton(DialogInterface.BUTTON_POSITIVE).performClick();
    assertThat(activity).isFinishing();
}
项目:materialistic    文件:SubmitActivityTest.java   
@Test
public void testSubmitText() {
    ((EditText) activity.findViewById(R.id.edittext_title)).setText("title");
    ((EditText) activity.findViewById(R.id.edittext_content)).setText("content");
    shadowOf(activity).clickMenuItem(R.id.menu_send);
    AlertDialog alertDialog = ShadowAlertDialog.getLatestAlertDialog();
    assertNotNull(alertDialog);
    assertEquals(activity.getString(R.string.confirm_submit_question),
            shadowOf(alertDialog).getMessage());
}
项目:materialistic    文件:SubmitActivityTest.java   
@Test
public void testSubmitUrl() {
    ((EditText) activity.findViewById(R.id.edittext_title)).setText("title");
    ((EditText) activity.findViewById(R.id.edittext_content)).setText("http://example.com");
    shadowOf(activity).clickMenuItem(R.id.menu_send);
    AlertDialog alertDialog = ShadowAlertDialog.getLatestAlertDialog();
    assertNotNull(alertDialog);
    assertEquals(activity.getString(R.string.confirm_submit_url),
            shadowOf(alertDialog).getMessage());
}
项目:materialistic    文件:SubmitActivityTest.java   
@Test
public void testSubmitFailed() {
    ((EditText) activity.findViewById(R.id.edittext_title)).setText("title");
    ((EditText) activity.findViewById(R.id.edittext_content)).setText("http://example.com");
    shadowOf(activity).clickMenuItem(R.id.menu_send);
    ShadowAlertDialog.getLatestAlertDialog().getButton(DialogInterface.BUTTON_POSITIVE)
            .performClick();
    verify(userServices).submit(any(Context.class), eq("title"), eq("http://example.com"),
            eq(true), submitCallback.capture());
    submitCallback.getValue().onDone(false);
    assertThat(shadowOf(activity).getNextStartedActivity())
            .hasComponent(activity, LoginActivity.class);
}
项目:materialistic    文件:SubmitActivityTest.java   
@Test
public void testSubmitSuccessful() {
    ((EditText) activity.findViewById(R.id.edittext_title)).setText("title");
    ((EditText) activity.findViewById(R.id.edittext_content)).setText("http://example.com");
    shadowOf(activity).clickMenuItem(R.id.menu_send);
    ShadowAlertDialog.getLatestAlertDialog().getButton(DialogInterface.BUTTON_POSITIVE)
            .performClick();
    verify(userServices).submit(any(Context.class), eq("title"), eq("http://example.com"),
            eq(true), submitCallback.capture());
    submitCallback.getValue().onDone(true);
    assertThat(shadowOf(activity).getNextStartedActivity())
            .hasComponent(activity, NewActivity.class);
    assertThat(activity).isFinishing();
}
项目:materialistic    文件:SubmitActivityTest.java   
@Test
public void testSubmitDelayedError() {
    ((EditText) activity.findViewById(R.id.edittext_title)).setText("title");
    ((EditText) activity.findViewById(R.id.edittext_content)).setText("http://example.com");
    shadowOf(activity).clickMenuItem(R.id.menu_send);
    ShadowAlertDialog.getLatestAlertDialog().getButton(DialogInterface.BUTTON_POSITIVE)
            .performClick();
    verify(userServices).submit(any(Context.class), eq("title"), eq("http://example.com"),
            eq(true), submitCallback.capture());
    shadowOf(activity).clickMenuItem(android.R.id.home);
    ShadowAlertDialog.getLatestAlertDialog().getButton(DialogInterface.BUTTON_POSITIVE)
            .performClick();
    submitCallback.getValue().onError(new IOException());
    assertEquals(activity.getString(R.string.submit_failed), ShadowToast.getTextOfLatestToast());
}
项目:materialistic    文件:SubmitActivityTest.java   
@Test
public void testSubmitDelayedFailed() {
    ((EditText) activity.findViewById(R.id.edittext_title)).setText("title");
    ((EditText) activity.findViewById(R.id.edittext_content)).setText("http://example.com");
    shadowOf(activity).clickMenuItem(R.id.menu_send);
    ShadowAlertDialog.getLatestAlertDialog().getButton(DialogInterface.BUTTON_POSITIVE)
            .performClick();
    verify(userServices).submit(any(Context.class), eq("title"), eq("http://example.com"),
            eq(true), submitCallback.capture());
    shadowOf(activity).clickMenuItem(android.R.id.home);
    ShadowAlertDialog.getLatestAlertDialog().getButton(DialogInterface.BUTTON_POSITIVE)
            .performClick();
    submitCallback.getValue().onDone(false);
    assertNull(shadowOf(activity).getNextStartedActivity());
}
项目:materialistic    文件:SubmitActivityTest.java   
@Test
public void testSubmitDelayedSuccessful() {
    ((EditText) activity.findViewById(R.id.edittext_title)).setText("title");
    ((EditText) activity.findViewById(R.id.edittext_content)).setText("http://example.com");
    shadowOf(activity).clickMenuItem(R.id.menu_send);
    ShadowAlertDialog.getLatestAlertDialog().getButton(DialogInterface.BUTTON_POSITIVE)
            .performClick();
    verify(userServices).submit(any(Context.class), eq("title"), eq("http://example.com"),
            eq(true), submitCallback.capture());
    shadowOf(activity).clickMenuItem(android.R.id.home);
    ShadowAlertDialog.getLatestAlertDialog().getButton(DialogInterface.BUTTON_POSITIVE)
            .performClick();
    submitCallback.getValue().onDone(true);
    assertNull(shadowOf(activity).getNextStartedActivity());
}
项目:materialistic    文件:ComposeActivityTest.java   
@Test
public void testExitSaveDraft() {
    ((EditText) activity.findViewById(R.id.edittext_body)).setText("Reply");
    shadowOf(activity).clickMenuItem(android.R.id.home);
    AlertDialog alertDialog = ShadowAlertDialog.getLatestAlertDialog();
    assertNotNull(alertDialog);
    alertDialog.getButton(DialogInterface.BUTTON_POSITIVE).performClick();
    assertThat(activity).isFinishing();
    assertThat(Preferences.getDraft(activity, "1")).contains("Reply");
}
项目:materialistic    文件:ComposeActivityTest.java   
@Test
public void testExitDiscardDraft() {
    ((EditText) activity.findViewById(R.id.edittext_body)).setText("Reply");
    shadowOf(activity).clickMenuItem(android.R.id.home);
    AlertDialog alertDialog = ShadowAlertDialog.getLatestAlertDialog();
    assertNotNull(alertDialog);
    alertDialog.getButton(DialogInterface.BUTTON_NEGATIVE).performClick();
    assertThat(activity).isFinishing();
    assertThat(Preferences.getDraft(activity, "1")).isNullOrEmpty();
}
项目:materialistic    文件:AppUtilsTest.java   
@Test
public void testShareComment() {
    AppUtils.share(RuntimeEnvironment.application, mock(PopupMenu.class),
            new View(RuntimeEnvironment.application), new TestHnItem(1));
    assertNull(ShadowAlertDialog.getLatestAlertDialog());
    AppUtils.share(RuntimeEnvironment.application, mock(PopupMenu.class),
            new View(RuntimeEnvironment.application), new TestHnItem(1) {
                @Override
                public String getUrl() {
                    return String.format(HackerNewsClient.WEB_ITEM_PATH, "1");
                }
            });
    assertNull(ShadowAlertDialog.getLatestAlertDialog());
}
项目: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    文件:SettingsActivityTest.java   
@Test
public void testClearRecentSearches() {
    ShadowSearchRecentSuggestions.historyClearCount = 0;
    assertNotNull(shadowOf(activity).getOptionsMenu().findItem(R.id.menu_clear_recent));
    shadowOf(activity).clickMenuItem(R.id.menu_clear_recent);
    AlertDialog alertDialog = ShadowAlertDialog.getLatestAlertDialog();
    assertNotNull(alertDialog);
    alertDialog.getButton(DialogInterface.BUTTON_POSITIVE).performClick();
    assertEquals(1, ShadowSearchRecentSuggestions.historyClearCount);
}
项目:materialistic    文件:SettingsActivityTest.java   
@Test
public void testReset() {
    PreferenceManager.getDefaultSharedPreferences(activity)
            .edit()
            .putBoolean(activity.getString(R.string.pref_color_code), false)
            .apply();
    assertFalse(Preferences.colorCodeEnabled(activity));
    assertNotNull(shadowOf(activity).getOptionsMenu().findItem(R.id.menu_reset));
    shadowOf(activity).clickMenuItem(R.id.menu_reset);
    AlertDialog alertDialog = ShadowAlertDialog.getLatestAlertDialog();
    assertNotNull(alertDialog);
    alertDialog.getButton(DialogInterface.BUTTON_POSITIVE).performClick();
    assertTrue(Preferences.colorCodeEnabled(activity));
}
项目:AluShare    文件:ContactTabFragmentTest.java   
@Test
public void testContextMenu4() {
    adapter.updateDataSet(contacts);
    RecyclerView.ViewHolder viewHolder = adapter.onCreateViewHolder(recyclerView, 0);
    adapter.onBindViewHolder(viewHolder, 0);
    try {
        viewHolder.itemView.performLongClick(); // Danke Robolectric. NullPointer weil irgendwas mit Menu buggy..
    } catch (NullPointerException e) {
        //Nichts tun.
    }

    Contact contact = contacts.get(0);
    RoboMenuItem item = new RoboMenuItem(R.id.context_tab_contact_link_to_contact);
    item.setGroupId(R.id.context_tab_contact_group);
    fragment.onContextItemSelected(item);

    android.support.v7.app.AlertDialog dialog = (android.support.v7.app.AlertDialog) ShadowAlertDialog.getLatestDialog();
    ListView listView = dialog.getListView();
    Shadows.shadowOf(listView).performItemClick(0);
    ShadowActivity shadowActivity = Shadows.shadowOf(activity);
    Intent i = shadowActivity.getNextStartedActivityForResult().intent;
    assertNotNull(i);

    fragment.onContextItemSelected(item);
    dialog = (android.support.v7.app.AlertDialog) ShadowAlertDialog.getLatestDialog();
    listView = dialog.getListView();
    Shadows.shadowOf(listView).performItemClick(1);
    i = shadowActivity.getNextStartedActivityForResult().intent;
    assertNotNull(i);
}
项目:AluShare    文件:FileTabFragmentTest.java   
@Test
public void testContextMenu2()  {
    adapter.updateDataSet(files);

    RecyclerView.ViewHolder viewHolder = adapter.onCreateViewHolder(recyclerView, 0);
    adapter.onBindViewHolder(viewHolder, 0);
    try {
        viewHolder.itemView.performLongClick(); // Danke Robolectric. NullPointer weil irgendwas mit Menu buggy..
    } catch (NullPointerException e) {
        //Nichts tun.
    }
    RoboMenuItem item = new RoboMenuItem(R.id.context_tab_file_rename);
    item.setGroupId(R.id.context_tab_file_group);

    fragment.onContextItemSelected(item);

    android.support.v7.app.AlertDialog dialog = (android.support.v7.app.AlertDialog) ShadowAlertDialog.getLatestDialog();

    Button b = dialog.getButton(Dialog.BUTTON_POSITIVE);
    EditText editText = (EditText) dialog.findViewById(R.id.alter_dialog_edit);
    editText.setText("neuerName");
    b.performClick();

    files = helper.getFiles();
    String newName = files.get(0).getASName();
    assertEquals("neuerName", newName);

    fragment.onContextItemSelected(item);
    dialog = (android.support.v7.app.AlertDialog) ShadowAlertDialog.getLatestDialog();
    b = dialog.getButton(Dialog.BUTTON_NEGATIVE);
    b.performClick();
    assertFalse(dialog.isShowing());

}
项目:AluShare    文件:ChatTabFragmentTest.java   
@Test
public void testContextRename() {
    adapter.updateDataSet(chats);
    String newTitle = "NewTitle";
    RecyclerView.ViewHolder viewHolder = adapter.onCreateViewHolder(recyclerView, 0);
    adapter.onBindViewHolder(viewHolder, 0);
    try {
        viewHolder.itemView.performLongClick(); // Danke Robolectric. NullPointer weil irgendwas mit Menu buggy..
    } catch (NullPointerException e) {
        //Nichts tun.
    }

    RoboMenuItem item = new RoboMenuItem(R.id.context_tab_chat_rename);
    item.setGroupId(R.id.context_tab_chat_group);

    fragment.onContextItemSelected(item);
    android.support.v7.app.AlertDialog dialog = (android.support.v7.app.AlertDialog) ShadowAlertDialog.getLatestDialog();

    Button b = dialog.getButton(Dialog.BUTTON_POSITIVE);
    EditText editText = (EditText) dialog.findViewById(R.id.alter_dialog_edit);
    editText.setText(newTitle);
    b.performClick();

    chats = helper.getChats();
    Chat chat = chats.get(0);
    assertEquals(chat.getTitle(), newTitle);

    b = dialog.getButton(Dialog.BUTTON_NEGATIVE);
    b.performClick();
    assertFalse(dialog.isShowing());
}
项目:rides-android-sdk    文件:RideRequestActivityTest.java   
@Test
public void onLoad_whenLoginErrorOccurs_shouldReturnErrorResultIntent() {
    ShadowActivity shadowActivity = shadowOf(activity);
    activity.onLoginError(AuthenticationError.MISMATCHING_REDIRECT_URI);
    ShadowAlertDialog shadowAlertDialog = shadowOf(activity.authenticationErrorDialog);

    String message = "There was a problem authenticating you.";
    assertEquals(message, shadowAlertDialog.getMessage());
    activity.authenticationErrorDialog.getButton(AlertDialog.BUTTON_POSITIVE).performClick();

    Assert.assertNotNull(shadowActivity.getResultIntent());
    assertEquals(shadowActivity.getResultCode(), Activity.RESULT_CANCELED);
    assertEquals(AuthenticationError.MISMATCHING_REDIRECT_URI, shadowActivity.getResultIntent().getSerializableExtra
            (RideRequestActivity.AUTHENTICATION_ERROR));
}
项目:rides-android-sdk    文件:RideRequestActivityTest.java   
@Test
public void onLoad_whenSomeRideRequestViewErrorOccurs_shouldReturnResultIntentError() {
    ShadowActivity shadowActivity = shadowOf(activity);
    activity.onErrorReceived(RideRequestViewError.UNKNOWN);
    ShadowAlertDialog shadowAlertDialog = shadowOf(activity.rideRequestErrorDialog);

    String message = "The Ride Request Widget encountered a problem.";
    assertEquals(message, shadowAlertDialog.getMessage());
    activity.rideRequestErrorDialog.getButton(AlertDialog.BUTTON_POSITIVE).performClick();

    assertNotNull(shadowActivity.getResultIntent());
    assertEquals(Activity.RESULT_CANCELED, shadowActivity.getResultCode());
    assertEquals(RideRequestViewError.UNKNOWN, shadowActivity.getResultIntent().getSerializableExtra
            (RideRequestActivity.RIDE_REQUEST_ERROR));
}
项目:rides-android-sdk    文件:RideRequestActivityTest.java   
@Test
public void onLoad_whenErrorOccursAndUserHitsBackWhenAlertShows_shouldReturnResultIntentError() {
    ShadowActivity shadowActivity = shadowOf(activity);
    activity.onErrorReceived(RideRequestViewError.UNKNOWN);
    ShadowAlertDialog shadowAlertDialog = shadowOf(activity.rideRequestErrorDialog);

    String message = "The Ride Request Widget encountered a problem.";
    assertEquals(message, shadowAlertDialog.getMessage());
    activity.rideRequestErrorDialog.onBackPressed();

    assertNotNull(shadowActivity.getResultIntent());
    assertEquals(Activity.RESULT_CANCELED, shadowActivity.getResultCode());
    assertEquals(RideRequestViewError.UNKNOWN, shadowActivity.getResultIntent().getSerializableExtra
            (RideRequestActivity.RIDE_REQUEST_ERROR));
}
项目:lmis-moz-mobile    文件:StockMovementViewHolderTest.java   
@Test
public void shouldShowMovementTypeDialogOnClick() {
    viewModel.setDraft(true);
    viewHolder.populate(viewModel, stockCard);

    viewHolder.txReason.performClick();

    AlertDialog typeDialog = ShadowAlertDialog.getLatestAlertDialog();
    assertNotNull(typeDialog);
}
项目:fogger    文件:DialogWithBlurredBackgroundLauncherTest.java   
@Test
public void shouldShowGivenDialog() {
    //when
    mDialogWithBlurredBackgroundLauncher.showDialog(dialog);

    //then
    AlertDialog alert = ShadowAlertDialog.getLatestAlertDialog();
    assertThat(dialog).isEqualTo(alert);
}