Skip to content

Commit 93a2103

Browse files
committed
[YouTube] Apply changes in extractor tests
Also remove some public test methods modifiers, add missing Test annotations on old Junit 4 tests (and update them if needed), and use final in some places where it was possible.
1 parent 2c436d4 commit 93a2103

7 files changed

Lines changed: 134 additions & 187 deletions

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

Lines changed: 37 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@
22

33
import static org.junit.jupiter.api.Assertions.assertEquals;
44
import static org.junit.jupiter.api.Assertions.assertFalse;
5-
import static org.junit.jupiter.api.Assertions.assertNull;
65
import static org.junit.jupiter.api.Assertions.assertThrows;
76
import static org.junit.jupiter.api.Assertions.assertTrue;
87
import static org.schabi.newpipe.extractor.ExtractorAsserts.assertContains;
9-
import static org.schabi.newpipe.extractor.ExtractorAsserts.assertIsSecureUrl;
8+
import static org.schabi.newpipe.extractor.ExtractorAsserts.assertEmpty;
109
import static org.schabi.newpipe.extractor.ExtractorAsserts.assertNotBlank;
1110
import static org.schabi.newpipe.extractor.ExtractorAsserts.assertTabsContain;
1211
import static org.schabi.newpipe.extractor.ServiceList.YouTube;
@@ -203,17 +202,13 @@ public void testDescription() throws Exception {
203202
}
204203

205204
@Test
206-
public void testAvatarUrl() throws Exception {
207-
String avatarUrl = extractor.getAvatarUrl();
208-
assertIsSecureUrl(avatarUrl);
209-
assertContains("yt3", avatarUrl);
205+
public void testAvatars() throws Exception {
206+
YoutubeTestsUtils.testImages(extractor.getAvatars());
210207
}
211208

212209
@Test
213-
public void testBannerUrl() throws Exception {
214-
String bannerUrl = extractor.getBannerUrl();
215-
assertIsSecureUrl(bannerUrl);
216-
assertContains("yt3", bannerUrl);
210+
public void testBanners() throws Exception {
211+
YoutubeTestsUtils.testImages(extractor.getBanners());
217212
}
218213

219214
@Test
@@ -226,6 +221,7 @@ public void testSubscriberCount() throws Exception {
226221
ExtractorAsserts.assertGreaterOrEqual(4_900_000, extractor.getSubscriberCount());
227222
}
228223

224+
@Test
229225
@Override
230226
public void testVerified() throws Exception {
231227
assertTrue(extractor.isVerified());
@@ -248,7 +244,7 @@ public void testTags() throws Exception {
248244
}
249245
}
250246

251-
// Youtube RED/Premium ad blocking test
247+
// YouTube RED/Premium ad blocking test
252248
public static class VSauce implements BaseChannelExtractorTest {
253249
private static YoutubeChannelExtractor extractor;
254250

@@ -300,17 +296,13 @@ public void testDescription() throws Exception {
300296
}
301297

302298
@Test
303-
public void testAvatarUrl() throws Exception {
304-
String avatarUrl = extractor.getAvatarUrl();
305-
assertIsSecureUrl(avatarUrl);
306-
assertContains("yt3", avatarUrl);
299+
public void testAvatars() throws Exception {
300+
YoutubeTestsUtils.testImages(extractor.getAvatars());
307301
}
308302

309303
@Test
310-
public void testBannerUrl() throws Exception {
311-
String bannerUrl = extractor.getBannerUrl();
312-
assertIsSecureUrl(bannerUrl);
313-
assertContains("yt3", bannerUrl);
304+
public void testBanners() throws Exception {
305+
YoutubeTestsUtils.testImages(extractor.getBanners());
314306
}
315307

316308
@Test
@@ -400,17 +392,13 @@ public void testDescription() throws Exception {
400392
}
401393

402394
@Test
403-
public void testAvatarUrl() throws Exception {
404-
String avatarUrl = extractor.getAvatarUrl();
405-
assertIsSecureUrl(avatarUrl);
406-
assertContains("yt3", avatarUrl);
395+
public void testAvatars() throws Exception {
396+
YoutubeTestsUtils.testImages(extractor.getAvatars());
407397
}
408398

409399
@Test
410-
public void testBannerUrl() throws Exception {
411-
String bannerUrl = extractor.getBannerUrl();
412-
assertIsSecureUrl(bannerUrl);
413-
assertContains("yt3", bannerUrl);
400+
public void testBanners() throws Exception {
401+
YoutubeTestsUtils.testImages(extractor.getBanners());
414402
}
415403

416404
@Test
@@ -524,17 +512,13 @@ public void testDescription() throws Exception {
524512
}
525513

526514
@Test
527-
public void testAvatarUrl() throws Exception {
528-
String avatarUrl = extractor.getAvatarUrl();
529-
assertIsSecureUrl(avatarUrl);
530-
assertContains("yt3", avatarUrl);
515+
public void testAvatars() throws Exception {
516+
YoutubeTestsUtils.testImages(extractor.getAvatars());
531517
}
532518

533519
@Test
534-
public void testBannerUrl() throws Exception {
535-
String bannerUrl = extractor.getBannerUrl();
536-
assertIsSecureUrl(bannerUrl);
537-
assertContains("yt3", bannerUrl);
520+
public void testBanners() throws Exception {
521+
YoutubeTestsUtils.testImages(extractor.getBanners());
538522
}
539523

540524
@Test
@@ -621,17 +605,13 @@ public void testDescription() throws Exception {
621605
}
622606

623607
@Test
624-
public void testAvatarUrl() throws Exception {
625-
String avatarUrl = extractor.getAvatarUrl();
626-
assertIsSecureUrl(avatarUrl);
627-
assertContains("yt3", avatarUrl);
608+
public void testAvatars() throws Exception {
609+
YoutubeTestsUtils.testImages(extractor.getAvatars());
628610
}
629611

630612
@Test
631-
public void testBannerUrl() throws Exception {
632-
String bannerUrl = extractor.getBannerUrl();
633-
assertIsSecureUrl(bannerUrl);
634-
assertContains("yt3", bannerUrl);
613+
public void testBanners() throws Exception {
614+
YoutubeTestsUtils.testImages(extractor.getBanners());
635615
}
636616

637617
@Test
@@ -689,7 +669,7 @@ public void testServiceId() {
689669

690670
@Test
691671
public void testName() throws Exception {
692-
assertEquals(extractor.getName(), "Coachella");
672+
assertEquals("Coachella", extractor.getName());
693673
}
694674

695675
@Test
@@ -718,16 +698,14 @@ public void testDescription() throws ParsingException {
718698
}
719699

720700
@Test
721-
public void testAvatarUrl() throws Exception {
722-
String avatarUrl = extractor.getAvatarUrl();
723-
assertIsSecureUrl(avatarUrl);
724-
assertContains("yt3", avatarUrl);
701+
public void testAvatars() throws Exception {
702+
YoutubeTestsUtils.testImages(extractor.getAvatars());
725703
}
726704

727705
@Test
728-
public void testBannerUrl() throws Exception {
729-
// CarouselHeaderRenders do not contain a banner
730-
assertNull(extractor.getBannerUrl());
706+
public void testBanners() {
707+
// A CarouselHeaderRenderer doesn't contain a banner
708+
assertEmpty(extractor.getBanners());
731709
}
732710

733711
@Test
@@ -795,17 +773,15 @@ public void testDescription() throws Exception {
795773

796774
@Test
797775
@Override
798-
public void testAvatarUrl() throws Exception {
799-
final String avatarUrl = extractor.getAvatarUrl();
800-
assertIsSecureUrl(avatarUrl);
801-
assertContains("yt3", avatarUrl);
776+
public void testAvatars() throws Exception {
777+
YoutubeTestsUtils.testImages(extractor.getAvatars());
802778
}
803779

804780
@Test
805781
@Override
806-
public void testBannerUrl() throws Exception {
782+
public void testBanners() throws Exception {
807783
// Banners cannot be extracted from age-restricted channels
808-
assertTrue(isNullOrEmpty(extractor.getBannerUrl()));
784+
assertEmpty(extractor.getBanners());
809785
}
810786

811787
@Test
@@ -913,18 +889,14 @@ public void testDescription() throws Exception {
913889

914890
@Test
915891
@Override
916-
public void testAvatarUrl() throws Exception {
917-
final String avatarUrl = extractor.getAvatarUrl();
918-
assertIsSecureUrl(avatarUrl);
919-
assertContains("yt3", avatarUrl);
892+
public void testAvatars() throws Exception {
893+
YoutubeTestsUtils.testImages(extractor.getAvatars());
920894
}
921895

922896
@Test
923897
@Override
924-
public void testBannerUrl() throws Exception {
925-
final String bannerUrl = extractor.getBannerUrl();
926-
assertIsSecureUrl(bannerUrl);
927-
assertContains("yt3", bannerUrl);
898+
public void testBanners() throws Exception {
899+
YoutubeTestsUtils.testImages(extractor.getBanners());
928900
}
929901

930902
@Test

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

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public static void setUp() throws Exception {
4949
}
5050

5151
@Test
52-
public void testGetComments() throws IOException, ExtractionException {
52+
void testGetComments() throws IOException, ExtractionException {
5353
assertTrue(getCommentsHelper(extractor));
5454
}
5555

@@ -66,11 +66,11 @@ private boolean getCommentsHelper(YoutubeCommentsExtractor extractor) throws IOE
6666
}
6767

6868
@Test
69-
public void testGetCommentsFromCommentsInfo() throws IOException, ExtractionException {
69+
void testGetCommentsFromCommentsInfo() throws IOException, ExtractionException {
7070
assertTrue(getCommentsFromCommentsInfoHelper(url));
7171
}
7272

73-
private boolean getCommentsFromCommentsInfoHelper(String url) throws IOException, ExtractionException {
73+
private boolean getCommentsFromCommentsInfoHelper(final String url) throws IOException, ExtractionException {
7474
final CommentsInfo commentsInfo = CommentsInfo.getInfo(url);
7575

7676
assertEquals("Comments", commentsInfo.getName());
@@ -87,21 +87,21 @@ private boolean getCommentsFromCommentsInfoHelper(String url) throws IOException
8787
}
8888

8989
@Test
90-
public void testGetCommentsAllData() throws IOException, ExtractionException {
90+
void testGetCommentsAllData() throws IOException, ExtractionException {
9191
InfoItemsPage<CommentsInfoItem> comments = extractor.getInitialPage();
9292
assertTrue(extractor.getCommentsCount() > 5); // at least 5 comments
9393

9494
DefaultTests.defaultTestListOfItems(YouTube, comments.getItems(), comments.getErrors());
95-
for (CommentsInfoItem c : comments.getItems()) {
95+
for (final CommentsInfoItem c : comments.getItems()) {
9696
assertFalse(Utils.isBlank(c.getUploaderUrl()));
9797
assertFalse(Utils.isBlank(c.getUploaderName()));
98-
assertFalse(Utils.isBlank(c.getUploaderAvatarUrl()));
98+
YoutubeTestsUtils.testImages(c.getUploaderAvatars());
9999
assertFalse(Utils.isBlank(c.getCommentId()));
100100
assertFalse(Utils.isBlank(c.getCommentText().getContent()));
101101
assertFalse(Utils.isBlank(c.getName()));
102102
assertFalse(Utils.isBlank(c.getTextualUploadDate()));
103103
assertNotNull(c.getUploadDate());
104-
assertFalse(Utils.isBlank(c.getThumbnailUrl()));
104+
YoutubeTestsUtils.testImages(c.getThumbnails());
105105
assertFalse(Utils.isBlank(c.getUrl()));
106106
assertTrue(c.getLikeCount() >= 0);
107107
}
@@ -138,19 +138,19 @@ public static void setUp() throws Exception {
138138
}
139139

140140
@Test
141-
public void testGetCommentsAllData() throws IOException, ExtractionException {
141+
void testGetCommentsAllData() throws IOException, ExtractionException {
142142
final InfoItemsPage<CommentsInfoItem> comments = extractor.getInitialPage();
143143

144144
DefaultTests.defaultTestListOfItems(YouTube, comments.getItems(), comments.getErrors());
145-
for (CommentsInfoItem c : comments.getItems()) {
145+
for (final CommentsInfoItem c : comments.getItems()) {
146146
assertFalse(Utils.isBlank(c.getUploaderUrl()));
147147
assertFalse(Utils.isBlank(c.getUploaderName()));
148-
assertFalse(Utils.isBlank(c.getUploaderAvatarUrl()));
148+
YoutubeTestsUtils.testImages(c.getUploaderAvatars());
149149
assertFalse(Utils.isBlank(c.getCommentId()));
150150
assertFalse(Utils.isBlank(c.getName()));
151151
assertFalse(Utils.isBlank(c.getTextualUploadDate()));
152152
assertNotNull(c.getUploadDate());
153-
assertFalse(Utils.isBlank(c.getThumbnailUrl()));
153+
YoutubeTestsUtils.testImages(c.getThumbnails());
154154
assertFalse(Utils.isBlank(c.getUrl()));
155155
assertTrue(c.getLikeCount() >= 0);
156156
if (c.getCommentId().equals("Ugga_h1-EXdHB3gCoAEC")) { // comment without text
@@ -177,22 +177,22 @@ public static void setUp() throws Exception {
177177
}
178178

179179
@Test
180-
public void testGetCommentsAllData() throws IOException, ExtractionException {
180+
void testGetCommentsAllData() throws IOException, ExtractionException {
181181
final InfoItemsPage<CommentsInfoItem> comments = extractor.getInitialPage();
182182

183183
DefaultTests.defaultTestListOfItems(YouTube, comments.getItems(), comments.getErrors());
184184

185185
boolean heartedByUploader = false;
186186

187-
for (CommentsInfoItem c : comments.getItems()) {
187+
for (final CommentsInfoItem c : comments.getItems()) {
188188
assertFalse(Utils.isBlank(c.getUploaderUrl()));
189189
assertFalse(Utils.isBlank(c.getUploaderName()));
190-
assertFalse(Utils.isBlank(c.getUploaderAvatarUrl()));
190+
YoutubeTestsUtils.testImages(c.getUploaderAvatars());
191191
assertFalse(Utils.isBlank(c.getCommentId()));
192192
assertFalse(Utils.isBlank(c.getName()));
193193
assertFalse(Utils.isBlank(c.getTextualUploadDate()));
194194
assertNotNull(c.getUploadDate());
195-
assertFalse(Utils.isBlank(c.getThumbnailUrl()));
195+
YoutubeTestsUtils.testImages(c.getThumbnails());
196196
assertFalse(Utils.isBlank(c.getUrl()));
197197
assertTrue(c.getLikeCount() >= 0);
198198
assertFalse(Utils.isBlank(c.getCommentText().getContent()));
@@ -219,20 +219,20 @@ public static void setUp() throws Exception {
219219
}
220220

221221
@Test
222-
public void testGetCommentsAllData() throws IOException, ExtractionException {
222+
void testGetCommentsAllData() throws IOException, ExtractionException {
223223
final InfoItemsPage<CommentsInfoItem> comments = extractor.getInitialPage();
224224

225225
DefaultTests.defaultTestListOfItems(YouTube, comments.getItems(), comments.getErrors());
226226

227-
for (CommentsInfoItem c : comments.getItems()) {
227+
for (final CommentsInfoItem c : comments.getItems()) {
228228
assertFalse(Utils.isBlank(c.getUploaderUrl()));
229229
assertFalse(Utils.isBlank(c.getUploaderName()));
230-
assertFalse(Utils.isBlank(c.getUploaderAvatarUrl()));
230+
YoutubeTestsUtils.testImages(c.getUploaderAvatars());
231231
assertFalse(Utils.isBlank(c.getCommentId()));
232232
assertFalse(Utils.isBlank(c.getName()));
233233
assertFalse(Utils.isBlank(c.getTextualUploadDate()));
234234
assertNotNull(c.getUploadDate());
235-
assertFalse(Utils.isBlank(c.getThumbnailUrl()));
235+
YoutubeTestsUtils.testImages(c.getThumbnails());
236236
assertFalse(Utils.isBlank(c.getUrl()));
237237
assertTrue(c.getLikeCount() >= 0);
238238
assertFalse(Utils.isBlank(c.getCommentText().getContent()));
@@ -260,7 +260,7 @@ public static void setUp() throws Exception {
260260
}
261261

262262
@Test
263-
public void testGetCommentsFirst() throws IOException, ExtractionException {
263+
void testGetCommentsFirst() throws IOException, ExtractionException {
264264
final InfoItemsPage<CommentsInfoItem> comments = extractor.getInitialPage();
265265

266266
DefaultTests.defaultTestListOfItems(YouTube, comments.getItems(), comments.getErrors());
@@ -293,7 +293,7 @@ public static void setUp() throws Exception {
293293
}
294294

295295
@Test
296-
public void testGetCommentsFirst() throws IOException, ExtractionException {
296+
void testGetCommentsFirst() throws IOException, ExtractionException {
297297
final InfoItemsPage<CommentsInfoItem> comments = extractor.getInitialPage();
298298

299299
DefaultTests.defaultTestListOfItems(YouTube, comments.getItems(), comments.getErrors());
@@ -319,7 +319,7 @@ public static void setUp() throws Exception {
319319
}
320320

321321
@Test
322-
public void testGetCommentsFirstReplies() throws IOException, ExtractionException {
322+
void testGetCommentsFirstReplies() throws IOException, ExtractionException {
323323
final InfoItemsPage<CommentsInfoItem> comments = extractor.getInitialPage();
324324

325325
DefaultTests.defaultTestListOfItems(YouTube, comments.getItems(), comments.getErrors());

0 commit comments

Comments
 (0)