Skip to content

Commit bf845d8

Browse files
committed
Add tests for SoundCloud
1 parent 845c16b commit bf845d8

8 files changed

Lines changed: 545 additions & 0 deletions
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
package org.schabi.newpipe.extractor.services.soundcloud;
2+
3+
import static org.junit.Assert.assertEquals;
4+
import static org.junit.Assert.assertNotNull;
5+
import static org.junit.Assert.assertTrue;
6+
import static org.schabi.newpipe.extractor.ServiceList.SoundCloud;
7+
8+
import org.junit.Before;
9+
import org.junit.Test;
10+
import org.schabi.newpipe.Downloader;
11+
import org.schabi.newpipe.extractor.NewPipe;
12+
import org.schabi.newpipe.extractor.playlist.PlaylistExtractor;
13+
14+
/**
15+
* Test for {@link PlaylistExtractor}
16+
*/
17+
18+
public class SoundcloudPlaylistExtractorTest {
19+
private PlaylistExtractor extractor;
20+
21+
@Before
22+
public void setUp() throws Exception {
23+
NewPipe.init(Downloader.getInstance());
24+
extractor = SoundCloud.getService()
25+
.getPlaylistExtractor("https://soundcloud.com/liluzivert/sets/the-perfect-luv-tape-r");
26+
}
27+
28+
@Test
29+
public void testGetDownloader() throws Exception {
30+
assertNotNull(NewPipe.getDownloader());
31+
}
32+
33+
@Test
34+
public void testGetId() throws Exception {
35+
assertEquals(extractor.getPlaylistId(), "246349810");
36+
}
37+
38+
@Test
39+
public void testGetName() throws Exception {
40+
assertEquals(extractor.getPlaylistName(), "THE PERFECT LUV TAPE®️");
41+
}
42+
43+
@Test
44+
public void testGetAvatarUrl() throws Exception {
45+
assertEquals(extractor.getAvatarUrl(), "https://i1.sndcdn.com/artworks-000174203688-bweu12-large.jpg");
46+
}
47+
48+
@Test
49+
public void testGetUploaderUrl() throws Exception {
50+
assertEquals(extractor.getUploaderUrl(), "http://soundcloud.com/liluzivert");
51+
}
52+
53+
@Test
54+
public void testGetUploaderName() throws Exception {
55+
assertEquals(extractor.getUploaderName(), "LIL UZI VERT");
56+
}
57+
58+
@Test
59+
public void testGetUploaderAvatarUrl() throws Exception {
60+
assertEquals(extractor.getUploaderAvatarUrl(), "https://a1.sndcdn.com/images/default_avatar_large.png");
61+
}
62+
63+
@Test
64+
public void testGetStreamsCount() throws Exception {
65+
assertEquals(extractor.getStreamCount(), 10);
66+
}
67+
68+
@Test
69+
public void testGetStreams() throws Exception {
70+
assertTrue("no streams are received", !extractor.getStreams().getItemList().isEmpty());
71+
}
72+
73+
@Test
74+
public void testGetStreamsErrors() throws Exception {
75+
assertTrue("errors during stream list extraction", extractor.getStreams().getErrors().isEmpty());
76+
}
77+
78+
@Test
79+
public void testHasMoreStreams() throws Exception {
80+
// Setup the streams
81+
extractor.getStreams();
82+
assertTrue("extractor didn't have more streams", !extractor.hasMoreStreams());
83+
}
84+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package org.schabi.newpipe.extractor.services.soundcloud;
2+
3+
import static org.junit.Assert.assertFalse;
4+
import static org.junit.Assert.assertTrue;
5+
import static org.schabi.newpipe.extractor.ServiceList.SoundCloud;
6+
7+
import java.util.EnumSet;
8+
9+
import org.junit.Before;
10+
import org.junit.Test;
11+
import org.schabi.newpipe.Downloader;
12+
import org.schabi.newpipe.extractor.NewPipe;
13+
import org.schabi.newpipe.extractor.search.SearchEngine;
14+
import org.schabi.newpipe.extractor.search.SearchResult;
15+
16+
/**
17+
* Test for {@link SearchEngine}
18+
*/
19+
public class SoundcloudSearchEngineAllTest {
20+
private SearchResult result;
21+
22+
@Before
23+
public void setUp() throws Exception {
24+
NewPipe.init(Downloader.getInstance());
25+
SearchEngine engine = SoundCloud.getService().getSearchEngine();
26+
27+
// SoundCloud will suggest "lil uzi vert" instead of "lill uzi vert"
28+
// keep in mind that the suggestions can NOT change by country (the parameter "de")
29+
result = engine.search("lill uzi vert", 0, "de",
30+
EnumSet.of(SearchEngine.Filter.USER,
31+
SearchEngine.Filter.STREAM)).getSearchResult();
32+
}
33+
34+
@Test
35+
public void testResultList() {
36+
assertFalse(result.resultList.isEmpty());
37+
}
38+
39+
@Test
40+
public void testResultErrors() {
41+
if (!result.errors.isEmpty()) for (Throwable error : result.errors) error.printStackTrace();
42+
assertTrue(result.errors == null || result.errors.isEmpty());
43+
}
44+
45+
@Test
46+
public void testSuggestion() {
47+
//todo write a real test
48+
assertTrue(result.suggestion != null);
49+
}
50+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package org.schabi.newpipe.extractor.services.soundcloud;
2+
3+
import static org.junit.Assert.assertEquals;
4+
import static org.junit.Assert.assertFalse;
5+
import static org.junit.Assert.assertTrue;
6+
import static org.schabi.newpipe.extractor.ServiceList.SoundCloud;
7+
8+
import java.util.EnumSet;
9+
10+
import org.junit.Before;
11+
import org.junit.Test;
12+
import org.schabi.newpipe.Downloader;
13+
import org.schabi.newpipe.extractor.InfoItem;
14+
import org.schabi.newpipe.extractor.NewPipe;
15+
import org.schabi.newpipe.extractor.search.SearchEngine;
16+
import org.schabi.newpipe.extractor.search.SearchResult;
17+
18+
/**
19+
* Test for {@link SearchEngine}
20+
*/
21+
public class SoundcloudSearchEngineStreamTest {
22+
private SearchResult result;
23+
24+
@Before
25+
public void setUp() throws Exception {
26+
NewPipe.init(Downloader.getInstance());
27+
SearchEngine engine = SoundCloud.getService().getSearchEngine();
28+
29+
// SoundCloud will suggest "lil uzi vert" instead of "lil uzi vert",
30+
// keep in mind that the suggestions can NOT change by country (the parameter "de")
31+
result = engine.search("lill uzi vert", 0, "de",
32+
EnumSet.of(SearchEngine.Filter.STREAM)).getSearchResult();
33+
}
34+
35+
@Test
36+
public void testResultList() {
37+
assertFalse(result.resultList.isEmpty());
38+
}
39+
40+
@Test
41+
public void testStreamItemType() {
42+
for (InfoItem infoItem : result.resultList) {
43+
assertEquals(InfoItem.InfoType.STREAM, infoItem.info_type);
44+
}
45+
}
46+
47+
@Test
48+
public void testResultErrors() {
49+
if (!result.errors.isEmpty()) for (Throwable error : result.errors) error.printStackTrace();
50+
assertTrue(result.errors == null || result.errors.isEmpty());
51+
}
52+
53+
@Test
54+
public void testSuggestion() {
55+
//todo write a real test
56+
assertTrue(result.suggestion != null);
57+
}
58+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package org.schabi.newpipe.extractor.services.soundcloud;
2+
3+
import static org.junit.Assert.assertEquals;
4+
import static org.junit.Assert.assertFalse;
5+
import static org.junit.Assert.assertTrue;
6+
import static org.schabi.newpipe.extractor.ServiceList.SoundCloud;
7+
8+
import java.util.EnumSet;
9+
10+
import org.junit.Before;
11+
import org.junit.Test;
12+
import org.schabi.newpipe.Downloader;
13+
import org.schabi.newpipe.extractor.InfoItem;
14+
import org.schabi.newpipe.extractor.NewPipe;
15+
import org.schabi.newpipe.extractor.search.SearchEngine;
16+
import org.schabi.newpipe.extractor.search.SearchResult;
17+
18+
/**
19+
* Test for {@link SearchEngine}
20+
*/
21+
public class SoundcloudSearchEngineUserTest {
22+
private SearchResult result;
23+
24+
@Before
25+
public void setUp() throws Exception {
26+
NewPipe.init(Downloader.getInstance());
27+
SearchEngine engine = SoundCloud.getService().getSearchEngine();
28+
29+
// SoundCloud will suggest "lil uzi vert" instead of "lill uzi vert"
30+
// keep in mind that the suggestions can NOT change by country (the parameter "de")
31+
result = engine.search("lill uzi vert", 0, "de",
32+
EnumSet.of(SearchEngine.Filter.USER)).getSearchResult();
33+
}
34+
35+
@Test
36+
public void testResultList() {
37+
assertFalse(result.resultList.isEmpty());
38+
}
39+
40+
@Test
41+
public void testUserItemType() {
42+
for (InfoItem infoItem : result.resultList) {
43+
assertEquals(InfoItem.InfoType.USER, infoItem.info_type);
44+
}
45+
}
46+
47+
@Test
48+
public void testResultErrors() {
49+
if (!result.errors.isEmpty()) for (Throwable error : result.errors) error.printStackTrace();
50+
assertTrue(result.errors == null || result.errors.isEmpty());
51+
}
52+
53+
@Test
54+
public void testSuggestion() {
55+
//todo write a real test
56+
assertTrue(result.suggestion != null);
57+
}
58+
}
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
package org.schabi.newpipe.extractor.services.soundcloud;
2+
3+
import static org.junit.Assert.assertEquals;
4+
import static org.junit.Assert.assertFalse;
5+
import static org.junit.Assert.assertTrue;
6+
import static org.schabi.newpipe.extractor.ServiceList.SoundCloud;
7+
8+
import java.io.IOException;
9+
10+
import org.junit.Before;
11+
import org.junit.Test;
12+
import org.schabi.newpipe.Downloader;
13+
import org.schabi.newpipe.extractor.NewPipe;
14+
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
15+
import org.schabi.newpipe.extractor.exceptions.ParsingException;
16+
import org.schabi.newpipe.extractor.stream.StreamExtractor;
17+
import org.schabi.newpipe.extractor.stream.StreamInfoItemCollector;
18+
import org.schabi.newpipe.extractor.stream.StreamType;
19+
20+
/**
21+
* Test for {@link StreamExtractor}
22+
*/
23+
public class SoundcloudStreamExtractorDefaultTest {
24+
private StreamExtractor extractor;
25+
26+
@Before
27+
public void setUp() throws Exception {
28+
NewPipe.init(Downloader.getInstance());
29+
extractor = SoundCloud.getService().getStreamExtractor("https://soundcloud.com/liluzivert/do-what-i-want-produced-by-maaly-raw-don-cannon");
30+
}
31+
32+
@Test
33+
public void testGetInvalidTimeStamp() throws ParsingException {
34+
assertTrue(Integer.toString(extractor.getTimeStamp()),
35+
extractor.getTimeStamp() <= 0);
36+
}
37+
38+
@Test
39+
public void testGetValidTimeStamp() throws IOException, ExtractionException {
40+
StreamExtractor extractor = SoundCloud.getService().getStreamExtractor("https://soundcloud.com/liluzivert/do-what-i-want-produced-by-maaly-raw-don-cannon#t=69");
41+
assertEquals(Integer.toString(extractor.getTimeStamp()), "69");
42+
}
43+
44+
@Test
45+
public void testGetTitle() throws ParsingException {
46+
assertEquals(extractor.getTitle(), "Do What I Want [Produced By Maaly Raw + Don Cannon]");
47+
}
48+
49+
@Test
50+
public void testGetDescription() throws ParsingException {
51+
assertEquals(extractor.getDescription(), "The Perfect LUV Tape®️");
52+
}
53+
54+
@Test
55+
public void testGetUploader() throws ParsingException {
56+
assertEquals(extractor.getUploader(), "LIL UZI VERT");
57+
}
58+
59+
@Test
60+
public void testGetLength() throws ParsingException {
61+
assertEquals(extractor.getLength(), 175);
62+
}
63+
64+
@Test
65+
public void testGetViewCount() throws ParsingException {
66+
assertTrue(Long.toString(extractor.getViewCount()),
67+
extractor.getViewCount() > 44227978);
68+
}
69+
70+
@Test
71+
public void testGetUploadDate() throws ParsingException {
72+
assertEquals(extractor.getUploadDate(), "2016-07-31");
73+
}
74+
75+
@Test
76+
public void testGetUserUrl() throws ParsingException {
77+
assertEquals(extractor.getUserUrl(), "http://soundcloud.com/liluzivert");
78+
}
79+
80+
@Test
81+
public void testGetThumbnailUrl() throws ParsingException {
82+
assertEquals(extractor.getThumbnailUrl(), "https://i1.sndcdn.com/artworks-000174195399-iw6seg-large.jpg");
83+
}
84+
85+
@Test
86+
public void testGetUploaderThumbnailUrl() throws ParsingException {
87+
assertEquals(extractor.getUploaderThumbnailUrl(), "https://a1.sndcdn.com/images/default_avatar_large.png");
88+
}
89+
90+
@Test
91+
public void testGetAudioStreams() throws IOException, ExtractionException {
92+
assertTrue(!extractor.getAudioStreams().isEmpty());
93+
}
94+
95+
@Test
96+
public void testStreamType() throws ParsingException {
97+
assertTrue(extractor.getStreamType() == StreamType.AUDIO_STREAM);
98+
}
99+
100+
@Test
101+
public void testGetRelatedVideos() throws ExtractionException, IOException {
102+
StreamInfoItemCollector relatedVideos = extractor.getRelatedVideos();
103+
assertFalse(relatedVideos.getItemList().isEmpty());
104+
assertTrue(relatedVideos.getErrors().isEmpty());
105+
}
106+
}

0 commit comments

Comments
 (0)