GalleryAdapter extends PagerAdapter { @Override public Object instantiateItem(ViewGroup container, int position) { final GalleryImageView root = new GalleryImageView(context); root.setSwipeToDismissCallback(callback); container.addView(root); final MediaEntity entity = items.get(position); Picasso.with(context).load(entity.mediaUrlHttps).into(root); return root; } GalleryAdapter(Context context, SwipeToDismissTouchListener.Callback callback); @Override int getCount(); @Override boolean isViewFromObject(View view, Object object); @Override Object instantiateItem(ViewGroup container, int position); @Override void destroyItem(ViewGroup container, int position, Object object);  }
@Test public void testInstantiateItem() { subject.addAll(Collections.singletonList(entity)); final GalleryImageView result = (GalleryImageView) subject.instantiateItem(container, 0); assertNotNull(result); verify(container).addView(result); }