Improve tests for search results and reuse code
This commit is contained in:
parent
fe2583f3d7
commit
0ffd4d9743
|
@ -0,0 +1,57 @@
|
|||
package org.schabi.newpipe.extractor.services.soundcloud;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.schabi.newpipe.extractor.InfoItem;
|
||||
import org.schabi.newpipe.extractor.channel.ChannelInfoItem;
|
||||
import org.schabi.newpipe.extractor.playlist.PlaylistInfoItem;
|
||||
import org.schabi.newpipe.extractor.search.SearchResult;
|
||||
import org.schabi.newpipe.extractor.stream.StreamInfoItem;
|
||||
import org.schabi.newpipe.extractor.stream.StreamType;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.schabi.newpipe.extractor.ExtractorAsserts.assertIsSecureUrl;
|
||||
|
||||
public abstract class BaseSoundcloudSearchTest {
|
||||
|
||||
protected static SearchResult result;
|
||||
|
||||
@Test
|
||||
public void testResultList() {
|
||||
assertFalse("Got empty result list", result.resultList.isEmpty());
|
||||
for(InfoItem infoItem: result.resultList) {
|
||||
assertIsSecureUrl(infoItem.getUrl());
|
||||
assertIsSecureUrl(infoItem.getThumbnailUrl());
|
||||
assertFalse(infoItem.getName().isEmpty());
|
||||
assertFalse("Name is probably a URI: " + infoItem.getName(),
|
||||
infoItem.getName().contains("://"));
|
||||
if(infoItem instanceof StreamInfoItem) {
|
||||
// test stream item
|
||||
StreamInfoItem streamInfoItem = (StreamInfoItem) infoItem;
|
||||
assertIsSecureUrl(streamInfoItem.getUploaderUrl());
|
||||
assertFalse(streamInfoItem.getUploadDate().isEmpty());
|
||||
assertFalse(streamInfoItem.getUploaderName().isEmpty());
|
||||
assertEquals(StreamType.AUDIO_STREAM, streamInfoItem.getStreamType());
|
||||
} else if(infoItem instanceof ChannelInfoItem) {
|
||||
// Nothing special to check?
|
||||
} else if(infoItem instanceof PlaylistInfoItem) {
|
||||
// test playlist item
|
||||
assertTrue(infoItem.getUrl().contains("/sets/"));
|
||||
long streamCount = ((PlaylistInfoItem) infoItem).getStreamCount();
|
||||
assertTrue(streamCount > 0);
|
||||
} else {
|
||||
fail("Unknown infoItem type: " + infoItem);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testResultErrors() {
|
||||
assertNotNull(result.errors);
|
||||
if (!result.errors.isEmpty()) {
|
||||
for (Throwable error : result.errors) {
|
||||
error.printStackTrace();
|
||||
}
|
||||
}
|
||||
assertTrue(result.errors.isEmpty());
|
||||
}
|
||||
}
|
|
@ -6,9 +6,7 @@ import org.junit.Test;
|
|||
import org.schabi.newpipe.Downloader;
|
||||
import org.schabi.newpipe.extractor.NewPipe;
|
||||
import org.schabi.newpipe.extractor.search.SearchEngine;
|
||||
import org.schabi.newpipe.extractor.search.SearchResult;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.schabi.newpipe.extractor.ServiceList.SoundCloud;
|
||||
|
@ -16,8 +14,7 @@ import static org.schabi.newpipe.extractor.ServiceList.SoundCloud;
|
|||
/**
|
||||
* Test for {@link SearchEngine}
|
||||
*/
|
||||
public class SoundcloudSearchEngineAllTest {
|
||||
private static SearchResult result;
|
||||
public class SoundcloudSearchEngineAllTest extends BaseSoundcloudSearchTest {
|
||||
|
||||
@BeforeClass
|
||||
public static void setUp() throws Exception {
|
||||
|
@ -30,18 +27,6 @@ public class SoundcloudSearchEngineAllTest {
|
|||
.getSearchResult();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testResultList() {
|
||||
assertFalse(result.resultList.isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testResultErrors() {
|
||||
assertNotNull(result.errors);
|
||||
if (!result.errors.isEmpty()) for (Throwable error : result.errors) error.printStackTrace();
|
||||
assertTrue(result.errors.isEmpty());
|
||||
}
|
||||
|
||||
@Ignore
|
||||
@Test
|
||||
public void testSuggestion() {
|
||||
|
|
|
@ -15,8 +15,7 @@ import static org.schabi.newpipe.extractor.ServiceList.SoundCloud;
|
|||
/**
|
||||
* Test for {@link SearchEngine}
|
||||
*/
|
||||
public class SoundcloudSearchEngineChannelTest {
|
||||
private static SearchResult result;
|
||||
public class SoundcloudSearchEngineChannelTest extends BaseSoundcloudSearchTest {
|
||||
|
||||
@BeforeClass
|
||||
public static void setUp() throws Exception {
|
||||
|
@ -29,11 +28,6 @@ public class SoundcloudSearchEngineChannelTest {
|
|||
.getSearchResult();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testResultList() {
|
||||
assertFalse(result.resultList.isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testResultsItemType() {
|
||||
for (InfoItem infoItem : result.resultList) {
|
||||
|
@ -41,13 +35,6 @@ public class SoundcloudSearchEngineChannelTest {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testResultErrors() {
|
||||
assertNotNull(result.errors);
|
||||
if (!result.errors.isEmpty()) for (Throwable error : result.errors) error.printStackTrace();
|
||||
assertTrue(result.errors.isEmpty());
|
||||
}
|
||||
|
||||
@Ignore
|
||||
@Test
|
||||
public void testSuggestion() {
|
||||
|
|
|
@ -36,8 +36,7 @@ import static org.schabi.newpipe.extractor.ServiceList.SoundCloud;
|
|||
/**
|
||||
* Test for {@link SearchEngine}
|
||||
*/
|
||||
public class SoundcloudSearchEnginePlaylistTest {
|
||||
private static SearchResult result;
|
||||
public class SoundcloudSearchEnginePlaylistTest extends BaseSoundcloudSearchTest {
|
||||
|
||||
@BeforeClass
|
||||
public static void setUp() throws Exception {
|
||||
|
@ -49,11 +48,6 @@ public class SoundcloudSearchEnginePlaylistTest {
|
|||
.getSearchResult();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testResultList() {
|
||||
assertFalse(result.resultList.isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUserItemType() {
|
||||
for (InfoItem infoItem : result.resultList) {
|
||||
|
@ -61,13 +55,6 @@ public class SoundcloudSearchEnginePlaylistTest {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testResultErrors() {
|
||||
assertNotNull(result.errors);
|
||||
if (!result.errors.isEmpty()) for (Throwable error : result.errors) error.printStackTrace();
|
||||
assertTrue(result.errors.isEmpty());
|
||||
}
|
||||
|
||||
@Ignore
|
||||
@Test
|
||||
public void testSuggestion() {
|
||||
|
|
|
@ -15,25 +15,19 @@ import static org.schabi.newpipe.extractor.ServiceList.SoundCloud;
|
|||
/**
|
||||
* Test for {@link SearchEngine}
|
||||
*/
|
||||
public class SoundcloudSearchEngineStreamTest {
|
||||
private static SearchResult result;
|
||||
public class SoundcloudSearchEngineStreamTest extends BaseSoundcloudSearchTest {
|
||||
|
||||
@BeforeClass
|
||||
public static void setUp() throws Exception {
|
||||
NewPipe.init(Downloader.getInstance());
|
||||
SearchEngine engine = SoundCloud.getService().getSearchEngine();
|
||||
|
||||
// SoundCloud will suggest "lil uzi vert" instead of "lil uzi vert",
|
||||
// SoundCloud will suggest "lil uzi vert" instead of "lill uzi vert",
|
||||
// keep in mind that the suggestions can NOT change by country (the parameter "de")
|
||||
result = engine.search("lill uzi vert", 0, "de", SearchEngine.Filter.STREAM)
|
||||
.getSearchResult();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testResultList() {
|
||||
assertFalse(result.resultList.isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testResultsItemType() {
|
||||
for (InfoItem infoItem : result.resultList) {
|
||||
|
@ -41,13 +35,6 @@ public class SoundcloudSearchEngineStreamTest {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testResultErrors() {
|
||||
assertNotNull(result.errors);
|
||||
if (!result.errors.isEmpty()) for (Throwable error : result.errors) error.printStackTrace();
|
||||
assertTrue(result.errors.isEmpty());
|
||||
}
|
||||
|
||||
@Ignore
|
||||
@Test
|
||||
public void testSuggestion() {
|
||||
|
|
|
@ -16,6 +16,7 @@ import java.util.ArrayList;
|
|||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.schabi.newpipe.extractor.ExtractorAsserts.assertIsSecureUrl;
|
||||
import static org.schabi.newpipe.extractor.ServiceList.YouTube;
|
||||
|
||||
/**
|
||||
|
@ -85,14 +86,12 @@ public class YoutubeStreamExtractorRestrictedTest {
|
|||
|
||||
@Test
|
||||
public void testGetThumbnailUrl() throws ParsingException {
|
||||
assertTrue(extractor.getThumbnailUrl(),
|
||||
extractor.getThumbnailUrl().contains(HTTPS));
|
||||
assertIsSecureUrl(extractor.getThumbnailUrl());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetUploaderAvatarUrl() throws ParsingException {
|
||||
assertTrue(extractor.getUploaderAvatarUrl(),
|
||||
extractor.getUploaderAvatarUrl().contains(HTTPS));
|
||||
assertIsSecureUrl(extractor.getUploaderAvatarUrl());
|
||||
}
|
||||
|
||||
// FIXME: 25.11.17 Are there no streams or are they not listed?
|
||||
|
|
Loading…
Reference in New Issue