MyDeckAdapter extends BaseAdapter implements DeckItem.DeckMenuListener { @Override public View getView(int position, View view, ViewGroup parent) { DeckItem deckItem; Deck deck = getItem(position); if (view == null) { deckItem = new DeckItem(activity); } else { deckItem = (DeckItem) view; } deckItem.setDeck(deck); deckItem.setMenuListener(this); return deckItem; } MyDeckAdapter(Activity context, MyDecksPresenter presenter); @Override int getCount(); @Override Deck getItem(int position); @Override long getItemId(int position); @Override View getView(int position, View view, ViewGroup parent); @Override void onShareClicked(Deck deck); @Override void onDeleteClicked(Deck deck); void setDecks(List<Deck> decks);  }
@Test public void shouldCreateNewViewWhenExistingViewIsNull() { controller = Robolectric.buildActivity(Activity.class); activity = controller.withIntent(new Intent()).create().get(); MyDeckAdapter adapter = new MyDeckAdapter(activity, myDecksPresenter); View view = adapter.getView(0, null, null); TextView deckName = (TextView) view.findViewById(R.id.deck_name); assertEquals(DeckItem.class.getName(), view.getClass().getName()); assertEquals(deck.getTitle(), deckName.getText().toString()); }
@Test public void shouldModifyExistingViewIfViewNotNull() { controller = Robolectric.buildActivity(Activity.class); activity = controller.withIntent(new Intent()).create().get(); MyDeckAdapter adapter = new MyDeckAdapter(activity, myDecksPresenter); DeckItem view = new DeckItem(activity.getApplicationContext()); adapter.getView(0, view, null); TextView deckName = (TextView) view.findViewById(R.id.deck_name); assertEquals(deck.getTitle(), deckName.getText().toString()); }