mirror of
https://github.com/TeamNewPipe/NewPipeExtractor.git
synced 2025-04-27 15:30:34 +05:30
YouTube 100% Mock coverage
This commit is contained in:
parent
3b34b82e0f
commit
69d5bf2a89
@ -473,7 +473,7 @@ public class YoutubeChannelExtractorTest {
|
||||
@BeforeAll
|
||||
public static void setUp() throws Exception {
|
||||
YoutubeTestsUtils.ensureStateless();
|
||||
NewPipe.init(DownloaderFactory.getDownloader(RESOURCE_PATH + "kurzgesagtAdditional"));
|
||||
NewPipe.init(DownloaderFactory.getDownloader(RESOURCE_PATH + "kurzgesagtAdditional1"));
|
||||
extractor = (YoutubeChannelExtractor) YouTube.getChannelExtractor(
|
||||
"https://www.youtube.com/channel/UCsXVk37bltHxD1rDPwtNM8Q");
|
||||
extractor.fetchPage();
|
||||
@ -483,7 +483,10 @@ public class YoutubeChannelExtractorTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetPageInNewExtractor() throws Exception {
|
||||
void testGetPageInNewExtractor() throws Exception {
|
||||
// Init downloader again for mock as otherwise request confusion occurs when using Mock
|
||||
NewPipe.init(DownloaderFactory.getDownloader(RESOURCE_PATH + "kurzgesagtAdditional2"));
|
||||
|
||||
final ChannelExtractor newExtractor = YouTube.getChannelExtractor(extractor.getUrl());
|
||||
newExtractor.fetchPage();
|
||||
final ChannelTabExtractor newTabExtractor = YouTube.getChannelTabExtractor(
|
||||
|
@ -13,34 +13,41 @@ import java.io.IOException;
|
||||
|
||||
class YoutubeJavaScriptExtractorTest {
|
||||
private static final String RESOURCE_PATH =
|
||||
DownloaderFactory.RESOURCE_PATH + "services/youtube/extractor/js_extractor";
|
||||
DownloaderFactory.RESOURCE_PATH + "services/youtube/extractor/js_extractor/";
|
||||
|
||||
@BeforeEach
|
||||
public void setup() throws IOException {
|
||||
public void setup() {
|
||||
YoutubeTestsUtils.ensureStateless();
|
||||
NewPipe.init(DownloaderFactory.getDownloader(RESOURCE_PATH));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testExtractJavaScriptUrlIframe() throws ParsingException {
|
||||
NewPipe.init(DownloaderFactory.getDownloader(RESOURCE_PATH + "urlWithIframeResource"));
|
||||
|
||||
assertTrue(YoutubeJavaScriptExtractor.extractJavaScriptUrlWithIframeResource()
|
||||
.endsWith("base.js"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testExtractJavaScriptUrlEmbed() throws ParsingException {
|
||||
NewPipe.init(DownloaderFactory.getDownloader(RESOURCE_PATH + "embedWatchPage"));
|
||||
|
||||
assertTrue(YoutubeJavaScriptExtractor.extractJavaScriptUrlWithEmbedWatchPage("d4IGg5dqeO8")
|
||||
.endsWith("base.js"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testExtractJavaScript__success() throws ParsingException {
|
||||
NewPipe.init(DownloaderFactory.getDownloader(RESOURCE_PATH + "playerCode"));
|
||||
|
||||
final String playerJsCode = YoutubeJavaScriptExtractor.extractJavaScriptPlayerCode("d4IGg5dqeO8");
|
||||
assertPlayerJsCode(playerJsCode);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testExtractJavaScript__invalidVideoId__success() throws ParsingException {
|
||||
NewPipe.init(DownloaderFactory.getDownloader(RESOURCE_PATH + "playerCodeInvalidVideoId"));
|
||||
|
||||
String playerJsCode = YoutubeJavaScriptExtractor.extractJavaScriptPlayerCode("not_a_video_id");
|
||||
assertPlayerJsCode(playerJsCode);
|
||||
|
||||
|
@ -68,14 +68,14 @@ public class YoutubeStreamExtractorDefaultTest {
|
||||
public static final String YOUTUBE_LICENCE = "YouTube licence";
|
||||
|
||||
public static class NotAvailable {
|
||||
@BeforeAll
|
||||
public static void setUp() throws IOException {
|
||||
YoutubeTestsUtils.ensureStateless();
|
||||
NewPipe.init(DownloaderFactory.getDownloader(RESOURCE_PATH + "notAvailable"));
|
||||
}
|
||||
private static final String RESOURCE_PATH =
|
||||
YoutubeStreamExtractorDefaultTest.RESOURCE_PATH + "notAvailable/";
|
||||
|
||||
@Test
|
||||
void geoRestrictedContent() throws Exception {
|
||||
YoutubeTestsUtils.ensureStateless();
|
||||
NewPipe.init(DownloaderFactory.getDownloader(RESOURCE_PATH + "restricted"));
|
||||
|
||||
final StreamExtractor extractor =
|
||||
YouTube.getStreamExtractor(BASE_URL + "_PL2HJKxnOM");
|
||||
assertThrows(GeographicRestrictionException.class, extractor::fetchPage);
|
||||
@ -83,6 +83,9 @@ public class YoutubeStreamExtractorDefaultTest {
|
||||
|
||||
@Test
|
||||
void nonExistentFetch() throws Exception {
|
||||
YoutubeTestsUtils.ensureStateless();
|
||||
NewPipe.init(DownloaderFactory.getDownloader(RESOURCE_PATH + "nonExistent"));
|
||||
|
||||
final StreamExtractor extractor =
|
||||
YouTube.getStreamExtractor(BASE_URL + "don-t-exist");
|
||||
assertThrows(ContentNotAvailableException.class, extractor::fetchPage);
|
||||
@ -90,6 +93,9 @@ public class YoutubeStreamExtractorDefaultTest {
|
||||
|
||||
@Test
|
||||
void invalidId() throws Exception {
|
||||
YoutubeTestsUtils.ensureStateless();
|
||||
NewPipe.init(DownloaderFactory.getDownloader(RESOURCE_PATH + "invalidId"));
|
||||
|
||||
final StreamExtractor extractor =
|
||||
YouTube.getStreamExtractor(BASE_URL + "INVALID_ID_INVALID_ID");
|
||||
assertThrows(ParsingException.class, extractor::fetchPage);
|
||||
@ -97,6 +103,9 @@ public class YoutubeStreamExtractorDefaultTest {
|
||||
|
||||
@Test
|
||||
void paidContent() throws Exception {
|
||||
YoutubeTestsUtils.ensureStateless();
|
||||
NewPipe.init(DownloaderFactory.getDownloader(RESOURCE_PATH + "paidContent"));
|
||||
|
||||
final StreamExtractor extractor =
|
||||
YouTube.getStreamExtractor(BASE_URL + "ayI2iBwGdxw");
|
||||
assertThrows(PaidContentException.class, extractor::fetchPage);
|
||||
@ -104,6 +113,9 @@ public class YoutubeStreamExtractorDefaultTest {
|
||||
|
||||
@Test
|
||||
void privateContent() throws Exception {
|
||||
YoutubeTestsUtils.ensureStateless();
|
||||
NewPipe.init(DownloaderFactory.getDownloader(RESOURCE_PATH + "privateContent"));
|
||||
|
||||
final StreamExtractor extractor =
|
||||
YouTube.getStreamExtractor(BASE_URL + "8VajtrESJzA");
|
||||
assertThrows(PrivateContentException.class, extractor::fetchPage);
|
||||
@ -111,6 +123,9 @@ public class YoutubeStreamExtractorDefaultTest {
|
||||
|
||||
@Test
|
||||
void youtubeMusicPremiumContent() throws Exception {
|
||||
YoutubeTestsUtils.ensureStateless();
|
||||
NewPipe.init(DownloaderFactory.getDownloader(RESOURCE_PATH + "musicPremiumContent"));
|
||||
|
||||
final StreamExtractor extractor =
|
||||
YouTube.getStreamExtractor(BASE_URL + "sMJ8bRN2dak");
|
||||
assertThrows(YoutubeMusicPremiumContentException.class, extractor::fetchPage);
|
||||
|
Loading…
x
Reference in New Issue
Block a user