Java 类org.robolectric.shadows.ShadowListView 实例源码

项目:rental-calc    文件:ItemizationActivityTest.java   
private void addItems(Activity activity, Map<String, Integer> items)
{
    ListView list = (ListView)activity.findViewById(R.id.list);
    assertNotNull(list);

    ShadowListView shadowList = shadowOf(list);
    shadowList.populateItems();

    int initialCount = list.getCount();

    for(Map.Entry<String, Integer> item : items.entrySet())
    {
        addItem(activity, item.getKey(), item.getValue());
    }

    assertEquals(initialCount + items.size(), list.getCount());
}
项目:budget-watch    文件:MainActivityTest.java   
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);
}
项目:commcare-android    文件:FormRecordListActivityTest.java   
public static void openASavedForm(int expectedFormCount, int formIndexToSelect) {
    Intent savedFormsIntent =
            new Intent(RuntimeEnvironment.application, FormRecordListActivity.class);
    ShadowActivity homeActivityShadow = prepSavedFormsActivity(savedFormsIntent);

    FormRecordListActivity savedFormsActivity =
            Robolectric.buildActivity(FormRecordListActivity.class)
                    .withIntent(savedFormsIntent).create().start()
                    .resume().get();

    // wait for saved forms to load
    Robolectric.flushBackgroundThreadScheduler();
    Robolectric.flushForegroundThreadScheduler();

    ShadowListView shadowEntityList = assertSavedFormEntries(expectedFormCount, savedFormsActivity);
    shadowEntityList.performItemClick(formIndexToSelect);

    launchFormEntryForSavedForm(homeActivityShadow, savedFormsIntent, savedFormsActivity);
}
项目:Awwl    文件:DashboardViewImplActivityTest.java   
/**
 * test interface redirect {@link #showTransactionList()}
 * @param mTransactionList
 */
@Override
public void showTransactionList(List mTransactionList) {
    // prepare
    List<TransactionFields> list = MockTransaction.fakeTransactionList();
    // test
    DashboardView dashboardView = getTestObj();
    dashboardView.showTransactionList(list);
    ListView listView = getField(dashboardView, ReflectionId.listView);
    ListAdapter listAdapter = listView.getAdapter();
    ShadowListView shadowListView = shadowOf(listView);
    shadowListView.populateItems();
    // verify
    int i = 0;
    for (TransactionFields transactionFields : list) {
        ViewTransactionFields viewTransactionFields = (ViewTransactionFields) listAdapter.getItem(i);
        compareObj(transactionFields, viewTransactionFields.getTransactionFields());
        i++;
    }
}
项目:rental-calc    文件:PropertiesListActivityTest.java   
@Test
public void clickPropertyLaunchesActivity()
{
    db.insertProperty(new Property());
    ActivityController controller = Robolectric.buildActivity(PropertiesListActivity.class).create();
    Activity activity = (Activity)controller.get();

    controller.start();
    controller.visible();
    controller.resume();

    ListView list = (ListView)activity.findViewById(R.id.list);
    ShadowListView shadowList = shadowOf(list);

    shadowList.populateItems();

    assertEquals(1, list.getCount());
    shadowList.performItemClick(0);

    assertTrue(activity.isFinishing() == false);

    Intent next = shadowOf(activity).getNextStartedActivity();

    ComponentName componentName = next.getComponent();
    String name = componentName.flattenToShortString();
    assertEquals("protect.rentalcalc/.PropertyOverviewActivity", name);

    Bundle extras = next.getExtras();
    assertNotNull(extras);
    assertTrue(extras.containsKey("id"));
    assertEquals(DatabaseTestHelper.FIRST_ID, extras.getLong("id"));
}
项目:rental-calc    文件:ItemizationActivityTest.java   
@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);
}
项目:budget-watch    文件:BudgetActivityTest.java   
@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);
}
项目:tarcle-tdd    文件:TopicFragmentTest.java   
@Test
public void shouldShowContentInListView() {
    ShadowListView shadowListView = shadowOf(topicFragment.getListView());

    int index = shadowListView.findIndexOfItemContainingText("Topic 1 content");
    assertThat(index).isEqualTo(0);
}
项目:tarcle-tdd    文件:NavigationDrawerFragmentTest.java   
@Test
public void shouldInvokeCallbackWhenItemIsClicked() {
    RootActivity spyActivity = spy(Robolectric.buildActivity(RootActivity.class).create().start().resume().get());
    fragment.onAttach(spyActivity);

    int position = 2;
    ShadowListView shadowListView = shadowOf(fragment.mDrawerListView);
    shadowListView.performItemClick(position);
    verify(spyActivity).onNavigationDrawerItemSelected(eq(position));
}
项目:tarcle-tdd    文件:CircleFragmentTest.java   
@Test
public void shouldShowCircleNameInListItem() {
    ShadowListView shadowListView = shadowOf(circleFragment.getListView());

    int position = shadowListView.findIndexOfItemContainingText("Circle Tang");
    assertThat(position).isEqualTo(1);
}
项目:commcare-android    文件:FormRecordListActivityTest.java   
private static ShadowListView assertSavedFormEntries(int expectedFormCount,
                                                     FormRecordListActivity savedFormActivity) {
    ListView entityList =
            (ListView)savedFormActivity.findViewById(R.id.screen_entity_select_list);
    IncompleteFormListAdapter adapter =
            (IncompleteFormListAdapter)entityList.getAdapter();
    adapter.setFormFilter(FormRecordListActivity.FormRecordFilter.Submitted);
    adapter.resetRecords();
    assertEquals(expectedFormCount, adapter.getCount());
    return Shadows.shadowOf(entityList);
}
项目:commcare-android    文件:CaseLoadUtils.java   
public static EntityListAdapter loadList(EntitySelectActivity entitySelectActivity) {
    // wait for entities to load
    Robolectric.flushBackgroundThreadScheduler();
    Robolectric.flushForegroundThreadScheduler();

    ListView entityList =
            (ListView)entitySelectActivity.findViewById(R.id.screen_entity_select_list);
    EntityListAdapter adapter = (EntityListAdapter)entityList.getAdapter();

    ShadowListView shadowListView = Shadows.shadowOf(entityList);
    shadowListView.populateItems();
    return adapter;
}
项目:the-blue-alliance-android    文件:FragmentTestDriver.java   
public static void testListViewClick(ListViewFragment fragment, List<ListItem> items, Class expectedActivity) {
    Activity activity = FragmentTestDriver.bindData(fragment, items);

    ListView listView = FragmentTestDriver.getListView(fragment);
    ShadowListView shadowList = Shadows.shadowOf(listView);
    ShadowActivity shadowActivity = Shadows.shadowOf(activity);

    shadowList.performItemClick(0);
    assertNotNull(shadowActivity.peekNextStartedActivity());
    assertEquals(shadowActivity.peekNextStartedActivity().getComponent(),
            new ComponentName(activity, expectedActivity));

    activity.finish();
}
项目:foul-android    文件:FoulTest.java   
private void testMenuClick(final int index, final Class<?> expected) {
    ShadowListView list = shadowOf_(foul.getListView());
    assertThat(list.performItemClick(index), is(true));

    ShadowActivity activity = shadowOf_(foul);
    ShadowIntent intent = shadowOf_(activity.getNextStartedActivity());
    assertThat(intent.getIntentClass().getName(), equalTo(expected.getName()));
}
项目:FullRobolectricTestSample    文件:Robolectric.java   
public static ShadowListView shadowOf(ListView instance) {
  return (ShadowListView) shadowOf_(instance);
}