项目: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",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);
}
@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,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,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()));
}
@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\"?");
}
@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,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",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();
}
@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();
}
@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());
}
@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());
}
@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),submitCallback.capture());
submitCallback.getValue().onDone(false);
assertthat(shadowOf(activity).getNextStartedActivity())
.hasComponent(activity,LoginActivity.class);
}
@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),submitCallback.capture());
submitCallback.getValue().onDone(true);
assertthat(shadowOf(activity).getNextStartedActivity())
.hasComponent(activity,NewActivity.class);
assertthat(activity).isFinishing();
}
@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),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());
}
@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),submitCallback.capture());
shadowOf(activity).clickMenuItem(android.R.id.home);
ShadowAlertDialog.getLatestAlertDialog().getButton(DialogInterface.BUTTON_POSITIVE)
.performClick();
submitCallback.getValue().onDone(false);
assertNull(shadowOf(activity).getNextStartedActivity());
}
@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),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,new View(RuntimeEnvironment.application),new TestHnItem(1));
assertNull(ShadowAlertDialog.getLatestAlertDialog());
AppUtils.share(RuntimeEnvironment.application,"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);
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);
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.getResultIntent().getSerializableExtra
(RideRequestActivity.RIDE_REQUEST_ERROR));
}
项目:lmis-moz-mobile
文件:StockMovementViewHolderTest.java
项目:fogger
文件:DialogWithBlurredBackgroundLauncherTest.java
@Test
public void shouldShowGivendialog() {
//when
mDialogWithBlurredBackgroundLauncher.showDialog(dialog);
//then
AlertDialog alert = ShadowAlertDialog.getLatestAlertDialog();
assertthat(dialog).isEqualTo(alert);
}