TweetMediaUtils { public static MediaEntity getVideoEntity(Tweet tweet) { for (MediaEntity mediaEntity : getAllMediaEntities(tweet)) { if (mediaEntity.type != null && isVideoType(mediaEntity)) { return mediaEntity; } } 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 testGetVideoEntity_nullEntities() { final Tweet tweet = new TweetBuilder().setExtendedEntities(null).build(); assertNull(TweetMediaUtils.getVideoEntity(tweet)); }
@Test public void testGetVideoEntity_nullMedia() { final TweetEntities entities = new TweetEntities(null, null, null, null, null); final Tweet tweet = new TweetBuilder().setExtendedEntities(entities).build(); assertNull(TweetMediaUtils.getVideoEntity(tweet)); }
@Test public void testGetVideoEntity_emptyMedia() { final TweetEntities entities = new TweetEntities(null, null, new ArrayList<>(), null, null); final Tweet tweet = new TweetBuilder().setExtendedEntities(entities).build(); assertNull(TweetMediaUtils.getVideoEntity(tweet)); }
@Test public void testGetVideoEntity_hasVideoEntity() { 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().setExtendedEntities(entities).build(); assertEquals(entity, TweetMediaUtils.getVideoEntity(tweet)); }
@Test public void testGetVideoEntity_nonVideoMedia() { 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().setExtendedEntities(entities).build(); assertNull(TweetMediaUtils.getVideoEntity(tweet)); }