Add SoundcloudChartsExtractor
This commit is contained in:
@@ -0,0 +1,85 @@
|
||||
package org.schabi.newpipe.extractor.services.soundcloud;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
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;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.schabi.newpipe.Downloader;
|
||||
import org.schabi.newpipe.extractor.InfoItemCollector;
|
||||
import org.schabi.newpipe.extractor.NewPipe;
|
||||
import org.schabi.newpipe.extractor.kiosk.KioskExtractor;
|
||||
|
||||
/**
|
||||
* Test for {@link SoundcloudChartsUrlIdHandler}
|
||||
*/
|
||||
public class SoundcloudChartsExtractorTest {
|
||||
|
||||
KioskExtractor extractor;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
NewPipe.init(Downloader.getInstance());
|
||||
extractor = SoundCloud.getService()
|
||||
.getKioskList()
|
||||
.getExtractorByType("Top 50");
|
||||
extractor.fetchPage();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetDownloader() throws Exception {
|
||||
assertNotNull(NewPipe.getDownloader());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetName() throws Exception {
|
||||
assertEquals(extractor.getName(), "Top 50");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testId() throws Exception {
|
||||
assertEquals(extractor.getId(), "Top 50");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetStreams() throws Exception {
|
||||
InfoItemCollector collector = extractor.getStreams();
|
||||
if(!collector.getErrors().isEmpty()) {
|
||||
System.err.println("----------");
|
||||
for(Throwable e : collector.getErrors()) {
|
||||
e.printStackTrace();
|
||||
System.err.println("----------");
|
||||
}
|
||||
}
|
||||
assertTrue("no streams are received",
|
||||
!collector.getItemList().isEmpty()
|
||||
&& collector.getErrors().isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetStreamsErrors() throws Exception {
|
||||
assertTrue("errors during stream list extraction", extractor.getStreams().getErrors().isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHasMoreStreams() throws Exception {
|
||||
// Setup the streams
|
||||
extractor.getStreams();
|
||||
assertTrue("has more streams", extractor.hasMoreStreams());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetNextStreams() throws Exception {
|
||||
extractor.getStreams();
|
||||
assertFalse("extractor has next streams", extractor.getNextStreams() == null
|
||||
|| extractor.getNextStreams().nextItemsList.isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetCleanUrl() throws Exception {
|
||||
assertEquals(extractor.getCleanUrl(), "https://soundcloud.com/charts/top");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
package org.schabi.newpipe.extractor.services.soundcloud;
|
||||
|
||||
import static junit.framework.TestCase.assertFalse;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.schabi.newpipe.Downloader;
|
||||
import org.schabi.newpipe.extractor.NewPipe;
|
||||
|
||||
/**
|
||||
* Test for {@link SoundcloudChartsUrlIdHandler}
|
||||
*/
|
||||
public class SoundcloudChartsUrlIdHandlerTest {
|
||||
private SoundcloudChartsUrlIdHandler urlIdHandler;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
urlIdHandler = new SoundcloudChartsUrlIdHandler();
|
||||
NewPipe.init(Downloader.getInstance());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getUrl() {
|
||||
assertEquals(urlIdHandler.getUrl("Top 50"), "https://soundcloud.com/charts/top");
|
||||
assertEquals(urlIdHandler.getUrl("New & hot"), "https://soundcloud.com/charts/new");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getId() {
|
||||
assertEquals(urlIdHandler.getId("http://soundcloud.com/charts/top?genre=all-music"), "Top 50");
|
||||
assertEquals(urlIdHandler.getId("HTTP://www.soundcloud.com/charts/new/?genre=all-music&country=all-countries"), "New & hot");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void acceptUrl() {
|
||||
assertTrue(urlIdHandler.acceptUrl("https://soundcloud.com/charts"));
|
||||
assertTrue(urlIdHandler.acceptUrl("https://soundcloud.com/charts/"));
|
||||
assertTrue(urlIdHandler.acceptUrl("https://www.soundcloud.com/charts/new"));
|
||||
assertTrue(urlIdHandler.acceptUrl("http://soundcloud.com/charts/top?genre=all-music"));
|
||||
assertTrue(urlIdHandler.acceptUrl("HTTP://www.soundcloud.com/charts/new/?genre=all-music&country=all-countries"));
|
||||
|
||||
assertFalse(urlIdHandler.acceptUrl("kdskjfiiejfia"));
|
||||
assertFalse(urlIdHandler.acceptUrl("soundcloud.com/charts askjkf"));
|
||||
assertFalse(urlIdHandler.acceptUrl(" soundcloud.com/charts"));
|
||||
assertFalse(urlIdHandler.acceptUrl(""));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user