FeedsAdapter extends BaseAdapter { @Override public View getView(int position, View recycledView, ViewGroup parent) { if (recycledView == null) { recycledView = inflater.inflate(R.layout.feed_list_item, parent, false); } TextView textView = (TextView) recycledView.findViewById(R.id.feed_title); textView.setText(getItem(position).getTitle()); return recycledView; } FeedsAdapter(List<Feed> feeds, LayoutInflater inflater); @Override int getCount(); @Override Feed getItem(int position); @Override long getItemId(int position); @Override View getView(int position, View recycledView, ViewGroup parent);  }
@Test public void itInflatesView() { List<Feed> feeds = givenFeeds(new Feed()); FeedsAdapter feedsAdapter = givenAdapaterWith(feeds); View view = feedsAdapter.getView(firstPosition, recycledView, parent); assertNotNull(view); }
@Test public void itDoesNotInflateViewWhenViewIsAlreadySet() { List<Feed> feeds = givenFeeds(new Feed()); FeedsAdapter feedsAdapter = givenAdapaterWith(feeds); recycledView = spiedLayoutInflater.inflate(R.layout.feed_list_item, parent, false); feedsAdapter.getView(firstPosition, recycledView, parent); feedsAdapter.getView(firstPosition, recycledView, parent); feedsAdapter.getView(firstPosition, recycledView, parent); verify(spiedLayoutInflater, times(1)).inflate(R.layout.feed_list_item, parent, false); }