NewPipeExtractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubePlaylistExtractorTes...

117 lines
4.1 KiB
Java
Raw Normal View History

2017-08-06 22:20:15 +02:00
package org.schabi.newpipe.extractor.services.youtube;
import org.junit.BeforeClass;
2017-08-06 22:20:15 +02:00
import org.junit.Test;
import org.schabi.newpipe.Downloader;
import org.schabi.newpipe.extractor.ListExtractor;
2017-08-06 22:20:15 +02:00
import org.schabi.newpipe.extractor.NewPipe;
2017-11-25 03:13:26 +01:00
import org.schabi.newpipe.extractor.stream.StreamInfoItem;
import java.util.List;
2017-08-06 22:20:15 +02:00
import static org.junit.Assert.*;
2017-11-25 03:13:26 +01:00
import static org.schabi.newpipe.extractor.ExtractorAsserts.assertEmptyErrors;
2017-08-07 18:12:51 +02:00
import static org.schabi.newpipe.extractor.ServiceList.YouTube;
2017-08-06 22:20:15 +02:00
/**
2017-11-25 03:13:26 +01:00
* Test for {@link YoutubePlaylistExtractor}
2017-08-06 22:20:15 +02:00
*/
public class YoutubePlaylistExtractorTest {
private static YoutubePlaylistExtractor extractor;
2017-11-25 03:13:26 +01:00
private static void assertNotEmpty(String message, String value) {
assertNotNull(message, value);
assertFalse(message, value.isEmpty());
}
2017-08-06 22:20:15 +02:00
@BeforeClass
public static void setUp() throws Exception {
2017-08-06 22:20:15 +02:00
NewPipe.init(Downloader.getInstance());
2017-11-25 03:13:26 +01:00
extractor = (YoutubePlaylistExtractor) YouTube.getService()
2017-08-06 22:20:15 +02:00
.getPlaylistExtractor("https://www.youtube.com/playlist?list=PL7XlqX4npddfrdpMCxBnNZXg2GFll7t5y");
}
@Test
public void testGetDownloader() throws Exception {
2017-08-06 22:20:15 +02:00
assertNotNull(NewPipe.getDownloader());
}
@Test
public void testGetId() throws Exception {
2017-08-11 03:23:09 +02:00
assertEquals(extractor.getId(), "PL7XlqX4npddfrdpMCxBnNZXg2GFll7t5y");
2017-08-06 22:20:15 +02:00
}
@Test
public void testGetName() throws Exception {
2017-08-11 03:23:09 +02:00
assertEquals(extractor.getName(), "important videos");
2017-08-06 22:20:15 +02:00
}
@Test
2017-08-08 23:36:11 +02:00
public void testGetThumbnailUrl() throws Exception {
assertTrue(extractor.getThumbnailUrl(), extractor.getThumbnailUrl().contains("yt"));
2017-08-06 22:20:15 +02:00
}
@Test
public void testGetBannerUrl() throws Exception {
assertTrue(extractor.getBannerUrl(), extractor.getBannerUrl().contains("yt"));
}
@Test
public void testGetUploaderUrl() throws Exception {
assertTrue(extractor.getUploaderUrl(), extractor.getUploaderUrl().contains("youtube.com"));
}
@Test
public void testGetUploaderName() throws Exception {
assertTrue(extractor.getUploaderName(), !extractor.getUploaderName().isEmpty());
}
@Test
public void testGetUploaderAvatarUrl() throws Exception {
assertTrue(extractor.getUploaderAvatarUrl(), extractor.getUploaderAvatarUrl().contains("yt"));
}
@Test
public void testGetStreamsCount() throws Exception {
assertTrue("error in the streams count", extractor.getStreamCount() > 100);
}
@Test
public void testGetStreams() throws Exception {
2017-11-25 03:13:26 +01:00
List<StreamInfoItem> streams = extractor.getStreams().getItemList();
assertFalse("no streams are received", streams.isEmpty());
assertTrue(streams.size() > 60);
assertFalse(streams.contains(null));
for(StreamInfoItem item: streams) {
assertEquals("Service id doesn't match", YouTube.getId(), item.getServiceId());
assertNotNull("Stream type not set: " + item, item.getStreamType());
//assertNotEmpty("Upload date not set: " + item, item.getUploadDate());
assertNotEmpty("Uploader name not set: " + item, item.getUploaderName());
assertNotEmpty("Uploader url not set: " + item, item.getUploaderUrl());
}
2017-08-06 22:20:15 +02:00
}
@Test
public void testGetStreamsErrors() throws Exception {
2017-11-25 03:13:26 +01:00
assertEmptyErrors("errors during stream list extraction", extractor.getStreams().getErrors());
2017-08-06 22:20:15 +02:00
}
@Test
public void testHasMoreStreams() throws Exception {
// Setup the streams
extractor.getStreams();
assertTrue("extractor didn't have more streams", extractor.hasMoreStreams());
}
@Test
public void testGetNextStreams() throws Exception {
// Setup the streams
extractor.getStreams();
ListExtractor.NextItemsResult nextItemsResult = extractor.getNextStreams();
assertTrue("extractor didn't have next streams", !nextItemsResult.nextItemsList.isEmpty());
2017-11-25 03:13:26 +01:00
assertEmptyErrors("errors occurred during extraction of the next streams", nextItemsResult.errors);
2017-08-06 22:20:15 +02:00
assertTrue("extractor didn't have more streams after getNextStreams", extractor.hasMoreStreams());
}
}