[SoundCloud] Add test for small playlist, use defaultTestGetPageInNewExtractor

This commit is contained in:
Stypox 2020-03-17 21:03:50 +01:00
parent 45bb646480
commit 265cfb61f3
No known key found for this signature in database
GPG Key ID: 4BDF1B40A49FDD23
1 changed files with 104 additions and 23 deletions

View File

@ -1,6 +1,5 @@
package org.schabi.newpipe.extractor.services.soundcloud;
import org.hamcrest.CoreMatchers;
import org.junit.BeforeClass;
import org.junit.Test;
import org.schabi.newpipe.DownloaderTestImpl;
@ -10,6 +9,7 @@ import org.schabi.newpipe.extractor.playlist.PlaylistExtractor;
import org.schabi.newpipe.extractor.services.BasePlaylistExtractorTest;
import org.schabi.newpipe.extractor.stream.StreamInfoItem;
import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.*;
import static org.schabi.newpipe.extractor.ExtractorAsserts.assertIsSecureUrl;
import static org.schabi.newpipe.extractor.ServiceList.SoundCloud;
@ -71,14 +71,6 @@ public class SoundcloudPlaylistExtractorTest {
@Test
public void testMoreRelatedItems() throws Exception {
defaultTestMoreItems(extractor);
try {
defaultTestMoreItems(extractor);
} catch (Throwable ignored) {
return;
}
fail("This playlist doesn't have more items, it should throw an error");
}
/*//////////////////////////////////////////////////////////////////////////
@ -100,7 +92,7 @@ public class SoundcloudPlaylistExtractorTest {
public void testUploaderUrl() {
final String uploaderUrl = extractor.getUploaderUrl();
assertIsSecureUrl(uploaderUrl);
assertTrue(uploaderUrl, uploaderUrl.contains("liluzivert"));
assertThat(uploaderUrl, containsString("liluzivert"));
}
@Test
@ -115,7 +107,7 @@ public class SoundcloudPlaylistExtractorTest {
@Test
public void testStreamCount() {
assertTrue("Error in the streams count", extractor.getStreamCount() >= 10);
assertTrue("Stream count does not fit: " + extractor.getStreamCount(), extractor.getStreamCount() >= 10);
}
}
@ -192,7 +184,7 @@ public class SoundcloudPlaylistExtractorTest {
public void testUploaderUrl() {
final String uploaderUrl = extractor.getUploaderUrl();
assertIsSecureUrl(uploaderUrl);
assertThat(uploaderUrl, CoreMatchers.containsString("micky96"));
assertThat(uploaderUrl, containsString("micky96"));
}
@Test
@ -207,7 +199,7 @@ public class SoundcloudPlaylistExtractorTest {
@Test
public void testStreamCount() {
assertTrue("Error in the streams count", extractor.getStreamCount() >= 10);
assertTrue("Stream count does not fit: " + extractor.getStreamCount(), extractor.getStreamCount() >= 10);
}
}
@ -228,17 +220,8 @@ public class SoundcloudPlaylistExtractorTest {
@Test
public void testGetPageInNewExtractor() throws Exception {
final PlaylistExtractor newExtractor = SoundCloud.getPlaylistExtractor(extractor.getUrl());
PlaylistExtractor newExtractor = SoundCloud.getPlaylistExtractor(extractor.getUrl());
defaultTestGetPageInNewExtractor(extractor, newExtractor);
String page1 = newExtractor.getNextPageUrl();
defaultTestMoreItems(newExtractor); // there has to be another page
String page2 = newExtractor.getNextPageUrl();
defaultTestMoreItems(newExtractor); // and another one
String page3 = newExtractor.getNextPageUrl();
assertNotEquals("Same pages", page1, page2);
assertNotEquals("Same pages", page2, page3);
assertNotEquals("Same pages", page3, page1);
}
/*//////////////////////////////////////////////////////////////////////////
@ -326,4 +309,102 @@ public class SoundcloudPlaylistExtractorTest {
assertTrue("Stream count does not fit: " + extractor.getStreamCount(), extractor.getStreamCount() >= 370);
}
}
public static class SmallPlaylist implements BasePlaylistExtractorTest {
private static SoundcloudPlaylistExtractor extractor;
@BeforeClass
public static void setUp() throws Exception {
NewPipe.init(DownloaderTestImpl.getInstance());
extractor = (SoundcloudPlaylistExtractor) SoundCloud
.getPlaylistExtractor("https://soundcloud.com/breezy-123/sets/empty-playlist?test=123");
extractor.fetchPage();
}
/*//////////////////////////////////////////////////////////////////////////
// Extractor
//////////////////////////////////////////////////////////////////////////*/
@Test
public void testServiceId() {
assertEquals(SoundCloud.getServiceId(), extractor.getServiceId());
}
@Test
public void testName() {
assertEquals("EMPTY PLAYLIST", extractor.getName());
}
@Test
public void testId() {
assertEquals("23483459", extractor.getId());
}
@Test
public void testUrl() throws Exception {
assertEquals("https://soundcloud.com/breezy-123/sets/empty-playlist", extractor.getUrl());
}
@Test
public void testOriginalUrl() throws Exception {
assertEquals("https://soundcloud.com/breezy-123/sets/empty-playlist?test=123", extractor.getOriginalUrl());
}
/*//////////////////////////////////////////////////////////////////////////
// ListExtractor
//////////////////////////////////////////////////////////////////////////*/
@Test
public void testRelatedItems() throws Exception {
defaultTestRelatedItems(extractor);
}
@Test
public void testMoreRelatedItems() throws Exception {
try {
defaultTestMoreItems(extractor);
} catch (Throwable ignored) {
return;
}
fail("This playlist doesn't have more items, it should throw an error");
}
/*//////////////////////////////////////////////////////////////////////////
// PlaylistExtractor
//////////////////////////////////////////////////////////////////////////*/
@Test
public void testThumbnailUrl() {
assertIsSecureUrl(extractor.getThumbnailUrl());
}
@Test
public void testBannerUrl() {
// SoundCloud playlists do not have a banner
assertNull(extractor.getBannerUrl());
}
@Test
public void testUploaderUrl() {
final String uploaderUrl = extractor.getUploaderUrl();
assertIsSecureUrl(uploaderUrl);
assertThat(uploaderUrl, containsString("breezy-123"));
}
@Test
public void testUploaderName() {
assertEquals("breezy-123", extractor.getUploaderName());
}
@Test
public void testUploaderAvatarUrl() {
assertIsSecureUrl(extractor.getUploaderAvatarUrl());
}
@Test
public void testStreamCount() {
assertEquals(2, extractor.getStreamCount());
}
}
}