Skip to content

Commit

Permalink
Improve kiosk tests across services
Browse files Browse the repository at this point in the history
  • Loading branch information
mauriciocolli authored and TobiGr committed Mar 1, 2020
1 parent e590417 commit 90ae5fb
Show file tree
Hide file tree
Showing 4 changed files with 221 additions and 227 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,90 +5,75 @@
import org.schabi.newpipe.DownloaderTestImpl;
import org.schabi.newpipe.extractor.ListExtractor;
import org.schabi.newpipe.extractor.NewPipe;
import org.schabi.newpipe.extractor.exceptions.ParsingException;
import org.schabi.newpipe.extractor.kiosk.KioskExtractor;
import org.schabi.newpipe.extractor.services.BaseListExtractorTest;
import org.schabi.newpipe.extractor.services.peertube.extractors.PeertubeTrendingExtractor;
import org.schabi.newpipe.extractor.services.soundcloud.SoundcloudChartsExtractor;
import org.schabi.newpipe.extractor.services.youtube.extractors.YoutubeTrendingExtractor;
import org.schabi.newpipe.extractor.stream.StreamInfoItem;

import java.util.List;

import static org.junit.Assert.*;
import static org.schabi.newpipe.extractor.ServiceList.PeerTube;
import static org.schabi.newpipe.extractor.ServiceList.*;
import static org.schabi.newpipe.extractor.services.DefaultTests.*;

/**
* Test for {@link PeertubeTrendingExtractor}
*/
public class PeertubeTrendingExtractorTest {
public static class Trending implements BaseListExtractorTest {
private static PeertubeTrendingExtractor extractor;

static KioskExtractor extractor;
@BeforeClass
public static void setUp() throws Exception {
NewPipe.init(DownloaderTestImpl.getInstance());
// setting instance might break test when running in parallel
PeerTube.setInstance(new PeertubeInstance("https://peertube.mastodon.host", "PeerTube on Mastodon.host"));
extractor = (PeertubeTrendingExtractor) PeerTube.getKioskList()
.getExtractorById("Trending", null);
extractor.fetchPage();
}

@BeforeClass
public static void setUp() throws Exception {
NewPipe.init(DownloaderTestImpl.getInstance());
// setting instance might break test when running in parallel
PeerTube.setInstance(new PeertubeInstance("https://peertube.mastodon.host", "PeerTube on Mastodon.host"));
extractor = PeerTube
.getKioskList()
.getExtractorById("Trending", null);
extractor.fetchPage();
}
/*//////////////////////////////////////////////////////////////////////////
// Extractor
//////////////////////////////////////////////////////////////////////////*/

@Test
public void testGetDownloader() throws Exception {
assertNotNull(NewPipe.getDownloader());
}

@Test
public void testGetName() throws Exception {
assertEquals(extractor.getName(), "Trending");
}
@Test
public void testServiceId() {
assertEquals(PeerTube.getServiceId(), extractor.getServiceId());
}

@Test
public void testId() {
assertEquals(extractor.getId(), "Trending");
}
@Test
public void testName() throws Exception {
assertEquals("Trending", extractor.getName());
}

@Test
public void testGetStreams() throws Exception {
ListExtractor.InfoItemsPage<StreamInfoItem> page = extractor.getInitialPage();
if (!page.getErrors().isEmpty()) {
System.err.println("----------");
List<Throwable> errors = page.getErrors();
for (Throwable e : errors) {
e.printStackTrace();
System.err.println("----------");
}
@Test
public void testId() throws Exception {
assertEquals("Trending", extractor.getId());
}
assertTrue("no streams are received",
!page.getItems().isEmpty()
&& page.getErrors().isEmpty());
}

@Test
public void testGetStreamsErrors() throws Exception {
assertTrue("errors during stream list extraction", extractor.getInitialPage().getErrors().isEmpty());
}
@Test
public void testUrl() throws ParsingException {
assertEquals("https://peertube.mastodon.host/api/v1/videos?sort=-trending", extractor.getUrl());
}

@Test
public void testHasMoreStreams() throws Exception {
// Setup the streams
extractor.getInitialPage();
assertTrue("has more streams", extractor.hasNextPage());
}
@Test
public void testOriginalUrl() throws ParsingException {
assertEquals("https://peertube.mastodon.host/api/v1/videos?sort=-trending", extractor.getOriginalUrl());
}

@Test
public void testGetNextPageUrl() throws Exception {
assertTrue(extractor.hasNextPage());
}
/*//////////////////////////////////////////////////////////////////////////
// ListExtractor
//////////////////////////////////////////////////////////////////////////*/

@Test
public void testGetNextPage() throws Exception {
extractor.getInitialPage().getItems();
assertFalse("extractor has next streams", extractor.getPage(extractor.getNextPageUrl()) == null
|| extractor.getPage(extractor.getNextPageUrl()).getItems().isEmpty());
}
@Test
public void testRelatedItems() throws Exception {
defaultTestRelatedItems(extractor);
}

@Test
public void testGetCleanUrl() throws Exception {
assertEquals(extractor.getUrl(), "https://peertube.mastodon.host/api/v1/videos?sort=-trending");
@Test
public void testMoreRelatedItems() throws Exception {
defaultTestMoreItems(extractor);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,87 +5,127 @@
import org.schabi.newpipe.DownloaderTestImpl;
import org.schabi.newpipe.extractor.ListExtractor;
import org.schabi.newpipe.extractor.NewPipe;
import org.schabi.newpipe.extractor.exceptions.ParsingException;
import org.schabi.newpipe.extractor.kiosk.KioskExtractor;
import org.schabi.newpipe.extractor.services.BaseListExtractorTest;
import org.schabi.newpipe.extractor.services.youtube.extractors.YoutubeTrendingExtractor;
import org.schabi.newpipe.extractor.stream.StreamInfoItem;

import java.util.List;

import static org.junit.Assert.*;
import static org.schabi.newpipe.extractor.ServiceList.SoundCloud;
import static org.schabi.newpipe.extractor.ServiceList.YouTube;
import static org.schabi.newpipe.extractor.services.DefaultTests.*;

/**
* Test for {@link SoundcloudChartsLinkHandlerFactory}
*/
public class SoundcloudChartsExtractorTest {
public static class NewAndHot implements BaseListExtractorTest {
private static SoundcloudChartsExtractor extractor;

static KioskExtractor extractor;
@BeforeClass
public static void setUp() throws Exception {
NewPipe.init(DownloaderTestImpl.getInstance());
extractor = (SoundcloudChartsExtractor) SoundCloud.getKioskList()
.getExtractorById("New & hot", null);
extractor.fetchPage();
}

@BeforeClass
public static void setUp() throws Exception {
NewPipe.init(DownloaderTestImpl.getInstance());
extractor = SoundCloud
.getKioskList()
.getExtractorById("Top 50", null);
extractor.fetchPage();
}
/*//////////////////////////////////////////////////////////////////////////
// Extractor
//////////////////////////////////////////////////////////////////////////*/

@Test
public void testGetDownloader() throws Exception {
assertNotNull(NewPipe.getDownloader());
}
@Test
public void testServiceId() {
assertEquals(SoundCloud.getServiceId(), extractor.getServiceId());
}

@Test
public void testGetName() throws Exception {
assertEquals(extractor.getName(), "Top 50");
}
@Test
public void testName() {
assertEquals("New & hot", extractor.getName());
}

@Test
public void testId() {
assertEquals(extractor.getId(), "Top 50");
}
@Test
public void testId() {
assertEquals("New & hot", extractor.getId());
}

@Test
public void testGetStreams() throws Exception {
ListExtractor.InfoItemsPage<StreamInfoItem> page = extractor.getInitialPage();
if (!page.getErrors().isEmpty()) {
System.err.println("----------");
List<Throwable> errors = page.getErrors();
for (Throwable e : errors) {
e.printStackTrace();
System.err.println("----------");
}
}
assertTrue("no streams are received",
!page.getItems().isEmpty()
&& page.getErrors().isEmpty());
}
@Test
public void testUrl() throws ParsingException {
assertEquals("https://soundcloud.com/charts/new", extractor.getUrl());
}

@Test
public void testGetStreamsErrors() throws Exception {
assertTrue("errors during stream list extraction", extractor.getInitialPage().getErrors().isEmpty());
}
@Test
public void testOriginalUrl() throws ParsingException {
assertEquals("https://soundcloud.com/charts/new", extractor.getOriginalUrl());
}

@Test
public void testHasMoreStreams() throws Exception {
// Setup the streams
extractor.getInitialPage();
assertTrue("has more streams", extractor.hasNextPage());
}
/*//////////////////////////////////////////////////////////////////////////
// ListExtractor
//////////////////////////////////////////////////////////////////////////*/

@Test
public void testGetNextPageUrl() throws Exception {
assertTrue(extractor.hasNextPage());
}
@Test
public void testRelatedItems() throws Exception {
defaultTestRelatedItems(extractor);
}

@Test
public void testGetNextPage() throws Exception {
extractor.getInitialPage().getItems();
assertFalse("extractor has next streams", extractor.getPage(extractor.getNextPageUrl()) == null
|| extractor.getPage(extractor.getNextPageUrl()).getItems().isEmpty());
@Test
public void testMoreRelatedItems() throws Exception {
defaultTestMoreItems(extractor);
}
}

@Test
public void testGetCleanUrl() throws Exception {
assertEquals(extractor.getUrl(), "https://soundcloud.com/charts/top");
public static class Top50Charts implements BaseListExtractorTest {
private static SoundcloudChartsExtractor extractor;

@BeforeClass
public static void setUp() throws Exception {
NewPipe.init(DownloaderTestImpl.getInstance());
extractor = (SoundcloudChartsExtractor) SoundCloud.getKioskList()
.getExtractorById("Top 50", null);
extractor.fetchPage();
}

/*//////////////////////////////////////////////////////////////////////////
// Extractor
//////////////////////////////////////////////////////////////////////////*/

@Test
public void testServiceId() {
assertEquals(SoundCloud.getServiceId(), extractor.getServiceId());
}

@Test
public void testName() {
assertEquals("Top 50", extractor.getName());
}

@Test
public void testId() {
assertEquals("Top 50", extractor.getId());
}

@Test
public void testUrl() throws ParsingException {
assertEquals("https://soundcloud.com/charts/top", extractor.getUrl());
}

@Test
public void testOriginalUrl() throws ParsingException {
assertEquals("https://soundcloud.com/charts/top", extractor.getOriginalUrl());
}

/*//////////////////////////////////////////////////////////////////////////
// ListExtractor
//////////////////////////////////////////////////////////////////////////*/

@Test
public void testRelatedItems() throws Exception {
defaultTestRelatedItems(extractor);
}

@Test
public void testMoreRelatedItems() throws Exception {
defaultTestMoreItems(extractor);
}
}
}
Loading

0 comments on commit 90ae5fb

Please sign in to comment.