Skip to content

Commit 69d5bf2

Browse files
committed
YouTube 100% Mock coverage
1 parent 3b34b82 commit 69d5bf2

3 files changed

Lines changed: 35 additions & 10 deletions

File tree

extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeChannelExtractorTest.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,7 @@ public static class KurzgesagtAdditional {
473473
@BeforeAll
474474
public static void setUp() throws Exception {
475475
YoutubeTestsUtils.ensureStateless();
476-
NewPipe.init(DownloaderFactory.getDownloader(RESOURCE_PATH + "kurzgesagtAdditional"));
476+
NewPipe.init(DownloaderFactory.getDownloader(RESOURCE_PATH + "kurzgesagtAdditional1"));
477477
extractor = (YoutubeChannelExtractor) YouTube.getChannelExtractor(
478478
"https://www.youtube.com/channel/UCsXVk37bltHxD1rDPwtNM8Q");
479479
extractor.fetchPage();
@@ -483,7 +483,10 @@ public static void setUp() throws Exception {
483483
}
484484

485485
@Test
486-
public void testGetPageInNewExtractor() throws Exception {
486+
void testGetPageInNewExtractor() throws Exception {
487+
// Init downloader again for mock as otherwise request confusion occurs when using Mock
488+
NewPipe.init(DownloaderFactory.getDownloader(RESOURCE_PATH + "kurzgesagtAdditional2"));
489+
487490
final ChannelExtractor newExtractor = YouTube.getChannelExtractor(extractor.getUrl());
488491
newExtractor.fetchPage();
489492
final ChannelTabExtractor newTabExtractor = YouTube.getChannelTabExtractor(

extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeJavaScriptExtractorTest.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,34 +13,41 @@
1313

1414
class YoutubeJavaScriptExtractorTest {
1515
private static final String RESOURCE_PATH =
16-
DownloaderFactory.RESOURCE_PATH + "services/youtube/extractor/js_extractor";
16+
DownloaderFactory.RESOURCE_PATH + "services/youtube/extractor/js_extractor/";
1717

1818
@BeforeEach
19-
public void setup() throws IOException {
19+
public void setup() {
2020
YoutubeTestsUtils.ensureStateless();
21-
NewPipe.init(DownloaderFactory.getDownloader(RESOURCE_PATH));
2221
}
2322

2423
@Test
2524
void testExtractJavaScriptUrlIframe() throws ParsingException {
25+
NewPipe.init(DownloaderFactory.getDownloader(RESOURCE_PATH + "urlWithIframeResource"));
26+
2627
assertTrue(YoutubeJavaScriptExtractor.extractJavaScriptUrlWithIframeResource()
2728
.endsWith("base.js"));
2829
}
2930

3031
@Test
3132
void testExtractJavaScriptUrlEmbed() throws ParsingException {
33+
NewPipe.init(DownloaderFactory.getDownloader(RESOURCE_PATH + "embedWatchPage"));
34+
3235
assertTrue(YoutubeJavaScriptExtractor.extractJavaScriptUrlWithEmbedWatchPage("d4IGg5dqeO8")
3336
.endsWith("base.js"));
3437
}
3538

3639
@Test
3740
void testExtractJavaScript__success() throws ParsingException {
41+
NewPipe.init(DownloaderFactory.getDownloader(RESOURCE_PATH + "playerCode"));
42+
3843
final String playerJsCode = YoutubeJavaScriptExtractor.extractJavaScriptPlayerCode("d4IGg5dqeO8");
3944
assertPlayerJsCode(playerJsCode);
4045
}
4146

4247
@Test
4348
void testExtractJavaScript__invalidVideoId__success() throws ParsingException {
49+
NewPipe.init(DownloaderFactory.getDownloader(RESOURCE_PATH + "playerCodeInvalidVideoId"));
50+
4451
String playerJsCode = YoutubeJavaScriptExtractor.extractJavaScriptPlayerCode("not_a_video_id");
4552
assertPlayerJsCode(playerJsCode);
4653

extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/stream/YoutubeStreamExtractorDefaultTest.java

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,49 +68,64 @@ public class YoutubeStreamExtractorDefaultTest {
6868
public static final String YOUTUBE_LICENCE = "YouTube licence";
6969

7070
public static class NotAvailable {
71-
@BeforeAll
72-
public static void setUp() throws IOException {
73-
YoutubeTestsUtils.ensureStateless();
74-
NewPipe.init(DownloaderFactory.getDownloader(RESOURCE_PATH + "notAvailable"));
75-
}
71+
private static final String RESOURCE_PATH =
72+
YoutubeStreamExtractorDefaultTest.RESOURCE_PATH + "notAvailable/";
7673

7774
@Test
7875
void geoRestrictedContent() throws Exception {
76+
YoutubeTestsUtils.ensureStateless();
77+
NewPipe.init(DownloaderFactory.getDownloader(RESOURCE_PATH + "restricted"));
78+
7979
final StreamExtractor extractor =
8080
YouTube.getStreamExtractor(BASE_URL + "_PL2HJKxnOM");
8181
assertThrows(GeographicRestrictionException.class, extractor::fetchPage);
8282
}
8383

8484
@Test
8585
void nonExistentFetch() throws Exception {
86+
YoutubeTestsUtils.ensureStateless();
87+
NewPipe.init(DownloaderFactory.getDownloader(RESOURCE_PATH + "nonExistent"));
88+
8689
final StreamExtractor extractor =
8790
YouTube.getStreamExtractor(BASE_URL + "don-t-exist");
8891
assertThrows(ContentNotAvailableException.class, extractor::fetchPage);
8992
}
9093

9194
@Test
9295
void invalidId() throws Exception {
96+
YoutubeTestsUtils.ensureStateless();
97+
NewPipe.init(DownloaderFactory.getDownloader(RESOURCE_PATH + "invalidId"));
98+
9399
final StreamExtractor extractor =
94100
YouTube.getStreamExtractor(BASE_URL + "INVALID_ID_INVALID_ID");
95101
assertThrows(ParsingException.class, extractor::fetchPage);
96102
}
97103

98104
@Test
99105
void paidContent() throws Exception {
106+
YoutubeTestsUtils.ensureStateless();
107+
NewPipe.init(DownloaderFactory.getDownloader(RESOURCE_PATH + "paidContent"));
108+
100109
final StreamExtractor extractor =
101110
YouTube.getStreamExtractor(BASE_URL + "ayI2iBwGdxw");
102111
assertThrows(PaidContentException.class, extractor::fetchPage);
103112
}
104113

105114
@Test
106115
void privateContent() throws Exception {
116+
YoutubeTestsUtils.ensureStateless();
117+
NewPipe.init(DownloaderFactory.getDownloader(RESOURCE_PATH + "privateContent"));
118+
107119
final StreamExtractor extractor =
108120
YouTube.getStreamExtractor(BASE_URL + "8VajtrESJzA");
109121
assertThrows(PrivateContentException.class, extractor::fetchPage);
110122
}
111123

112124
@Test
113125
void youtubeMusicPremiumContent() throws Exception {
126+
YoutubeTestsUtils.ensureStateless();
127+
NewPipe.init(DownloaderFactory.getDownloader(RESOURCE_PATH + "musicPremiumContent"));
128+
114129
final StreamExtractor extractor =
115130
YouTube.getStreamExtractor(BASE_URL + "sMJ8bRN2dak");
116131
assertThrows(YoutubeMusicPremiumContentException.class, extractor::fetchPage);

0 commit comments

Comments
 (0)