44import org .junit .BeforeClass ;
55import org .junit .Test ;
66import org .schabi .newpipe .DownloaderTestImpl ;
7- import org .schabi .newpipe .DownloaderTestImpl ;
87import org .schabi .newpipe .extractor .ListExtractor .InfoItemsPage ;
98import org .schabi .newpipe .extractor .NewPipe ;
109import org .schabi .newpipe .extractor .comments .CommentsInfo ;
2120
2221public class YoutubeCommentsExtractorTest {
2322
24- private static YoutubeCommentsExtractor extractor ;
23+ private static final String urlYT = "https://www.youtube.com/watch?v=D00Au7k3i6o" ;
24+ private static final String urlInvidious = "https://invidio.us/watch?v=D00Au7k3i6o" ;
25+ private static final String urlInvidioush = "https://invidiou.sh/watch?v=D00Au7k3i6o" ;
26+ private static YoutubeCommentsExtractor extractorYT ;
27+ private static YoutubeCommentsExtractor extractorInvidious ;
28+ private static YoutubeCommentsExtractor extractorInvidioush ;
2529
2630 @ BeforeClass
2731 public static void setUp () throws Exception {
2832 NewPipe .init (DownloaderTestImpl .getInstance ());
29- extractor = (YoutubeCommentsExtractor ) YouTube
30- .getCommentsExtractor ("https://www.youtube.com/watch?v=D00Au7k3i6o" );
33+ extractorYT = (YoutubeCommentsExtractor ) YouTube
34+ .getCommentsExtractor (urlYT );
35+ extractorInvidious = (YoutubeCommentsExtractor ) YouTube
36+ .getCommentsExtractor (urlInvidious );
37+ extractorInvidioush = (YoutubeCommentsExtractor ) YouTube
38+ .getCommentsExtractor (urlInvidioush );
3139 }
3240
3341 @ Test
3442 public void testGetComments () throws IOException , ExtractionException {
43+ assertTrue (getCommentsHelper (extractorYT ));
44+ assertTrue (getCommentsHelper (extractorInvidious ));
45+ assertTrue (getCommentsHelper (extractorInvidioush ));
46+ }
47+
48+ private boolean getCommentsHelper (YoutubeCommentsExtractor extractor ) throws IOException , ExtractionException {
3549 boolean result ;
3650 InfoItemsPage <CommentsInfoItem > comments = extractor .getInitialPage ();
3751 result = findInComments (comments , "s1ck m3m3" );
@@ -41,14 +55,20 @@ public void testGetComments() throws IOException, ExtractionException {
4155 result = findInComments (comments , "s1ck m3m3" );
4256 }
4357
44- assertTrue ( result ) ;
58+ return result ;
4559 }
4660
4761 @ Test
4862 public void testGetCommentsFromCommentsInfo () throws IOException , ExtractionException {
63+ assertTrue (getCommentsFromCommentsInfoHelper (urlYT ));
64+ assertTrue (getCommentsFromCommentsInfoHelper (urlInvidious ));
65+ assertTrue (getCommentsFromCommentsInfoHelper (urlInvidioush ));
66+ }
67+
68+ private boolean getCommentsFromCommentsInfoHelper (String url ) throws IOException , ExtractionException {
4969 boolean result = false ;
50- CommentsInfo commentsInfo = CommentsInfo .getInfo ("https://www.youtube.com/watch?v=D00Au7k3i6o" );
51- assertTrue ("what the fuck am i doing with my life" . equals ( commentsInfo .getName () ));
70+ CommentsInfo commentsInfo = CommentsInfo .getInfo (url );
71+ assertEquals ("what the fuck am i doing with my life" , commentsInfo .getName ());
5272 result = findInComments (commentsInfo .getRelatedItems (), "s1ck m3m3" );
5373
5474 String nextPage = commentsInfo .getNextPageUrl ();
@@ -57,16 +77,15 @@ public void testGetCommentsFromCommentsInfo() throws IOException, ExtractionExce
5777 result = findInComments (moreItems .getItems (), "s1ck m3m3" );
5878 nextPage = moreItems .getNextPageUrl ();
5979 }
60-
61- assertTrue (result );
80+ return result ;
6281 }
63-
82+
6483 @ Test
6584 public void testGetCommentsAllData () throws IOException , ExtractionException {
66- InfoItemsPage <CommentsInfoItem > comments = extractor .getInitialPage ();
85+ InfoItemsPage <CommentsInfoItem > comments = extractorYT .getInitialPage ();
6786
6887 DefaultTests .defaultTestListOfItems (YouTube .getServiceId (), comments .getItems (), comments .getErrors ());
69- for (CommentsInfoItem c : comments .getItems ()) {
88+ for (CommentsInfoItem c : comments .getItems ()) {
7089 assertFalse (StringUtil .isBlank (c .getAuthorEndpoint ()));
7190 assertFalse (StringUtil .isBlank (c .getAuthorName ()));
7291 assertFalse (StringUtil .isBlank (c .getAuthorThumbnail ()));
@@ -86,8 +105,8 @@ private boolean findInComments(InfoItemsPage<CommentsInfoItem> comments, String
86105 }
87106
88107 private boolean findInComments (List <CommentsInfoItem > comments , String comment ) {
89- for (CommentsInfoItem c : comments ) {
90- if (c .getCommentText ().contains (comment )) {
108+ for (CommentsInfoItem c : comments ) {
109+ if (c .getCommentText ().contains (comment )) {
91110 return true ;
92111 }
93112 }
0 commit comments