Some tests extension

This commit is contained in:
Coffeemakr 2017-11-25 03:13:26 +01:00
parent 95120641a9
commit c9eb790d1c
No known key found for this signature in database
GPG Key ID: 3F35676D8FF6E743
4 changed files with 47 additions and 12 deletions

View File

@ -0,0 +1,14 @@
package org.schabi.newpipe.extractor;
import java.util.List;
public class ExtractorAsserts {
public static void assertEmptyErrors(String message, List<Throwable> errors) {
if(!errors.isEmpty()) {
for (Throwable throwable : errors) {
message += "\n * " + throwable.getMessage();
}
throw new AssertionError(message, errors.get(0));
}
}
}

View File

@ -7,7 +7,10 @@ import org.schabi.newpipe.extractor.ListExtractor;
import org.schabi.newpipe.extractor.NewPipe; import org.schabi.newpipe.extractor.NewPipe;
import org.schabi.newpipe.extractor.channel.ChannelExtractor; import org.schabi.newpipe.extractor.channel.ChannelExtractor;
import java.util.List;
import static org.junit.Assert.*; import static org.junit.Assert.*;
import static org.schabi.newpipe.extractor.ExtractorAsserts.assertEmptyErrors;
import static org.schabi.newpipe.extractor.ServiceList.YouTube; import static org.schabi.newpipe.extractor.ServiceList.YouTube;
/* /*
@ -35,12 +38,12 @@ import static org.schabi.newpipe.extractor.ServiceList.YouTube;
*/ */
public class YoutubeChannelExtractorTest { public class YoutubeChannelExtractorTest {
ChannelExtractor extractor; YoutubeChannelExtractor extractor;
@Before @Before
public void setUp() throws Exception { public void setUp() throws Exception {
NewPipe.init(Downloader.getInstance()); NewPipe.init(Downloader.getInstance());
extractor = YouTube.getService() extractor = (YoutubeChannelExtractor) YouTube.getService()
.getChannelExtractor("https://www.youtube.com/user/Gronkh"); .getChannelExtractor("https://www.youtube.com/user/Gronkh");
} }
@ -91,7 +94,7 @@ public class YoutubeChannelExtractorTest {
@Test @Test
public void testGetStreamsErrors() throws Exception { public void testGetStreamsErrors() throws Exception {
assertTrue("errors during stream list extraction", extractor.getStreams().getErrors().isEmpty()); assertEmptyErrors("errors during stream list extraction", extractor.getStreams().getErrors());
} }
@Test @Test
@ -112,7 +115,7 @@ public class YoutubeChannelExtractorTest {
extractor.getStreams(); extractor.getStreams();
ListExtractor.NextItemsResult nextItemsResult = extractor.getNextStreams(); ListExtractor.NextItemsResult nextItemsResult = extractor.getNextStreams();
assertTrue("extractor didn't have next streams", !nextItemsResult.nextItemsList.isEmpty()); assertTrue("extractor didn't have next streams", !nextItemsResult.nextItemsList.isEmpty());
assertTrue("errors occurred during extraction of the next streams", nextItemsResult.errors.isEmpty()); assertEmptyErrors("errors occurred during extraction of the next streams", nextItemsResult.errors);
assertTrue("extractor didn't have more streams after getNextStreams", extractor.hasMoreStreams()); assertTrue("extractor didn't have more streams after getNextStreams", extractor.hasMoreStreams());
} }
} }

View File

@ -6,21 +6,29 @@ import org.schabi.newpipe.Downloader;
import org.schabi.newpipe.extractor.ListExtractor; import org.schabi.newpipe.extractor.ListExtractor;
import org.schabi.newpipe.extractor.NewPipe; import org.schabi.newpipe.extractor.NewPipe;
import org.schabi.newpipe.extractor.playlist.PlaylistExtractor; import org.schabi.newpipe.extractor.playlist.PlaylistExtractor;
import org.schabi.newpipe.extractor.stream.StreamInfoItem;
import java.util.List;
import static org.junit.Assert.*; import static org.junit.Assert.*;
import static org.schabi.newpipe.extractor.ExtractorAsserts.assertEmptyErrors;
import static org.schabi.newpipe.extractor.ServiceList.YouTube; import static org.schabi.newpipe.extractor.ServiceList.YouTube;
/** /**
* Test for {@link PlaylistExtractor} * Test for {@link YoutubePlaylistExtractor}
*/ */
public class YoutubePlaylistExtractorTest { public class YoutubePlaylistExtractorTest {
private PlaylistExtractor extractor; private YoutubePlaylistExtractor extractor;
private static void assertNotEmpty(String message, String value) {
assertNotNull(message, value);
assertFalse(message, value.isEmpty());
}
@Before @Before
public void setUp() throws Exception { public void setUp() throws Exception {
NewPipe.init(Downloader.getInstance()); NewPipe.init(Downloader.getInstance());
extractor = YouTube.getService() extractor = (YoutubePlaylistExtractor) YouTube.getService()
.getPlaylistExtractor("https://www.youtube.com/playlist?list=PL7XlqX4npddfrdpMCxBnNZXg2GFll7t5y"); .getPlaylistExtractor("https://www.youtube.com/playlist?list=PL7XlqX4npddfrdpMCxBnNZXg2GFll7t5y");
} }
@ -71,12 +79,22 @@ public class YoutubePlaylistExtractorTest {
@Test @Test
public void testGetStreams() throws Exception { public void testGetStreams() throws Exception {
assertTrue("no streams are received", !extractor.getStreams().getItemList().isEmpty()); 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());
}
} }
@Test @Test
public void testGetStreamsErrors() throws Exception { public void testGetStreamsErrors() throws Exception {
assertTrue("errors during stream list extraction", extractor.getStreams().getErrors().isEmpty()); assertEmptyErrors("errors during stream list extraction", extractor.getStreams().getErrors());
} }
@Test @Test
@ -92,7 +110,7 @@ public class YoutubePlaylistExtractorTest {
extractor.getStreams(); extractor.getStreams();
ListExtractor.NextItemsResult nextItemsResult = extractor.getNextStreams(); ListExtractor.NextItemsResult nextItemsResult = extractor.getNextStreams();
assertTrue("extractor didn't have next streams", !nextItemsResult.nextItemsList.isEmpty()); assertTrue("extractor didn't have next streams", !nextItemsResult.nextItemsList.isEmpty());
assertTrue("errors occurred during extraction of the next streams", nextItemsResult.errors.isEmpty()); assertEmptyErrors("errors occurred during extraction of the next streams", nextItemsResult.errors);
assertTrue("extractor didn't have more streams after getNextStreams", extractor.hasMoreStreams()); assertTrue("extractor didn't have more streams after getNextStreams", extractor.hasMoreStreams());
} }

View File

@ -44,7 +44,7 @@ public class YoutubeStreamExtractorRestrictedTest {
@Test @Test
public void testGetAgeLimit() throws ParsingException { public void testGetAgeLimit() throws ParsingException {
assertTrue(extractor.getAgeLimit() == 18); assertEquals(18, extractor.getAgeLimit());
} }
@Test @Test