本文整理汇总了Java中org.robolectric.shadows.ShadowAlertDialog类的典型用法代码示例。如果您正苦于以下问题:Java ShadowAlertDialog类的具体用法?Java ShadowAlertDialog怎么用?Java ShadowAlertDialog使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ShadowAlertDialog类属于org.robolectric.shadows包,在下文中一共展示了ShadowAlertDialog类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testOptionsMenuClear
import org.robolectric.shadows.ShadowAlertDialog; //导入依赖的package包/类
@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());
}
示例2: testDelete
import org.robolectric.shadows.ShadowAlertDialog; //导入依赖的package包/类
@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());
}
示例3: testNoExistingAccount
import org.robolectric.shadows.ShadowAlertDialog; //导入依赖的package包/类
@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();
}
示例4: testExistingAccount
import org.robolectric.shadows.ShadowAlertDialog; //导入依赖的package包/类
@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);
}
示例5: testAddAccount
import org.robolectric.shadows.ShadowAlertDialog; //导入依赖的package包/类
@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);
}
示例6: testSubmitError
import org.robolectric.shadows.ShadowAlertDialog; //导入依赖的package包/类
@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);
}
示例7: testOpenExternalComment
import org.robolectric.shadows.ShadowAlertDialog; //导入依赖的package包/类
@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();
}
示例8: whenLocationIsDisabledItShouldShowError
import org.robolectric.shadows.ShadowAlertDialog; //导入依赖的package包/类
@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());
}
示例9: showUserDownloadImageAlert_withActivityContext_shouldDisplayAlertDialog
import org.robolectric.shadows.ShadowAlertDialog; //导入依赖的package包/类
@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();
}
示例10: showUserDownloadImageAlert_whenCancelClicked_shouldDismissDialog
import org.robolectric.shadows.ShadowAlertDialog; //导入依赖的package包/类
@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);
}
示例11: buildingAMagic8Ball
import org.robolectric.shadows.ShadowAlertDialog; //导入依赖的package包/类
@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()));
}
示例12: testCreateDirectoryDialog
import org.robolectric.shadows.ShadowAlertDialog; //导入依赖的package包/类
@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\"?");
}
示例13: textExternalWithoutPermission
import org.robolectric.shadows.ShadowAlertDialog; //导入依赖的package包/类
@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?");
}
示例14: tapRefreshShowsAlertWhenInternetNotPresent
import org.robolectric.shadows.ShadowAlertDialog; //导入依赖的package包/类
@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)));
}
示例15: catchException
import org.robolectric.shadows.ShadowAlertDialog; //导入依赖的package包/类
@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());
}