本文整理匯總了Java中org.robolectric.shadows.ShadowActivity.clickMenuItem方法的典型用法代碼示例。如果您正苦於以下問題:Java ShadowActivity.clickMenuItem方法的具體用法?Java ShadowActivity.clickMenuItem怎麽用?Java ShadowActivity.clickMenuItem使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.robolectric.shadows.ShadowActivity
的用法示例。
在下文中一共展示了ShadowActivity.clickMenuItem方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: clickBackFinishes
import org.robolectric.shadows.ShadowActivity; //導入方法依賴的package包/類
@Test
public void clickBackFinishes() throws IOException
{
File file = new File(Environment.getExternalStorageDirectory(), "test.jpg");
file.createNewFile();
ActivityController controller = startWithFile(file);
Activity activity = (Activity)controller.get();
ShadowActivity shadowActivity = shadowOf(activity);
assertTrue(shadowActivity.isFinishing() == false);
shadowActivity.clickMenuItem(android.R.id.home);
assertTrue(shadowActivity.isFinishing());
// Check that can finish out the lifecycle
controller.pause();
controller.stop();
controller.destroy();
// The done menu item was not clicked, so the result should be that
// the activity was canceled
assertEquals(Activity.RESULT_CANCELED, shadowActivity.getResultCode());
assertNull(shadowActivity.getResultIntent());
}
示例2: clickDeleteFinishes
import org.robolectric.shadows.ShadowActivity; //導入方法依賴的package包/類
@Test
public void clickDeleteFinishes() throws IOException
{
File file = new File(Environment.getExternalStorageDirectory(), "test.jpg");
file.createNewFile();
ActivityController controller = startWithFile(file);
Activity activity = (Activity)controller.get();
ShadowActivity shadowActivity = shadowOf(activity);
assertTrue(shadowActivity.isFinishing() == false);
boolean result = shadowActivity.clickMenuItem(R.id.action_delete);
assertTrue(result);
// Note, cannot finish the test because the v7 AlertDialog
// currently does not have shadow support.
}
示例3: clickBackFinishes
import org.robolectric.shadows.ShadowActivity; //導入方法依賴的package包/類
@Test
public void clickBackFinishes()
{
ActivityController controller = startWithMap(new HashMap<String, Integer>());
Activity activity = (Activity)controller.get();
ShadowActivity shadowActivity = shadowOf(activity);
assertTrue(shadowActivity.isFinishing() == false);
shadowActivity.clickMenuItem(android.R.id.home);
assertTrue(shadowActivity.isFinishing());
// Check that can finish out the lifecycle
controller.pause();
controller.stop();
controller.destroy();
// The done menu item was not clicked, so the result should be that
// the activity was canceled
assertEquals(Activity.RESULT_CANCELED, shadowActivity.getResultCode());
assertNull(shadowActivity.getResultIntent());
}
示例4: doneNoItems
import org.robolectric.shadows.ShadowActivity; //導入方法依賴的package包/類
@Test
public void doneNoItems()
{
HashMap<String, Integer> emptyMap = new HashMap<>();
ActivityController controller = startWithMap(emptyMap);
Activity activity = (Activity)controller.get();
ShadowActivity shadowActivity = shadowOf(activity);
assertTrue(shadowActivity.isFinishing() == false);
shadowActivity.clickMenuItem(R.id.action_done);
assertTrue(shadowActivity.isFinishing());
// Check that can finish out the lifecycle
controller.pause();
controller.stop();
controller.destroy();
checkReturnedMap(activity, emptyMap);
}
示例5: addItem
import org.robolectric.shadows.ShadowActivity; //導入方法依賴的package包/類
private void addItem(Activity activity, String name, Integer value)
{
ShadowActivity shadowActivity = shadowOf(activity);
ListView list = (ListView)activity.findViewById(R.id.list);
assertNotNull(list);
int initialCount = list.getCount();
shadowActivity.clickMenuItem(R.id.action_add);
ItemizationAdapter adapter = (ItemizationAdapter)list.getAdapter();
Itemization listItem = adapter.getItem(initialCount);
assertNotNull(listItem);
listItem.name = name;
listItem.value = value;
assertEquals(initialCount+1, list.getCount());
}
示例6: givenTheLoaderIsFinishedWhenTheShareButtonIsPressedThenTheLoadedListOfRemindersIsShared
import org.robolectric.shadows.ShadowActivity; //導入方法依賴的package包/類
@Test
public void givenTheLoaderIsFinishedWhenTheShareButtonIsPressedThenTheLoadedListOfRemindersIsShared() {
Reminder reminder = new Reminder(0, "test");
Reminder reminder2 = new Reminder(0, "test2");
Cursor mockCursor = mock(Cursor.class);
when(mockCursor.moveToNext()).thenReturn(true).thenReturn(true).thenReturn(false);
when(mockCursor.getLong(0)).thenReturn(reminder.getId()).thenReturn(reminder2.getId());
when(mockCursor.getString(1)).thenReturn(reminder.getText()).thenReturn(reminder2.getText());
ShadowCursorWrapper wrapper = new ShadowCursorWrapper();
wrapper.__constructor__(mockCursor);
CursorLoader cursorLoader = (CursorLoader)activity.onCreateLoader(0, null);
activity.onLoadFinished(cursorLoader, wrapper);
ShadowActivity shadowActivity = Shadows.shadowOf(activity);
shadowActivity.clickMenuItem(R.id.action_share);
ShadowIntent shadowIntent = Shadows.shadowOf(shadowActivity.peekNextStartedActivity());
assertEquals(Intent.ACTION_CHOOSER, shadowIntent.getAction());
ShadowIntent shareIntent = Shadows.shadowOf((Intent) shadowIntent.getParcelableExtra("android.intent.extra.INTENT"));
assertEquals("text/plain", shareIntent.getType());
assertEquals("test\ntest2\n", shareIntent.getExtras().getString(Intent.EXTRA_TEXT));
}
示例7: doneBlankItem
import org.robolectric.shadows.ShadowActivity; //導入方法依賴的package包/類
@Test
public void doneBlankItem()
{
HashMap<String, Integer> emptyMap = new HashMap<>();
ActivityController controller = startWithMap(emptyMap);
Activity activity = (Activity)controller.get();
ShadowActivity shadowActivity = shadowOf(activity);
ListView list = (ListView)activity.findViewById(R.id.list);
assertNotNull(list);
ShadowListView shadowList = shadowOf(list);
shadowList.populateItems();
assertEquals(0, list.getCount());
shadowActivity.clickMenuItem(R.id.action_add);
assertEquals(1, list.getCount());
assertTrue(shadowActivity.isFinishing() == false);
shadowActivity.clickMenuItem(R.id.action_done);
assertTrue(shadowActivity.isFinishing());
// Check that can finish out the lifecycle
controller.pause();
controller.stop();
controller.destroy();
checkReturnedMap(activity, emptyMap);
}
示例8: filledOutItemsNotSaved
import org.robolectric.shadows.ShadowActivity; //導入方法依賴的package包/類
@Test
public void filledOutItemsNotSaved()
{
HashMap<String, Integer> emptyMap = new HashMap<>();
ActivityController controller = startWithMap(emptyMap);
Activity activity = (Activity)controller.get();
ShadowActivity shadowActivity = shadowOf(activity);
Map<String, Integer> addedValues = ImmutableMap.of
(
"test name", 12345
);
addItems(activity, addedValues);
assertTrue(shadowActivity.isFinishing() == false);
shadowActivity.clickMenuItem(android.R.id.home);
assertTrue(shadowActivity.isFinishing());
// Check that can finish out the lifecycle
controller.pause();
controller.stop();
controller.destroy();
// The done menu item was not clicked, so the result should be that
// the activity was canceled
assertEquals(Activity.RESULT_CANCELED, shadowActivity.getResultCode());
assertNull(shadowActivity.getResultIntent());
}
示例9: filledOutItemsClickedDone
import org.robolectric.shadows.ShadowActivity; //導入方法依賴的package包/類
@Test
public void filledOutItemsClickedDone()
{
HashMap<String, Integer> emptyMap = new HashMap<>();
ActivityController controller = startWithMap(emptyMap);
Activity activity = (Activity)controller.get();
ShadowActivity shadowActivity = shadowOf(activity);
Map<String, Integer> addedValues = ImmutableMap.of
(
"test name", 12345,
"test name 2", 44444,
"test name 3", 75412,
"test name 4", 951,
"test name 5", 1
);
addItems(activity, addedValues);
assertTrue(shadowActivity.isFinishing() == false);
shadowActivity.clickMenuItem(R.id.action_done);
assertTrue(shadowActivity.isFinishing());
// Check that can finish out the lifecycle
controller.pause();
controller.stop();
controller.destroy();
checkReturnedMap(activity, addedValues);
}
示例10: filledOutItemsWithDuplicatesClickedDone
import org.robolectric.shadows.ShadowActivity; //導入方法依賴的package包/類
@Test
public void filledOutItemsWithDuplicatesClickedDone()
{
HashMap<String, Integer> emptyMap = new HashMap<>();
ActivityController controller = startWithMap(emptyMap);
Activity activity = (Activity)controller.get();
ShadowActivity shadowActivity = shadowOf(activity);
final String TEST_NAME = "test name";
final int TEST_VALUE = 12345;
for(int index = 0; index < 10; index++)
{
addItem(activity, TEST_NAME, TEST_VALUE);
}
assertTrue(shadowActivity.isFinishing() == false);
shadowActivity.clickMenuItem(R.id.action_done);
assertTrue(shadowActivity.isFinishing());
controller.pause();
controller.stop();
controller.destroy();
// As all the items were duplicates, only one item
// should result.
Map<String, Integer> expectedValues = ImmutableMap.of
(
TEST_NAME, TEST_VALUE
);
checkReturnedMap(activity, expectedValues);
}
示例11: startWithItemsClickedDone
import org.robolectric.shadows.ShadowActivity; //導入方法依賴的package包/類
@Test
public void startWithItemsClickedDone()
{
Map<String, Integer> initialValues = ImmutableMap.of
(
"test name", 12345,
"test name 2", 44444,
"test name 3", 75412,
"test name 4", 951,
"test name 5", 1
);
ActivityController controller = startWithMap(initialValues);
Activity activity = (Activity)controller.get();
ShadowActivity shadowActivity = shadowOf(activity);
assertTrue(shadowActivity.isFinishing() == false);
shadowActivity.clickMenuItem(R.id.action_done);
assertTrue(shadowActivity.isFinishing());
// Check that can finish out the lifecycle
controller.pause();
controller.stop();
controller.destroy();
checkReturnedMap(activity, initialValues);
}
示例12: startWithoutParametersCannotCreateLoyaltyCard
import org.robolectric.shadows.ShadowActivity; //導入方法依賴的package包/類
@Test
public void startWithoutParametersCannotCreateLoyaltyCard()
{
ActivityController activityController = Robolectric.buildActivity(LoyaltyCardViewActivity.class).create();
activityController.start();
activityController.visible();
activityController.resume();
Activity activity = (Activity)activityController.get();
ShadowActivity shadowActivity = shadowOf(activity);
DBHelper db = new DBHelper(activity);
assertEquals(0, db.getLoyaltyCardCount());
final EditText storeField = (EditText) activity.findViewById(R.id.storeNameEdit);
final EditText noteField = (EditText) activity.findViewById(R.id.noteEdit);
final TextView cardIdField = (TextView) activity.findViewById(R.id.cardIdView);
shadowActivity.clickMenuItem(R.id.action_save);
assertEquals(0, db.getLoyaltyCardCount());
storeField.setText("store");
shadowActivity.clickMenuItem(R.id.action_save);
assertEquals(0, db.getLoyaltyCardCount());
noteField.setText("note");
shadowActivity.clickMenuItem(R.id.action_save);
assertEquals(0, db.getLoyaltyCardCount());
cardIdField.setText("cardId");
shadowActivity.clickMenuItem(R.id.action_save);
assertEquals(0, db.getLoyaltyCardCount());
}
示例13: whenTheStoresActionBarButtonIsPressedThenTheGroceryStoresActivityIsStarted
import org.robolectric.shadows.ShadowActivity; //導入方法依賴的package包/類
@Test
public void whenTheStoresActionBarButtonIsPressedThenTheGroceryStoresActivityIsStarted() {
ShadowActivity shadowActivity = Shadows.shadowOf(activity);
shadowActivity.clickMenuItem(R.id.action_find_stores);
Intent startedIntent = shadowActivity.peekNextStartedActivity();
assertEquals(GroceryStoresActivity.class.getName(), startedIntent.getComponent().getClassName());
}
示例14: whenTheStoresActionBarButtonIsPressedThenTheGroceryLocatorServiceIsStarted
import org.robolectric.shadows.ShadowActivity; //導入方法依賴的package包/類
@Test
public void whenTheStoresActionBarButtonIsPressedThenTheGroceryLocatorServiceIsStarted() {
ShadowActivity shadowActivity = Shadows.shadowOf(activity);
shadowActivity.clickMenuItem(R.id.action_find_stores);
Intent startedIntent = shadowActivity.peekNextStartedService();
assertEquals(GroceryLocatorService.class.getName(), startedIntent.getComponent().getClassName());
assertTrue(startedIntent.getBooleanExtra(GroceryReminderConstants.LISTEN_FOR_GPS_EXTRA, false));
}
示例15: invalidAppInstall
import org.robolectric.shadows.ShadowActivity; //導入方法依賴的package包/類
/**
* Test that trying to install an app with an invalid suite file results in
* the appropriate error message and a pinned notification with more
* details
*/
@Test
public void invalidAppInstall() {
String invalidUpdateReference = "jr://resource/commcare-apps/update_tests/invalid_suite_update/profile.ccpr";
// start the setup activity
Intent setupIntent =
new Intent(RuntimeEnvironment.application, CommCareSetupActivity.class);
CommCareSetupActivity setupActivity =
Robolectric.buildActivity(CommCareSetupActivity.class)
.withIntent(setupIntent).setup().get();
// click the 'offline install' menu item
ShadowActivity shadowActivity = Shadows.shadowOf(setupActivity);
shadowActivity.clickMenuItem(CommCareSetupActivity.MENU_ARCHIVE);
// make sure there are no pinned notifications
NotificationManager notificationManager =
(NotificationManager)RuntimeEnvironment.application.getSystemService(Context.NOTIFICATION_SERVICE);
Notification notification = Shadows.shadowOf(notificationManager).getNotification(CommCareNoficationManager.MESSAGE_NOTIFICATION);
assertNull(notification);
// mock receiving the offline app reference and start the install
Intent referenceIntent = new Intent();
referenceIntent.putExtra(InstallArchiveActivity.ARCHIVE_JR_REFERENCE, invalidUpdateReference);
shadowActivity.receiveResult(shadowActivity.getNextStartedActivity(), Activity.RESULT_OK, referenceIntent);
Robolectric.flushBackgroundThreadScheduler();
Robolectric.flushForegroundThreadScheduler();
// assert that we get the right error message
assertTrue(setupActivity.getErrorMessageToDisplay().contains(Localization.get("notification.install.invalid.title")));
// check that a pinned notification was created for invalid update
// NOTE: it is way more work to assert the notification body is correct, so skip over that
notification = Shadows.shadowOf(notificationManager).getNotification(CommCareNoficationManager.MESSAGE_NOTIFICATION);
assertNotNull(notification);
}