/** * Simulates a click on the {@code Dialog} item indicated by {@code index}. Handles both multi- and single-choice dialogs, tracks which items are currently * checked and calls listeners appropriately. * * @param index the index of the item to click on */ public void clickOnItem(int index) { ShadowListView shadowListView = Shadow.extract(realAlertDialog.getListView()); shadowListView.performItemClick(index); }
/** * Simulates a click on the {@code Dialog} item indicated by {@code index}. Handles both multi- and single-choice dialogs, tracks which items are currently * checked and calls listeners appropriately. * * @param index the index of the item to click on */ public void clickOnItem(int index) { ShadowListView shadowListView = Shadow.extract(realAlertDialog.getListView()); shadowListView.performItemClick(index); }
/** * Simulates a click on the {@code Dialog} item indicated by {@code index}. Handles both multi- and single-choice dialogs, tracks which items are currently * checked and calls listeners appropriately. * * @param index the index of the item to click on */ public void clickOnItem(int index) { Shadows.shadowOf(realAlertDialog.getListView()).performItemClick(index); }
/** * Simulates a click on the {@code Dialog} item indicated by {@code index}. Handles both multi- and single-choice dialogs, tracks which items are currently * checked and calls listeners appropriately. * * @param index the index of the item to click on */ public void clickOnItem(int index) { Shadows.shadowOf(realAlertDialog.getListView()).performItemClick(index); }
/** * Simulates a click on the {@code Dialog} item indicated by {@code index}. Handles both multi- and single-choice dialogs, tracks which items are currently * checked and calls listeners appropriately. * * @param index the index of the item to click on */ public void clickOnItem(int index) { Shadows.shadowOf(realAlertDialog.getListView()).performItemClick(index); }
private void testItemClickLaunchesActivity(int index, String expectedActivity) { ActivityController activityController = Robolectric.buildActivity(MainActivity.class).create(); Activity activity = (Activity)activityController.get(); activityController.start(); activityController.resume(); ListView list = (ListView)activity.findViewById(R.id.list); ShadowListView shadowList = shadowOf(list); shadowList.populateItems(); // First item should be the Budgets, second should be Transactions shadowList.performItemClick(index); testNextStartedActivity(activity, expectedActivity); }
@Test public void clickOnBudget() { ActivityController activityController = Robolectric.buildActivity(BudgetActivity.class).create(); Activity activity = (Activity)activityController.get(); DBHelper db = new DBHelper(activity); db.insertBudget("name", 100); db.close(); activityController.start(); activityController.resume(); ListView list = (ListView)activity.findViewById(R.id.list); ShadowListView shadowList = shadowOf(list); shadowList.populateItems(); shadowList.performItemClick(0); ShadowActivity shadowActivity = shadowOf(activity); Intent startedIntent = shadowActivity.getNextStartedActivity(); ComponentName name = startedIntent.getComponent(); assertEquals("protect.budgetwatch/.TransactionActivity", name.flattenToShortString()); Bundle bundle = startedIntent.getExtras(); String budget = bundle.getString("budget"); assertEquals("name", budget); } }