Improve tests for search results and reuse code

This commit is contained in:
Coffeemakr 2018-01-04 18:01:25 +01:00
parent fe2583f3d7
commit 0ffd4d9743
No known key found for this signature in database
GPG Key ID: 3F35676D8FF6E743
6 changed files with 65 additions and 63 deletions

View File

@ -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());
}
}

View File

@ -6,9 +6,7 @@ import org.junit.Test;
import org.schabi.newpipe.Downloader; import org.schabi.newpipe.Downloader;
import org.schabi.newpipe.extractor.NewPipe; import org.schabi.newpipe.extractor.NewPipe;
import org.schabi.newpipe.extractor.search.SearchEngine; 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.assertNotNull;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import static org.schabi.newpipe.extractor.ServiceList.SoundCloud; import static org.schabi.newpipe.extractor.ServiceList.SoundCloud;
@ -16,8 +14,7 @@ import static org.schabi.newpipe.extractor.ServiceList.SoundCloud;
/** /**
* Test for {@link SearchEngine} * Test for {@link SearchEngine}
*/ */
public class SoundcloudSearchEngineAllTest { public class SoundcloudSearchEngineAllTest extends BaseSoundcloudSearchTest {
private static SearchResult result;
@BeforeClass @BeforeClass
public static void setUp() throws Exception { public static void setUp() throws Exception {
@ -30,18 +27,6 @@ public class SoundcloudSearchEngineAllTest {
.getSearchResult(); .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 @Ignore
@Test @Test
public void testSuggestion() { public void testSuggestion() {

View File

@ -15,8 +15,7 @@ import static org.schabi.newpipe.extractor.ServiceList.SoundCloud;
/** /**
* Test for {@link SearchEngine} * Test for {@link SearchEngine}
*/ */
public class SoundcloudSearchEngineChannelTest { public class SoundcloudSearchEngineChannelTest extends BaseSoundcloudSearchTest {
private static SearchResult result;
@BeforeClass @BeforeClass
public static void setUp() throws Exception { public static void setUp() throws Exception {
@ -29,11 +28,6 @@ public class SoundcloudSearchEngineChannelTest {
.getSearchResult(); .getSearchResult();
} }
@Test
public void testResultList() {
assertFalse(result.resultList.isEmpty());
}
@Test @Test
public void testResultsItemType() { public void testResultsItemType() {
for (InfoItem infoItem : result.resultList) { 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 @Ignore
@Test @Test
public void testSuggestion() { public void testSuggestion() {

View File

@ -36,8 +36,7 @@ import static org.schabi.newpipe.extractor.ServiceList.SoundCloud;
/** /**
* Test for {@link SearchEngine} * Test for {@link SearchEngine}
*/ */
public class SoundcloudSearchEnginePlaylistTest { public class SoundcloudSearchEnginePlaylistTest extends BaseSoundcloudSearchTest {
private static SearchResult result;
@BeforeClass @BeforeClass
public static void setUp() throws Exception { public static void setUp() throws Exception {
@ -49,11 +48,6 @@ public class SoundcloudSearchEnginePlaylistTest {
.getSearchResult(); .getSearchResult();
} }
@Test
public void testResultList() {
assertFalse(result.resultList.isEmpty());
}
@Test @Test
public void testUserItemType() { public void testUserItemType() {
for (InfoItem infoItem : result.resultList) { 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 @Ignore
@Test @Test
public void testSuggestion() { public void testSuggestion() {

View File

@ -15,25 +15,19 @@ import static org.schabi.newpipe.extractor.ServiceList.SoundCloud;
/** /**
* Test for {@link SearchEngine} * Test for {@link SearchEngine}
*/ */
public class SoundcloudSearchEngineStreamTest { public class SoundcloudSearchEngineStreamTest extends BaseSoundcloudSearchTest {
private static SearchResult result;
@BeforeClass @BeforeClass
public static void setUp() throws Exception { public static void setUp() throws Exception {
NewPipe.init(Downloader.getInstance()); NewPipe.init(Downloader.getInstance());
SearchEngine engine = SoundCloud.getService().getSearchEngine(); 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") // 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) result = engine.search("lill uzi vert", 0, "de", SearchEngine.Filter.STREAM)
.getSearchResult(); .getSearchResult();
} }
@Test
public void testResultList() {
assertFalse(result.resultList.isEmpty());
}
@Test @Test
public void testResultsItemType() { public void testResultsItemType() {
for (InfoItem infoItem : result.resultList) { 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 @Ignore
@Test @Test
public void testSuggestion() { public void testSuggestion() {

View File

@ -16,6 +16,7 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import static org.junit.Assert.*; import static org.junit.Assert.*;
import static org.schabi.newpipe.extractor.ExtractorAsserts.assertIsSecureUrl;
import static org.schabi.newpipe.extractor.ServiceList.YouTube; import static org.schabi.newpipe.extractor.ServiceList.YouTube;
/** /**
@ -85,14 +86,12 @@ public class YoutubeStreamExtractorRestrictedTest {
@Test @Test
public void testGetThumbnailUrl() throws ParsingException { public void testGetThumbnailUrl() throws ParsingException {
assertTrue(extractor.getThumbnailUrl(), assertIsSecureUrl(extractor.getThumbnailUrl());
extractor.getThumbnailUrl().contains(HTTPS));
} }
@Test @Test
public void testGetUploaderAvatarUrl() throws ParsingException { public void testGetUploaderAvatarUrl() throws ParsingException {
assertTrue(extractor.getUploaderAvatarUrl(), assertIsSecureUrl(extractor.getUploaderAvatarUrl());
extractor.getUploaderAvatarUrl().contains(HTTPS));
} }
// FIXME: 25.11.17 Are there no streams or are they not listed? // FIXME: 25.11.17 Are there no streams or are they not listed?