Skip to content

Commit 64729e5

Browse files
committed
Improve the tests
1 parent 68b0fd9 commit 64729e5

1 file changed

Lines changed: 10 additions & 8 deletions

File tree

extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/search/YoutubeSearchPagingTest.java

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ public class YoutubeSearchPagingTest {
2424
private static ListExtractor.InfoItemsPage<InfoItem> page2;
2525
private static Set<String> urlList1;
2626
private static Set<String> urlList2;
27+
private static int pageSize;
2728

2829
@BeforeClass
2930
public static void setUpClass() throws Exception {
@@ -35,10 +36,11 @@ public static void setUpClass() throws Exception {
3536
extractor.fetchPage();
3637
page1 = extractor.getInitialPage();
3738
urlList1 = extractUrls(page1.getItems());
38-
assertEquals("page with items loaded", 20, page1.getItems().size());
39-
assertEquals("distinct videos", 20, urlList1.size());
39+
assertTrue("page with items loaded", 15 < page1.getItems().size());
40+
pageSize = page1.getItems().size();
41+
assertEquals("they are all distinct, no repetition", pageSize, urlList1.size());
4042

41-
assertTrue("has more page", page1.hasNextPage());
43+
assertTrue("has more than one page of results", page1.hasNextPage());
4244
assertNotNull("has next page url", page1.getNextPageUrl());
4345
page2 = extractor.getPage(page1.getNextPageUrl());
4446
urlList2 = extractUrls(page2.getItems());
@@ -54,25 +56,25 @@ private static Set<String> extractUrls(List<InfoItem> list) {
5456

5557
@Test
5658
public void firstPageOk() {
57-
assertEquals("page with items loaded", 20, page1.getItems().size());
58-
assertEquals("distinct videos", 20, urlList1.size());
59+
assertTrue("first page contains the expected number of items", 15 < page1.getItems().size());
60+
assertEquals("they are all distinct, no repetition", pageSize, urlList1.size());
5961
}
6062

6163
@Test
6264
public void secondPageLength() {
63-
assertEquals("one page", 20, page2.getItems().size());
65+
assertEquals("second page contains only the expected number of items", pageSize, page2.getItems().size());
6466
}
6567

6668
@Test
6769
public void secondPageUniqueVideos() {
68-
assertEquals("distinct videos", 20, urlList2.size());
70+
assertEquals("they are all distinct, no repetition", pageSize, urlList2.size());
6971
}
7072

7173
@Test
7274
public void noRepeatingVideosInPages() {
7375
Set<String> intersection = new HashSet<>(urlList2);
7476
intersection.retainAll(urlList1);
75-
assertEquals("empty intersection", 0, intersection.size());
77+
assertEquals("Found a duplicated video on second search page", 0, intersection.size());
7678
}
7779

7880
}

0 commit comments

Comments
 (0)