Skip to content

Commit 345e136

Browse files
committed
create YouTubeCommentsLinkHandlerFactoryTest
and remove invidious test from YouTubeCommentsExtractorTest, because it was just testing if the URL is accepted, then the extractor does the same thing, we don't need to test the same thing twice
1 parent 564a965 commit 345e136

2 files changed

Lines changed: 73 additions & 16 deletions

File tree

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
package org.schabi.newpipe.extractor.services.youtube;
2+
3+
import org.junit.BeforeClass;
4+
import org.junit.Test;
5+
import org.schabi.newpipe.DownloaderTestImpl;
6+
import org.schabi.newpipe.extractor.NewPipe;
7+
import org.schabi.newpipe.extractor.exceptions.ParsingException;
8+
import org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubeCommentsLinkHandlerFactory;
9+
10+
import static org.junit.Assert.assertEquals;
11+
import static org.junit.Assert.assertFalse;
12+
import static org.junit.Assert.assertTrue;
13+
14+
public class YouTubeCommentsLinkHandlerFactoryTest {
15+
16+
private static YoutubeCommentsLinkHandlerFactory linkHandler;
17+
18+
@BeforeClass
19+
public static void setUp() {
20+
NewPipe.init(DownloaderTestImpl.getInstance());
21+
linkHandler = YoutubeCommentsLinkHandlerFactory.getInstance();
22+
}
23+
24+
@Test(expected = IllegalArgumentException.class)
25+
public void getIdWithNullAsUrl() throws ParsingException {
26+
linkHandler.fromId(null);
27+
}
28+
29+
@Test
30+
public void getIdFromYt() throws ParsingException {
31+
assertEquals("VM_6n762j6M", linkHandler.fromUrl("https://www.youtube.com/watch?v=VM_6n762j6M").getId());
32+
assertEquals("VM_6n762j6M", linkHandler.fromUrl("https://m.youtube.com/watch?v=VM_6n762j6M").getId());
33+
assertEquals("VM_6n762j6M", linkHandler.fromUrl("https://youtube.com/watch?v=VM_6n762j6M").getId());
34+
assertEquals("VM_6n762j6M", linkHandler.fromUrl("https://WWW.youtube.com/watch?v=VM_6n762j6M").getId());
35+
assertEquals("VM_6n762j6M", linkHandler.fromUrl("https://youtu.be/VM_6n762j6M").getId());
36+
assertEquals("VM_6n762j6M", linkHandler.fromUrl("https://youtu.be/VM_6n762j6M&t=20").getId());
37+
}
38+
39+
@Test
40+
public void testAcceptUrl() throws ParsingException {
41+
assertTrue(linkHandler.acceptUrl("https://www.youtube.com/watch?v=VM_6n762j6M&t=20"));
42+
assertTrue(linkHandler.acceptUrl("https://WWW.youtube.com/watch?v=VM_6n762j6M&t=20"));
43+
assertTrue(linkHandler.acceptUrl("https://youtube.com/watch?v=VM_6n762j6M&t=20"));
44+
assertTrue(linkHandler.acceptUrl("https://youtu.be/VM_6n762j6M&t=20"));
45+
}
46+
47+
@Test
48+
public void testDeniesUrl() throws ParsingException {
49+
assertFalse(linkHandler.acceptUrl("https://www.you com/watch?v=VM_6n762j6M"));
50+
assertFalse(linkHandler.acceptUrl("https://com/watch?v=VM_6n762j6M"));
51+
assertFalse(linkHandler.acceptUrl("htt ://com/watch?v=VM_6n762j6M"));
52+
assertFalse(linkHandler.acceptUrl("ftp://www.youtube.com/watch?v=VM_6n762j6M"));
53+
}
54+
55+
@Test
56+
public void getIdFromInvidious() throws ParsingException {
57+
assertEquals("VM_6n762j6M", linkHandler.fromUrl("https://www.invidio.us/watch?v=VM_6n762j6M").getId());
58+
assertEquals("VM_6n762j6M", linkHandler.fromUrl("https://invidio.us/watch?v=VM_6n762j6M").getId());
59+
assertEquals("VM_6n762j6M", linkHandler.fromUrl("https://INVIDIO.US/watch?v=VM_6n762j6M").getId());
60+
assertEquals("VM_6n762j6M", linkHandler.fromUrl("https://invidio.us/VM_6n762j6M").getId());
61+
assertEquals("VM_6n762j6M", linkHandler.fromUrl("https://invidio.us/VM_6n762j6M&t=20").getId());
62+
}
63+
64+
}

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

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -24,31 +24,25 @@
2424

2525
public class YoutubeCommentsExtractorTest {
2626
/**
27-
* Test a "normal" YouTube and Invidious page
27+
* Test a "normal" YouTube
2828
*/
2929
public static class Thomas {
30-
private static final String urlYT = "https://www.youtube.com/watch?v=D00Au7k3i6o";
31-
private static final String urlInvidious = "https://invidio.us/watch?v=D00Au7k3i6o";
32-
private static YoutubeCommentsExtractor extractorYT;
33-
private static YoutubeCommentsExtractor extractorInvidious;
30+
private static final String url = "https://www.youtube.com/watch?v=D00Au7k3i6o";
31+
private static YoutubeCommentsExtractor extractor;
3432

3533
private static final String commentContent = "sub 4 sub";
3634

3735
@BeforeClass
3836
public static void setUp() throws Exception {
3937
NewPipe.init(DownloaderTestImpl.getInstance());
40-
extractorYT = (YoutubeCommentsExtractor) YouTube
41-
.getCommentsExtractor(urlYT);
42-
extractorYT.fetchPage();
43-
extractorInvidious = (YoutubeCommentsExtractor) YouTube
44-
.getCommentsExtractor(urlInvidious);
45-
extractorInvidious.fetchPage();
38+
extractor = (YoutubeCommentsExtractor) YouTube
39+
.getCommentsExtractor(url);
40+
extractor.fetchPage();
4641
}
4742

4843
@Test
4944
public void testGetComments() throws IOException, ExtractionException {
50-
assertTrue(getCommentsHelper(extractorYT));
51-
assertTrue(getCommentsHelper(extractorInvidious));
45+
assertTrue(getCommentsHelper(extractor));
5246
}
5347

5448
private boolean getCommentsHelper(YoutubeCommentsExtractor extractor) throws IOException, ExtractionException {
@@ -65,8 +59,7 @@ private boolean getCommentsHelper(YoutubeCommentsExtractor extractor) throws IOE
6559

6660
@Test
6761
public void testGetCommentsFromCommentsInfo() throws IOException, ExtractionException {
68-
assertTrue(getCommentsFromCommentsInfoHelper(urlYT));
69-
assertTrue(getCommentsFromCommentsInfoHelper(urlInvidious));
62+
assertTrue(getCommentsFromCommentsInfoHelper(url));
7063
}
7164

7265
private boolean getCommentsFromCommentsInfoHelper(String url) throws IOException, ExtractionException {
@@ -87,7 +80,7 @@ private boolean getCommentsFromCommentsInfoHelper(String url) throws IOException
8780

8881
@Test
8982
public void testGetCommentsAllData() throws IOException, ExtractionException {
90-
InfoItemsPage<CommentsInfoItem> comments = extractorYT.getInitialPage();
83+
InfoItemsPage<CommentsInfoItem> comments = extractor.getInitialPage();
9184

9285
DefaultTests.defaultTestListOfItems(YouTube, comments.getItems(), comments.getErrors());
9386
for (CommentsInfoItem c : comments.getItems()) {

0 commit comments

Comments
 (0)