MessageViewAdapter extends BaseAdapter { @Nullable @Override public Object getItem(int position) { if (position >= items.size() || position < 0) { return null; } return items.get(position); } MessageViewAdapter(@NonNull Context context, int layout); @Override int getCount(); @Nullable @Override Object getItem(int position); @Override long getItemId(int position); @NonNull @Override View getView(int position, @Nullable View convertView, @Nullable ViewGroup parent); void set(@NonNull Collection<Message> collection); @Override boolean hasStableIds();  }
@Test public void testGetItem() { assertNull(messageViewAdapter.getItem(0)); assertNull(messageViewAdapter.getItem(-1)); messageViewAdapter.set(Arrays.asList(MessageCenterTestUtils.createMessage("id-0", null, false), MessageCenterTestUtils.createMessage("id-1", null, false))); assertEquals("id-0", ((Message) messageViewAdapter.getItem(0)).getMessageId()); assertEquals("id-1", ((Message) messageViewAdapter.getItem(1)).getMessageId()); assertNull(messageViewAdapter.getItem(2)); assertNull(messageViewAdapter.getItem(-1)); }