Skip to content

Commit 0ffd4d9

Browse files
committed
Improve tests for search results and reuse code
1 parent fe2583f commit 0ffd4d9

6 files changed

Lines changed: 65 additions & 63 deletions

File tree

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
package org.schabi.newpipe.extractor.services.soundcloud;
2+
3+
import org.junit.Test;
4+
import org.schabi.newpipe.extractor.InfoItem;
5+
import org.schabi.newpipe.extractor.channel.ChannelInfoItem;
6+
import org.schabi.newpipe.extractor.playlist.PlaylistInfoItem;
7+
import org.schabi.newpipe.extractor.search.SearchResult;
8+
import org.schabi.newpipe.extractor.stream.StreamInfoItem;
9+
import org.schabi.newpipe.extractor.stream.StreamType;
10+
11+
import static org.junit.Assert.*;
12+
import static org.schabi.newpipe.extractor.ExtractorAsserts.assertIsSecureUrl;
13+
14+
public abstract class BaseSoundcloudSearchTest {
15+
16+
protected static SearchResult result;
17+
18+
@Test
19+
public void testResultList() {
20+
assertFalse("Got empty result list", result.resultList.isEmpty());
21+
for(InfoItem infoItem: result.resultList) {
22+
assertIsSecureUrl(infoItem.getUrl());
23+
assertIsSecureUrl(infoItem.getThumbnailUrl());
24+
assertFalse(infoItem.getName().isEmpty());
25+
assertFalse("Name is probably a URI: " + infoItem.getName(),
26+
infoItem.getName().contains("://"));
27+
if(infoItem instanceof StreamInfoItem) {
28+
// test stream item
29+
StreamInfoItem streamInfoItem = (StreamInfoItem) infoItem;
30+
assertIsSecureUrl(streamInfoItem.getUploaderUrl());
31+
assertFalse(streamInfoItem.getUploadDate().isEmpty());
32+
assertFalse(streamInfoItem.getUploaderName().isEmpty());
33+
assertEquals(StreamType.AUDIO_STREAM, streamInfoItem.getStreamType());
34+
} else if(infoItem instanceof ChannelInfoItem) {
35+
// Nothing special to check?
36+
} else if(infoItem instanceof PlaylistInfoItem) {
37+
// test playlist item
38+
assertTrue(infoItem.getUrl().contains("/sets/"));
39+
long streamCount = ((PlaylistInfoItem) infoItem).getStreamCount();
40+
assertTrue(streamCount > 0);
41+
} else {
42+
fail("Unknown infoItem type: " + infoItem);
43+
}
44+
}
45+
}
46+
47+
@Test
48+
public void testResultErrors() {
49+
assertNotNull(result.errors);
50+
if (!result.errors.isEmpty()) {
51+
for (Throwable error : result.errors) {
52+
error.printStackTrace();
53+
}
54+
}
55+
assertTrue(result.errors.isEmpty());
56+
}
57+
}

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

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,15 @@
66
import org.schabi.newpipe.Downloader;
77
import org.schabi.newpipe.extractor.NewPipe;
88
import org.schabi.newpipe.extractor.search.SearchEngine;
9-
import org.schabi.newpipe.extractor.search.SearchResult;
109

11-
import static org.junit.Assert.assertFalse;
1210
import static org.junit.Assert.assertNotNull;
1311
import static org.junit.Assert.assertTrue;
1412
import static org.schabi.newpipe.extractor.ServiceList.SoundCloud;
1513

1614
/**
1715
* Test for {@link SearchEngine}
1816
*/
19-
public class SoundcloudSearchEngineAllTest {
20-
private static SearchResult result;
17+
public class SoundcloudSearchEngineAllTest extends BaseSoundcloudSearchTest {
2118

2219
@BeforeClass
2320
public static void setUp() throws Exception {
@@ -30,18 +27,6 @@ public static void setUp() throws Exception {
3027
.getSearchResult();
3128
}
3229

33-
@Test
34-
public void testResultList() {
35-
assertFalse(result.resultList.isEmpty());
36-
}
37-
38-
@Test
39-
public void testResultErrors() {
40-
assertNotNull(result.errors);
41-
if (!result.errors.isEmpty()) for (Throwable error : result.errors) error.printStackTrace();
42-
assertTrue(result.errors.isEmpty());
43-
}
44-
4530
@Ignore
4631
@Test
4732
public void testSuggestion() {

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

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@
1515
/**
1616
* Test for {@link SearchEngine}
1717
*/
18-
public class SoundcloudSearchEngineChannelTest {
19-
private static SearchResult result;
18+
public class SoundcloudSearchEngineChannelTest extends BaseSoundcloudSearchTest {
2019

2120
@BeforeClass
2221
public static void setUp() throws Exception {
@@ -29,25 +28,13 @@ public static void setUp() throws Exception {
2928
.getSearchResult();
3029
}
3130

32-
@Test
33-
public void testResultList() {
34-
assertFalse(result.resultList.isEmpty());
35-
}
36-
3731
@Test
3832
public void testResultsItemType() {
3933
for (InfoItem infoItem : result.resultList) {
4034
assertEquals(InfoItem.InfoType.CHANNEL, infoItem.info_type);
4135
}
4236
}
4337

44-
@Test
45-
public void testResultErrors() {
46-
assertNotNull(result.errors);
47-
if (!result.errors.isEmpty()) for (Throwable error : result.errors) error.printStackTrace();
48-
assertTrue(result.errors.isEmpty());
49-
}
50-
5138
@Ignore
5239
@Test
5340
public void testSuggestion() {

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

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,7 @@
3636
/**
3737
* Test for {@link SearchEngine}
3838
*/
39-
public class SoundcloudSearchEnginePlaylistTest {
40-
private static SearchResult result;
39+
public class SoundcloudSearchEnginePlaylistTest extends BaseSoundcloudSearchTest {
4140

4241
@BeforeClass
4342
public static void setUp() throws Exception {
@@ -49,25 +48,13 @@ public static void setUp() throws Exception {
4948
.getSearchResult();
5049
}
5150

52-
@Test
53-
public void testResultList() {
54-
assertFalse(result.resultList.isEmpty());
55-
}
56-
5751
@Test
5852
public void testUserItemType() {
5953
for (InfoItem infoItem : result.resultList) {
6054
assertEquals(InfoItem.InfoType.PLAYLIST, infoItem.info_type);
6155
}
6256
}
6357

64-
@Test
65-
public void testResultErrors() {
66-
assertNotNull(result.errors);
67-
if (!result.errors.isEmpty()) for (Throwable error : result.errors) error.printStackTrace();
68-
assertTrue(result.errors.isEmpty());
69-
}
70-
7158
@Ignore
7259
@Test
7360
public void testSuggestion() {

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

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,39 +15,26 @@
1515
/**
1616
* Test for {@link SearchEngine}
1717
*/
18-
public class SoundcloudSearchEngineStreamTest {
19-
private static SearchResult result;
18+
public class SoundcloudSearchEngineStreamTest extends BaseSoundcloudSearchTest {
2019

2120
@BeforeClass
2221
public static void setUp() throws Exception {
2322
NewPipe.init(Downloader.getInstance());
2423
SearchEngine engine = SoundCloud.getService().getSearchEngine();
2524

26-
// SoundCloud will suggest "lil uzi vert" instead of "lil uzi vert",
25+
// SoundCloud will suggest "lil uzi vert" instead of "lill uzi vert",
2726
// keep in mind that the suggestions can NOT change by country (the parameter "de")
2827
result = engine.search("lill uzi vert", 0, "de", SearchEngine.Filter.STREAM)
2928
.getSearchResult();
3029
}
3130

32-
@Test
33-
public void testResultList() {
34-
assertFalse(result.resultList.isEmpty());
35-
}
36-
3731
@Test
3832
public void testResultsItemType() {
3933
for (InfoItem infoItem : result.resultList) {
4034
assertEquals(InfoItem.InfoType.STREAM, infoItem.info_type);
4135
}
4236
}
4337

44-
@Test
45-
public void testResultErrors() {
46-
assertNotNull(result.errors);
47-
if (!result.errors.isEmpty()) for (Throwable error : result.errors) error.printStackTrace();
48-
assertTrue(result.errors.isEmpty());
49-
}
50-
5138
@Ignore
5239
@Test
5340
public void testSuggestion() {

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import java.util.List;
1717

1818
import static org.junit.Assert.*;
19+
import static org.schabi.newpipe.extractor.ExtractorAsserts.assertIsSecureUrl;
1920
import static org.schabi.newpipe.extractor.ServiceList.YouTube;
2021

2122
/**
@@ -85,14 +86,12 @@ public void testGetUploadDate() throws ParsingException {
8586

8687
@Test
8788
public void testGetThumbnailUrl() throws ParsingException {
88-
assertTrue(extractor.getThumbnailUrl(),
89-
extractor.getThumbnailUrl().contains(HTTPS));
89+
assertIsSecureUrl(extractor.getThumbnailUrl());
9090
}
9191

9292
@Test
9393
public void testGetUploaderAvatarUrl() throws ParsingException {
94-
assertTrue(extractor.getUploaderAvatarUrl(),
95-
extractor.getUploaderAvatarUrl().contains(HTTPS));
94+
assertIsSecureUrl(extractor.getUploaderAvatarUrl());
9695
}
9796

9897
// FIXME: 25.11.17 Are there no streams or are they not listed?

0 commit comments

Comments
 (0)