當前位置: 首頁>>代碼示例>>Java>>正文


Java ShadowActivity.clickMenuItem方法代碼示例

本文整理匯總了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());
}
 
開發者ID:brarcher,項目名稱:rental-calc,代碼行數:25,代碼來源:PictureViewActivityTest.java

示例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.
}
 
開發者ID:brarcher,項目名稱:rental-calc,代碼行數:18,代碼來源:PictureViewActivityTest.java

示例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());
}
 
開發者ID:brarcher,項目名稱:rental-calc,代碼行數:22,代碼來源:ItemizationActivityTest.java

示例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);
}
 
開發者ID:brarcher,項目名稱:rental-calc,代碼行數:20,代碼來源:ItemizationActivityTest.java

示例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());
}
 
開發者ID:brarcher,項目名稱:rental-calc,代碼行數:18,代碼來源:ItemizationActivityTest.java

示例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));
}
 
開發者ID:jameskbride,項目名稱:grocery-reminder,代碼行數:24,代碼來源:RemindersActivityTest.java

示例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);
}
 
開發者ID:brarcher,項目名稱:rental-calc,代碼行數:30,代碼來源:ItemizationActivityTest.java

示例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());
}
 
開發者ID:brarcher,項目名稱:rental-calc,代碼行數:30,代碼來源:ItemizationActivityTest.java

示例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);
}
 
開發者ID:brarcher,項目名稱:rental-calc,代碼行數:31,代碼來源:ItemizationActivityTest.java

示例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);
}
 
開發者ID:brarcher,項目名稱:rental-calc,代碼行數:34,代碼來源:ItemizationActivityTest.java

示例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);
}
 
開發者ID:brarcher,項目名稱:rental-calc,代碼行數:28,代碼來源:ItemizationActivityTest.java

示例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());
}
 
開發者ID:brarcher,項目名稱:loyalty-card-locker,代碼行數:33,代碼來源:LoyaltyCardViewActivityTest.java

示例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());
}
 
開發者ID:jameskbride,項目名稱:grocery-reminder,代碼行數:10,代碼來源:RemindersActivityTest.java

示例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));
}
 
開發者ID:jameskbride,項目名稱:grocery-reminder,代碼行數:11,代碼來源:RemindersActivityTest.java

示例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);
}
 
開發者ID:dimagi,項目名稱:commcare-android,代碼行數:44,代碼來源:CommCareSetupActivityTest.java


注:本文中的org.robolectric.shadows.ShadowActivity.clickMenuItem方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。