Skip to content

Commit c9eb790

Browse files
committed
Some tests extension
1 parent 9512064 commit c9eb790

4 files changed

Lines changed: 47 additions & 12 deletions

File tree

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package org.schabi.newpipe.extractor;
2+
3+
import java.util.List;
4+
5+
public class ExtractorAsserts {
6+
public static void assertEmptyErrors(String message, List<Throwable> errors) {
7+
if(!errors.isEmpty()) {
8+
for (Throwable throwable : errors) {
9+
message += "\n * " + throwable.getMessage();
10+
}
11+
throw new AssertionError(message, errors.get(0));
12+
}
13+
}
14+
}

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@
77
import org.schabi.newpipe.extractor.NewPipe;
88
import org.schabi.newpipe.extractor.channel.ChannelExtractor;
99

10+
import java.util.List;
11+
1012
import static org.junit.Assert.*;
13+
import static org.schabi.newpipe.extractor.ExtractorAsserts.assertEmptyErrors;
1114
import static org.schabi.newpipe.extractor.ServiceList.YouTube;
1215

1316
/*
@@ -35,12 +38,12 @@
3538
*/
3639
public class YoutubeChannelExtractorTest {
3740

38-
ChannelExtractor extractor;
41+
YoutubeChannelExtractor extractor;
3942

4043
@Before
4144
public void setUp() throws Exception {
4245
NewPipe.init(Downloader.getInstance());
43-
extractor = YouTube.getService()
46+
extractor = (YoutubeChannelExtractor) YouTube.getService()
4447
.getChannelExtractor("https://www.youtube.com/user/Gronkh");
4548
}
4649

@@ -91,7 +94,7 @@ public void testGetStreams() throws Exception {
9194

9295
@Test
9396
public void testGetStreamsErrors() throws Exception {
94-
assertTrue("errors during stream list extraction", extractor.getStreams().getErrors().isEmpty());
97+
assertEmptyErrors("errors during stream list extraction", extractor.getStreams().getErrors());
9598
}
9699

97100
@Test
@@ -112,7 +115,7 @@ public void testGetNextStreams() throws Exception {
112115
extractor.getStreams();
113116
ListExtractor.NextItemsResult nextItemsResult = extractor.getNextStreams();
114117
assertTrue("extractor didn't have next streams", !nextItemsResult.nextItemsList.isEmpty());
115-
assertTrue("errors occurred during extraction of the next streams", nextItemsResult.errors.isEmpty());
118+
assertEmptyErrors("errors occurred during extraction of the next streams", nextItemsResult.errors);
116119
assertTrue("extractor didn't have more streams after getNextStreams", extractor.hasMoreStreams());
117120
}
118121
}

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

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,29 @@
66
import org.schabi.newpipe.extractor.ListExtractor;
77
import org.schabi.newpipe.extractor.NewPipe;
88
import org.schabi.newpipe.extractor.playlist.PlaylistExtractor;
9+
import org.schabi.newpipe.extractor.stream.StreamInfoItem;
10+
11+
import java.util.List;
912

1013
import static org.junit.Assert.*;
14+
import static org.schabi.newpipe.extractor.ExtractorAsserts.assertEmptyErrors;
1115
import static org.schabi.newpipe.extractor.ServiceList.YouTube;
1216

1317
/**
14-
* Test for {@link PlaylistExtractor}
18+
* Test for {@link YoutubePlaylistExtractor}
1519
*/
16-
1720
public class YoutubePlaylistExtractorTest {
18-
private PlaylistExtractor extractor;
21+
private YoutubePlaylistExtractor extractor;
22+
23+
private static void assertNotEmpty(String message, String value) {
24+
assertNotNull(message, value);
25+
assertFalse(message, value.isEmpty());
26+
}
1927

2028
@Before
2129
public void setUp() throws Exception {
2230
NewPipe.init(Downloader.getInstance());
23-
extractor = YouTube.getService()
31+
extractor = (YoutubePlaylistExtractor) YouTube.getService()
2432
.getPlaylistExtractor("https://www.youtube.com/playlist?list=PL7XlqX4npddfrdpMCxBnNZXg2GFll7t5y");
2533
}
2634

@@ -71,12 +79,22 @@ public void testGetStreamsCount() throws Exception {
7179

7280
@Test
7381
public void testGetStreams() throws Exception {
74-
assertTrue("no streams are received", !extractor.getStreams().getItemList().isEmpty());
82+
List<StreamInfoItem> streams = extractor.getStreams().getItemList();
83+
assertFalse("no streams are received", streams.isEmpty());
84+
assertTrue(streams.size() > 60);
85+
assertFalse(streams.contains(null));
86+
for(StreamInfoItem item: streams) {
87+
assertEquals("Service id doesn't match", YouTube.getId(), item.getServiceId());
88+
assertNotNull("Stream type not set: " + item, item.getStreamType());
89+
//assertNotEmpty("Upload date not set: " + item, item.getUploadDate());
90+
assertNotEmpty("Uploader name not set: " + item, item.getUploaderName());
91+
assertNotEmpty("Uploader url not set: " + item, item.getUploaderUrl());
92+
}
7593
}
7694

7795
@Test
7896
public void testGetStreamsErrors() throws Exception {
79-
assertTrue("errors during stream list extraction", extractor.getStreams().getErrors().isEmpty());
97+
assertEmptyErrors("errors during stream list extraction", extractor.getStreams().getErrors());
8098
}
8199

82100
@Test
@@ -92,7 +110,7 @@ public void testGetNextStreams() throws Exception {
92110
extractor.getStreams();
93111
ListExtractor.NextItemsResult nextItemsResult = extractor.getNextStreams();
94112
assertTrue("extractor didn't have next streams", !nextItemsResult.nextItemsList.isEmpty());
95-
assertTrue("errors occurred during extraction of the next streams", nextItemsResult.errors.isEmpty());
113+
assertEmptyErrors("errors occurred during extraction of the next streams", nextItemsResult.errors);
96114
assertTrue("extractor didn't have more streams after getNextStreams", extractor.hasMoreStreams());
97115
}
98116

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public void testGetValidTimeStamp() throws IOException, ExtractionException {
4444

4545
@Test
4646
public void testGetAgeLimit() throws ParsingException {
47-
assertTrue(extractor.getAgeLimit() == 18);
47+
assertEquals(18, extractor.getAgeLimit());
4848
}
4949

5050
@Test

0 commit comments

Comments
 (0)