TweetMediaUtils { public static MediaEntity getPhotoEntity(Tweet tweet) { final List<MediaEntity> mediaEntityList = getAllMediaEntities(tweet); for (int i = mediaEntityList.size() - 1; i >= 0; i--) { final MediaEntity entity = mediaEntityList.get(i); if (entity.type != null && isPhotoType(entity)) { return entity; } } return null; } private  TweetMediaUtils(); static MediaEntity getPhotoEntity(Tweet tweet); static List<MediaEntity> getPhotoEntities(Tweet tweet); static boolean hasPhoto(Tweet tweet); static MediaEntity getVideoEntity(Tweet tweet); static boolean hasSupportedVideo(Tweet tweet); static VideoInfo.Variant getSupportedVariant(MediaEntity mediaEntity); static boolean isLooping(MediaEntity mediaEntity); static boolean showVideoControls(MediaEntity mediaEntity); static final String PHOTO_TYPE; static final String VIDEO_TYPE; static final String GIF_TYPE; }
@Test public void testGetPhotoEntity_nullEntities() { final Tweet tweet = new TweetBuilder().setEntities(null).build(); assertNull(TweetMediaUtils.getPhotoEntity(tweet)); }
@Test public void testGetPhotoEntity_nullMedia() { final TweetEntities entities = new TweetEntities(null, null, null, null, null); final Tweet tweet = new TweetBuilder().setEntities(entities).build(); assertNull(TweetMediaUtils.getPhotoEntity(tweet)); }
@Test public void testGetPhotoEntity_emptyMedia() { final TweetEntities entities = new TweetEntities(null, null, new ArrayList<>(), null, null); final Tweet tweet = new TweetBuilder().setEntities(entities).build(); assertNull(TweetMediaUtils.getPhotoEntity(tweet)); }
@Test public void testGetPhotoEntity_hasFinalPhotoEntity() { final MediaEntity entity = TestFixtures.newMediaEntity(TEST_INDICES_START, TEST_INDICES_END, TEST_MEDIA_TYPE_PHOTO); final ArrayList<MediaEntity> media = new ArrayList<>(); media.add(entity); final TweetEntities entities = new TweetEntities(null, null, media, null, null); final Tweet tweet = new TweetBuilder().setEntities(entities).build(); assertEquals(entity, TweetMediaUtils.getPhotoEntity(tweet)); }
@Test public void testGetPhotoEntity_nonPhotoMedia() { final MediaEntity entity = TestFixtures.newMediaEntity(TEST_INDICES_START, TEST_INDICES_END, TEST_MEDIA_TYPE_VIDEO); final ArrayList<MediaEntity> media = new ArrayList<>(); media.add(entity); final TweetEntities entities = new TweetEntities(null, null, media, null, null); final Tweet tweet = new TweetBuilder().setEntities(entities).build(); assertNull(TweetMediaUtils.getPhotoEntity(tweet)); }