Skip to content

Commit 740992a

Browse files
committed
test: yt featured channels extractor
1 parent dc03909 commit 740992a

1 file changed

Lines changed: 170 additions & 0 deletions

File tree

Lines changed: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
package org.schabi.newpipe.extractor.services.youtube;
2+
3+
import static org.junit.jupiter.api.Assertions.assertEquals;
4+
import static org.junit.jupiter.api.Assertions.assertFalse;
5+
import static org.junit.jupiter.api.Assertions.assertThrows;
6+
import static org.junit.jupiter.api.Assertions.assertTrue;
7+
import static org.schabi.newpipe.extractor.ExtractorAsserts.assertContains;
8+
import static org.schabi.newpipe.extractor.ServiceList.YouTube;
9+
import static org.schabi.newpipe.extractor.services.DefaultTests.defaultTestMoreItems;
10+
import static org.schabi.newpipe.extractor.services.DefaultTests.defaultTestRelatedItems;
11+
12+
import org.junit.jupiter.api.Test;
13+
import org.schabi.newpipe.extractor.ExtractorAsserts;
14+
import org.schabi.newpipe.extractor.channel.list.ChannelListExtractor;
15+
import org.schabi.newpipe.extractor.channel.tabs.rendererlist.RendererListInfoItemExtractor;
16+
import org.schabi.newpipe.extractor.exceptions.ContentNotAvailableException;
17+
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
18+
import org.schabi.newpipe.extractor.exceptions.ParsingException;
19+
import org.schabi.newpipe.extractor.playlist.PlaylistInfo;
20+
import org.schabi.newpipe.extractor.services.BaseListExtractorTest;
21+
import org.schabi.newpipe.extractor.services.BasePlaylistExtractorTest;
22+
import org.schabi.newpipe.extractor.services.DefaultSimpleExtractorTest;
23+
import org.schabi.newpipe.extractor.services.youtube.extractors.YoutubeFeaturedChannelListExtractor;
24+
import org.schabi.newpipe.extractor.services.youtube.extractors.YoutubePlaylistExtractor;
25+
import org.schabi.newpipe.extractor.stream.Description;
26+
27+
import java.util.List;
28+
29+
/**
30+
* Test for {@link YoutubeFeaturedChannelListExtractor}
31+
*/
32+
public class YoutubeFeaturedChannelListExtractorTest {
33+
34+
public static class NotAvailable implements InitYoutubeTest {
35+
36+
@Test
37+
void invalidIndex() throws Exception {
38+
final ChannelListExtractor extractor =
39+
YouTube.getChannelListExtractor(
40+
"user/LinusTechTips",
41+
List.of("featured", RendererListInfoItemExtractor
42+
.getRendererListIndexContentFilter(2)),
43+
"https://www.youtube.com");
44+
assertThrows(ExtractionException.class, extractor::fetchPage);
45+
}
46+
}
47+
48+
abstract static class Base extends DefaultSimpleExtractorTest<YoutubeFeaturedChannelListExtractor>
49+
implements BaseListExtractorTest, InitYoutubeTest {
50+
51+
@Override
52+
protected YoutubeFeaturedChannelListExtractor createExtractor() throws Exception {
53+
return (YoutubeFeaturedChannelListExtractor) YouTube.getChannelListExtractor(
54+
this.idForExtraction(),
55+
List.of("featured", RendererListInfoItemExtractor
56+
.getRendererListIndexContentFilter(this.rendererListIndexForExtraction())),
57+
"https://www.youtube.com");
58+
}
59+
60+
protected abstract int rendererListIndexForExtraction();
61+
62+
protected abstract String idForExtraction();
63+
}
64+
65+
public static class LinusTechTips extends YoutubeFeaturedChannelListExtractorTest.Base {
66+
@Override
67+
protected int rendererListIndexForExtraction() {
68+
return 5;
69+
}
70+
71+
@Override
72+
protected String idForExtraction() {
73+
return "user/LinusTechTips";
74+
}
75+
76+
@Override
77+
@Test
78+
public void testServiceId() {
79+
assertEquals(YouTube.getServiceId(), extractor().getServiceId());
80+
}
81+
82+
@Override
83+
@Test
84+
public void testName() throws Exception {
85+
assertTrue(extractor().getName().startsWith("Featured Channels"));
86+
}
87+
88+
@Override
89+
@Test
90+
public void testId() throws Exception {
91+
assertEquals("UCXuqSBlHAE6Xw-yeJA0Tunw", extractor().getId());
92+
}
93+
94+
@Override
95+
@Test
96+
public void testUrl() throws ParsingException {
97+
assertEquals("https://www.youtube.com/channel/UCXuqSBlHAE6Xw-yeJA0Tunw/featured", extractor().getUrl());
98+
}
99+
100+
@Override
101+
@Test
102+
public void testOriginalUrl() throws ParsingException {
103+
assertEquals("https://www.youtube.com/user/LinusTechTips/featured", extractor().getOriginalUrl());
104+
}
105+
106+
@Override
107+
@Test
108+
public void testRelatedItems() throws Exception {
109+
defaultTestRelatedItems(extractor());
110+
}
111+
112+
@Override
113+
public void testMoreRelatedItems() throws Exception {
114+
assertFalse(extractor().getInitialPage().hasNextPage());
115+
}
116+
}
117+
118+
public static class TSeries extends YoutubeFeaturedChannelListExtractorTest.Base {
119+
@Override
120+
protected int rendererListIndexForExtraction() {
121+
return 12;
122+
}
123+
124+
@Override
125+
protected String idForExtraction() {
126+
return "user/tseries";
127+
}
128+
129+
@Override
130+
@Test
131+
public void testServiceId() {
132+
assertEquals(YouTube.getServiceId(), extractor().getServiceId());
133+
}
134+
135+
@Override
136+
@Test
137+
public void testName() throws Exception {
138+
assertTrue(extractor().getName().startsWith("Other Great Channels"));
139+
}
140+
141+
@Override
142+
@Test
143+
public void testId() throws Exception {
144+
assertEquals("UCq-Fj5jknLsUf-MWSy4_brA", extractor().getId());
145+
}
146+
147+
@Override
148+
@Test
149+
public void testUrl() throws ParsingException {
150+
assertEquals("https://www.youtube.com/channel/UCq-Fj5jknLsUf-MWSy4_brA/featured", extractor().getUrl());
151+
}
152+
153+
@Override
154+
@Test
155+
public void testOriginalUrl() throws ParsingException {
156+
assertEquals("https://www.youtube.com/user/tseries/featured", extractor().getOriginalUrl());
157+
}
158+
159+
@Override
160+
@Test
161+
public void testRelatedItems() throws Exception {
162+
defaultTestRelatedItems(extractor());
163+
}
164+
165+
@Override
166+
public void testMoreRelatedItems() throws Exception {
167+
defaultTestMoreItems(extractor());
168+
}
169+
}
170+
}

0 commit comments

Comments
 (0)