Skip to content

Commit 90ae5fb

Browse files
mauriciocolliTobiGr
authored andcommitted
Improve kiosk tests across services
1 parent e590417 commit 90ae5fb

4 files changed

Lines changed: 221 additions & 227 deletions

File tree

extractor/src/test/java/org/schabi/newpipe/extractor/services/peertube/PeertubeTrendingExtractorTest.java

Lines changed: 50 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -5,90 +5,75 @@
55
import org.schabi.newpipe.DownloaderTestImpl;
66
import org.schabi.newpipe.extractor.ListExtractor;
77
import org.schabi.newpipe.extractor.NewPipe;
8+
import org.schabi.newpipe.extractor.exceptions.ParsingException;
89
import org.schabi.newpipe.extractor.kiosk.KioskExtractor;
10+
import org.schabi.newpipe.extractor.services.BaseListExtractorTest;
911
import org.schabi.newpipe.extractor.services.peertube.extractors.PeertubeTrendingExtractor;
12+
import org.schabi.newpipe.extractor.services.soundcloud.SoundcloudChartsExtractor;
13+
import org.schabi.newpipe.extractor.services.youtube.extractors.YoutubeTrendingExtractor;
1014
import org.schabi.newpipe.extractor.stream.StreamInfoItem;
1115

1216
import java.util.List;
1317

1418
import static org.junit.Assert.*;
15-
import static org.schabi.newpipe.extractor.ServiceList.PeerTube;
19+
import static org.schabi.newpipe.extractor.ServiceList.*;
20+
import static org.schabi.newpipe.extractor.services.DefaultTests.*;
1621

17-
/**
18-
* Test for {@link PeertubeTrendingExtractor}
19-
*/
2022
public class PeertubeTrendingExtractorTest {
23+
public static class Trending implements BaseListExtractorTest {
24+
private static PeertubeTrendingExtractor extractor;
2125

22-
static KioskExtractor extractor;
26+
@BeforeClass
27+
public static void setUp() throws Exception {
28+
NewPipe.init(DownloaderTestImpl.getInstance());
29+
// setting instance might break test when running in parallel
30+
PeerTube.setInstance(new PeertubeInstance("https://peertube.mastodon.host", "PeerTube on Mastodon.host"));
31+
extractor = (PeertubeTrendingExtractor) PeerTube.getKioskList()
32+
.getExtractorById("Trending", null);
33+
extractor.fetchPage();
34+
}
2335

24-
@BeforeClass
25-
public static void setUp() throws Exception {
26-
NewPipe.init(DownloaderTestImpl.getInstance());
27-
// setting instance might break test when running in parallel
28-
PeerTube.setInstance(new PeertubeInstance("https://peertube.mastodon.host", "PeerTube on Mastodon.host"));
29-
extractor = PeerTube
30-
.getKioskList()
31-
.getExtractorById("Trending", null);
32-
extractor.fetchPage();
33-
}
36+
/*//////////////////////////////////////////////////////////////////////////
37+
// Extractor
38+
//////////////////////////////////////////////////////////////////////////*/
3439

35-
@Test
36-
public void testGetDownloader() throws Exception {
37-
assertNotNull(NewPipe.getDownloader());
38-
}
39-
40-
@Test
41-
public void testGetName() throws Exception {
42-
assertEquals(extractor.getName(), "Trending");
43-
}
40+
@Test
41+
public void testServiceId() {
42+
assertEquals(PeerTube.getServiceId(), extractor.getServiceId());
43+
}
4444

45-
@Test
46-
public void testId() {
47-
assertEquals(extractor.getId(), "Trending");
48-
}
45+
@Test
46+
public void testName() throws Exception {
47+
assertEquals("Trending", extractor.getName());
48+
}
4949

50-
@Test
51-
public void testGetStreams() throws Exception {
52-
ListExtractor.InfoItemsPage<StreamInfoItem> page = extractor.getInitialPage();
53-
if (!page.getErrors().isEmpty()) {
54-
System.err.println("----------");
55-
List<Throwable> errors = page.getErrors();
56-
for (Throwable e : errors) {
57-
e.printStackTrace();
58-
System.err.println("----------");
59-
}
50+
@Test
51+
public void testId() throws Exception {
52+
assertEquals("Trending", extractor.getId());
6053
}
61-
assertTrue("no streams are received",
62-
!page.getItems().isEmpty()
63-
&& page.getErrors().isEmpty());
64-
}
6554

66-
@Test
67-
public void testGetStreamsErrors() throws Exception {
68-
assertTrue("errors during stream list extraction", extractor.getInitialPage().getErrors().isEmpty());
69-
}
55+
@Test
56+
public void testUrl() throws ParsingException {
57+
assertEquals("https://peertube.mastodon.host/api/v1/videos?sort=-trending", extractor.getUrl());
58+
}
7059

71-
@Test
72-
public void testHasMoreStreams() throws Exception {
73-
// Setup the streams
74-
extractor.getInitialPage();
75-
assertTrue("has more streams", extractor.hasNextPage());
76-
}
60+
@Test
61+
public void testOriginalUrl() throws ParsingException {
62+
assertEquals("https://peertube.mastodon.host/api/v1/videos?sort=-trending", extractor.getOriginalUrl());
63+
}
7764

78-
@Test
79-
public void testGetNextPageUrl() throws Exception {
80-
assertTrue(extractor.hasNextPage());
81-
}
65+
/*//////////////////////////////////////////////////////////////////////////
66+
// ListExtractor
67+
//////////////////////////////////////////////////////////////////////////*/
8268

83-
@Test
84-
public void testGetNextPage() throws Exception {
85-
extractor.getInitialPage().getItems();
86-
assertFalse("extractor has next streams", extractor.getPage(extractor.getNextPageUrl()) == null
87-
|| extractor.getPage(extractor.getNextPageUrl()).getItems().isEmpty());
88-
}
69+
@Test
70+
public void testRelatedItems() throws Exception {
71+
defaultTestRelatedItems(extractor);
72+
}
8973

90-
@Test
91-
public void testGetCleanUrl() throws Exception {
92-
assertEquals(extractor.getUrl(), "https://peertube.mastodon.host/api/v1/videos?sort=-trending");
74+
@Test
75+
public void testMoreRelatedItems() throws Exception {
76+
defaultTestMoreItems(extractor);
77+
}
9378
}
9479
}

extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudChartsExtractorTest.java

Lines changed: 101 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -5,87 +5,127 @@
55
import org.schabi.newpipe.DownloaderTestImpl;
66
import org.schabi.newpipe.extractor.ListExtractor;
77
import org.schabi.newpipe.extractor.NewPipe;
8+
import org.schabi.newpipe.extractor.exceptions.ParsingException;
89
import org.schabi.newpipe.extractor.kiosk.KioskExtractor;
10+
import org.schabi.newpipe.extractor.services.BaseListExtractorTest;
11+
import org.schabi.newpipe.extractor.services.youtube.extractors.YoutubeTrendingExtractor;
912
import org.schabi.newpipe.extractor.stream.StreamInfoItem;
1013

1114
import java.util.List;
1215

1316
import static org.junit.Assert.*;
1417
import static org.schabi.newpipe.extractor.ServiceList.SoundCloud;
18+
import static org.schabi.newpipe.extractor.ServiceList.YouTube;
19+
import static org.schabi.newpipe.extractor.services.DefaultTests.*;
1520

16-
/**
17-
* Test for {@link SoundcloudChartsLinkHandlerFactory}
18-
*/
1921
public class SoundcloudChartsExtractorTest {
22+
public static class NewAndHot implements BaseListExtractorTest {
23+
private static SoundcloudChartsExtractor extractor;
2024

21-
static KioskExtractor extractor;
25+
@BeforeClass
26+
public static void setUp() throws Exception {
27+
NewPipe.init(DownloaderTestImpl.getInstance());
28+
extractor = (SoundcloudChartsExtractor) SoundCloud.getKioskList()
29+
.getExtractorById("New & hot", null);
30+
extractor.fetchPage();
31+
}
2232

23-
@BeforeClass
24-
public static void setUp() throws Exception {
25-
NewPipe.init(DownloaderTestImpl.getInstance());
26-
extractor = SoundCloud
27-
.getKioskList()
28-
.getExtractorById("Top 50", null);
29-
extractor.fetchPage();
30-
}
33+
/*//////////////////////////////////////////////////////////////////////////
34+
// Extractor
35+
//////////////////////////////////////////////////////////////////////////*/
3136

32-
@Test
33-
public void testGetDownloader() throws Exception {
34-
assertNotNull(NewPipe.getDownloader());
35-
}
37+
@Test
38+
public void testServiceId() {
39+
assertEquals(SoundCloud.getServiceId(), extractor.getServiceId());
40+
}
3641

37-
@Test
38-
public void testGetName() throws Exception {
39-
assertEquals(extractor.getName(), "Top 50");
40-
}
42+
@Test
43+
public void testName() {
44+
assertEquals("New & hot", extractor.getName());
45+
}
4146

42-
@Test
43-
public void testId() {
44-
assertEquals(extractor.getId(), "Top 50");
45-
}
47+
@Test
48+
public void testId() {
49+
assertEquals("New & hot", extractor.getId());
50+
}
4651

47-
@Test
48-
public void testGetStreams() throws Exception {
49-
ListExtractor.InfoItemsPage<StreamInfoItem> page = extractor.getInitialPage();
50-
if (!page.getErrors().isEmpty()) {
51-
System.err.println("----------");
52-
List<Throwable> errors = page.getErrors();
53-
for (Throwable e : errors) {
54-
e.printStackTrace();
55-
System.err.println("----------");
56-
}
57-
}
58-
assertTrue("no streams are received",
59-
!page.getItems().isEmpty()
60-
&& page.getErrors().isEmpty());
61-
}
52+
@Test
53+
public void testUrl() throws ParsingException {
54+
assertEquals("https://soundcloud.com/charts/new", extractor.getUrl());
55+
}
6256

63-
@Test
64-
public void testGetStreamsErrors() throws Exception {
65-
assertTrue("errors during stream list extraction", extractor.getInitialPage().getErrors().isEmpty());
66-
}
57+
@Test
58+
public void testOriginalUrl() throws ParsingException {
59+
assertEquals("https://soundcloud.com/charts/new", extractor.getOriginalUrl());
60+
}
6761

68-
@Test
69-
public void testHasMoreStreams() throws Exception {
70-
// Setup the streams
71-
extractor.getInitialPage();
72-
assertTrue("has more streams", extractor.hasNextPage());
73-
}
62+
/*//////////////////////////////////////////////////////////////////////////
63+
// ListExtractor
64+
//////////////////////////////////////////////////////////////////////////*/
7465

75-
@Test
76-
public void testGetNextPageUrl() throws Exception {
77-
assertTrue(extractor.hasNextPage());
78-
}
66+
@Test
67+
public void testRelatedItems() throws Exception {
68+
defaultTestRelatedItems(extractor);
69+
}
7970

80-
@Test
81-
public void testGetNextPage() throws Exception {
82-
extractor.getInitialPage().getItems();
83-
assertFalse("extractor has next streams", extractor.getPage(extractor.getNextPageUrl()) == null
84-
|| extractor.getPage(extractor.getNextPageUrl()).getItems().isEmpty());
71+
@Test
72+
public void testMoreRelatedItems() throws Exception {
73+
defaultTestMoreItems(extractor);
74+
}
8575
}
8676

87-
@Test
88-
public void testGetCleanUrl() throws Exception {
89-
assertEquals(extractor.getUrl(), "https://soundcloud.com/charts/top");
77+
public static class Top50Charts implements BaseListExtractorTest {
78+
private static SoundcloudChartsExtractor extractor;
79+
80+
@BeforeClass
81+
public static void setUp() throws Exception {
82+
NewPipe.init(DownloaderTestImpl.getInstance());
83+
extractor = (SoundcloudChartsExtractor) SoundCloud.getKioskList()
84+
.getExtractorById("Top 50", null);
85+
extractor.fetchPage();
86+
}
87+
88+
/*//////////////////////////////////////////////////////////////////////////
89+
// Extractor
90+
//////////////////////////////////////////////////////////////////////////*/
91+
92+
@Test
93+
public void testServiceId() {
94+
assertEquals(SoundCloud.getServiceId(), extractor.getServiceId());
95+
}
96+
97+
@Test
98+
public void testName() {
99+
assertEquals("Top 50", extractor.getName());
100+
}
101+
102+
@Test
103+
public void testId() {
104+
assertEquals("Top 50", extractor.getId());
105+
}
106+
107+
@Test
108+
public void testUrl() throws ParsingException {
109+
assertEquals("https://soundcloud.com/charts/top", extractor.getUrl());
110+
}
111+
112+
@Test
113+
public void testOriginalUrl() throws ParsingException {
114+
assertEquals("https://soundcloud.com/charts/top", extractor.getOriginalUrl());
115+
}
116+
117+
/*//////////////////////////////////////////////////////////////////////////
118+
// ListExtractor
119+
//////////////////////////////////////////////////////////////////////////*/
120+
121+
@Test
122+
public void testRelatedItems() throws Exception {
123+
defaultTestRelatedItems(extractor);
124+
}
125+
126+
@Test
127+
public void testMoreRelatedItems() throws Exception {
128+
defaultTestMoreItems(extractor);
129+
}
90130
}
91131
}

0 commit comments

Comments
 (0)