Various changes regarding tests

This commit is contained in:
Fynn Godau 2020-11-19 22:33:52 +01:00
parent 6bc7e3420e
commit 186936d041
10 changed files with 256 additions and 84 deletions

View file

@ -69,6 +69,7 @@ public class BandcampRadioInfoItemExtractor implements StreamInfoItemExtractor {
@Override
public String getUploaderName() {
// JSON does not contain uploader name
return "";
}

View file

@ -21,6 +21,7 @@ import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Locale;
@ -209,12 +210,12 @@ public class BandcampStreamExtractor extends StreamExtractor {
@Override
public List<VideoStream> getVideoStreams() {
return null;
return Collections.EMPTY_LIST;
}
@Override
public List<VideoStream> getVideoOnlyStreams() {
return null;
return Collections.EMPTY_LIST;
}
@Nonnull

View file

@ -15,7 +15,7 @@ public class BandcampPlaylistStreamInfoItemExtractor extends BandcampStreamInfoI
private final JsonObject track;
private String substituteCoverUrl;
private StreamingService service;
private final StreamingService service;
public BandcampPlaylistStreamInfoItemExtractor(JsonObject track, String uploaderUrl, StreamingService service) {
super(uploaderUrl);
@ -45,6 +45,9 @@ public class BandcampPlaylistStreamInfoItemExtractor extends BandcampStreamInfoI
@Override
public String getUploaderName() {
/* Tracks can have an individual artist name, but it is not included in the
* given JSON.
*/
return "";
}

View file

@ -70,8 +70,8 @@ public class BandcampChannelExtractorTest implements BaseChannelExtractorTest {
}
@Override
public void testServiceId() throws Exception {
assertEquals(4, extractor.getServiceId());
public void testServiceId() {
assertEquals(Bandcamp.getServiceId(), extractor.getServiceId());
}
@Override

View file

@ -40,6 +40,7 @@ public class BandcampChannelLinkHandlerFactoryTest {
assertEquals("1196681540", linkHandler.getId("https://macbenson.bandcamp.com/"));
assertEquals("1581461772", linkHandler.getId("https://interovgm.com/releases"));
assertEquals("3321800855", linkHandler.getId("https://infiniteammo.bandcamp.com/"));
assertEquals("3775652329", linkHandler.getId("https://npet.bandcamp.com/"));
}
@Test

View file

@ -9,18 +9,21 @@ import org.schabi.newpipe.extractor.InfoItem;
import org.schabi.newpipe.extractor.NewPipe;
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
import org.schabi.newpipe.extractor.playlist.PlaylistInfoItem;
import org.schabi.newpipe.extractor.services.BaseListExtractorTest;
import org.schabi.newpipe.extractor.services.DefaultTests;
import org.schabi.newpipe.extractor.services.bandcamp.extractors.BandcampFeaturedExtractor;
import java.io.IOException;
import java.util.List;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.schabi.newpipe.extractor.ServiceList.Bandcamp;
/**
* Tests for {@link BandcampFeaturedExtractor}
*/
public class BandcampFeaturedExtractorTest {
public class BandcampFeaturedExtractorTest implements BaseListExtractorTest {
private static BandcampFeaturedExtractor extractor;
@ -43,4 +46,38 @@ public class BandcampFeaturedExtractorTest {
assertTrue(list.get(0).getUrl().contains("https://"));
}
@Override
public void testRelatedItems() throws Exception {
DefaultTests.defaultTestRelatedItems(extractor);
}
@Override
public void testMoreRelatedItems() throws Exception {
// more items not implemented
}
@Override
public void testServiceId() {
assertEquals(Bandcamp.getServiceId(), extractor.getServiceId());
}
@Override
public void testName() throws Exception {
assertEquals("Featured", extractor.getName());
}
@Override
public void testId() {
assertEquals("", extractor.getId());
}
@Override
public void testUrl() throws Exception {
assertEquals("", extractor.getUrl());
}
@Override
public void testOriginalUrl() throws Exception {
assertEquals("", extractor.getOriginalUrl());
}
}

View file

@ -10,6 +10,8 @@ import org.schabi.newpipe.extractor.exceptions.ContentNotAvailableException;
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
import org.schabi.newpipe.extractor.exceptions.ParsingException;
import org.schabi.newpipe.extractor.playlist.PlaylistExtractor;
import org.schabi.newpipe.extractor.services.BasePlaylistExtractorTest;
import org.schabi.newpipe.extractor.services.DefaultTests;
import org.schabi.newpipe.extractor.services.bandcamp.extractors.BandcampPlaylistExtractor;
import org.schabi.newpipe.extractor.stream.StreamInfoItem;
@ -90,7 +92,7 @@ public class BandcampPlaylistExtractorTest {
}
public static class ComingOfAge {
public static class ComingOfAge implements BasePlaylistExtractorTest {
private static PlaylistExtractor extractor;
@ -102,48 +104,78 @@ public class BandcampPlaylistExtractorTest {
}
@Test
public void getThumbnailUrl() throws ParsingException {
public void testThumbnailUrl() throws ParsingException {
assertTrue(extractor.getThumbnailUrl().contains("f4.bcbits.com/img"));
}
@Test
public void getBannerUrl() throws ParsingException {
public void testBannerUrl() throws ParsingException {
assertEquals("", extractor.getBannerUrl());
}
@Test
public void getUploaderUrl() throws ParsingException {
public void testUploaderUrl() throws ParsingException {
assertTrue(extractor.getUploaderUrl().contains("macbenson.bandcamp.com"));
}
@Test
public void getUploaderName() throws ParsingException {
public void testUploaderName() throws ParsingException {
assertEquals("mac benson", extractor.getUploaderName());
}
@Test
public void getUploaderAvatarUrl() throws ParsingException {
public void testUploaderAvatarUrl() throws ParsingException {
assertTrue(extractor.getUploaderAvatarUrl().contains("f4.bcbits.com/img"));
}
@Test
public void getStreamCount() throws ParsingException {
public void testStreamCount() throws ParsingException {
assertEquals(5, extractor.getStreamCount());
}
@Test
public void getInitialPage() throws IOException, ExtractionException {
public void testInitialPage() throws IOException, ExtractionException {
assertNotNull(extractor.getInitialPage().getItems().get(0));
}
@Test
public void getName() throws ParsingException {
public void testServiceId() {
assertEquals(Bandcamp.getServiceId(), extractor.getServiceId());
}
@Test
public void testName() throws ParsingException {
assertEquals("Coming of Age", extractor.getName());
}
@Test
public void getNextPageUrl() throws IOException, ExtractionException {
public void testId() throws Exception {
assertEquals("https://macbenson.bandcamp.com/album/coming-of-age", extractor.getId());
}
@Test
public void testUrl() throws Exception {
assertEquals("https://macbenson.bandcamp.com/album/coming-of-age", extractor.getUrl());
}
@Test
public void testOriginalUrl() throws Exception {
assertEquals("https://macbenson.bandcamp.com/album/coming-of-age", extractor.getOriginalUrl());
}
@Test
public void testNextPageUrl() throws IOException, ExtractionException {
assertNull(extractor.getPage(extractor.getInitialPage().getNextPage()));
}
@Test
public void testRelatedItems() throws Exception {
//DefaultTests.defaultTestRelatedItems(extractor);
// Would fail because BandcampPlaylistStreamInfoItemExtractor.getUploaderName() returns an empty String
}
@Test
public void testMoreRelatedItems() throws Exception {
}
}
}

View file

@ -8,18 +8,21 @@ import org.schabi.newpipe.DownloaderTestImpl;
import org.schabi.newpipe.extractor.InfoItem;
import org.schabi.newpipe.extractor.NewPipe;
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
import org.schabi.newpipe.extractor.services.BaseListExtractorTest;
import org.schabi.newpipe.extractor.services.DefaultTests;
import org.schabi.newpipe.extractor.services.bandcamp.extractors.BandcampRadioExtractor;
import java.io.IOException;
import java.util.List;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.schabi.newpipe.extractor.ServiceList.Bandcamp;
/**
* Tests for {@link BandcampRadioExtractor}
*/
public class BandcampRadioExtractorTest {
public class BandcampRadioExtractorTest implements BaseListExtractorTest {
private static BandcampRadioExtractor extractor;
@ -36,4 +39,40 @@ public class BandcampRadioExtractorTest {
List<InfoItem> list = Bandcamp.getKioskList().getExtractorById("Radio", null).getInitialPage().getItems();
assertTrue(list.size() > 300);
}
@Test
public void testRelatedItems() throws Exception {
//DefaultTests.defaultTestRelatedItems(extractor);
// Would fail because BandcampRadioInfoItemExtractor.getUploaderName() returns an empty String
}
@Test
public void testMoreRelatedItems() throws Exception {
// All items are on one page
}
@Test
public void testServiceId() {
assertEquals(Bandcamp.getServiceId(), extractor.getServiceId());
}
@Test
public void testName() throws Exception {
assertEquals("Radio", extractor.getName());
}
@Test
public void testId() {
assertEquals("Radio", extractor.getId());
}
@Test
public void testUrl() throws Exception {
assertEquals("https://bandcamp.com/api/bcweekly/1/list", extractor.getUrl());
}
@Test
public void testOriginalUrl() throws Exception {
assertEquals("https://bandcamp.com/api/bcweekly/1/list", extractor.getOriginalUrl());
}
}

View file

@ -107,7 +107,7 @@ public class BandcampSearchExtractorTest {
public static class DefaultTest extends DefaultSearchExtractorTest {
private static SearchExtractor extractor;
private static final String QUERY = "test";
private static final String QUERY = "noise";
@BeforeClass
public static void setUp() throws Exception {

View file

@ -6,103 +6,161 @@ import org.junit.BeforeClass;
import org.junit.Test;
import org.schabi.newpipe.DownloaderTestImpl;
import org.schabi.newpipe.extractor.NewPipe;
import org.schabi.newpipe.extractor.StreamingService;
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
import org.schabi.newpipe.extractor.exceptions.ParsingException;
import org.schabi.newpipe.extractor.services.DefaultStreamExtractorTest;
import org.schabi.newpipe.extractor.services.bandcamp.extractors.BandcampExtractorHelper;
import org.schabi.newpipe.extractor.services.bandcamp.extractors.BandcampStreamExtractor;
import org.schabi.newpipe.extractor.stream.StreamExtractor;
import org.schabi.newpipe.extractor.stream.StreamType;
import java.io.IOException;
import java.util.Calendar;
import java.util.Collections;
import java.util.List;
import java.util.TimeZone;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.schabi.newpipe.extractor.ServiceList.Bandcamp;
public class BandcampStreamExtractorTest {
/**
* Tests for {@link BandcampStreamExtractor}
*/
public class BandcampStreamExtractorTest extends DefaultStreamExtractorTest {
private static BandcampStreamExtractor extractor;
@BeforeClass
public static void setUp() throws Exception {
public static void setUp() throws ExtractionException, IOException {
NewPipe.init(DownloaderTestImpl.getInstance());
// This test track was uploaded specifically for NewPipeExtractor tests
extractor = (BandcampStreamExtractor) Bandcamp
.getStreamExtractor("https://zachbenson.bandcamp.com/track/kitchen");
.getStreamExtractor("https://npet.bandcamp.com/track/track-1");
extractor.fetchPage();
}
@Test
public void testServiceId() {
assertEquals(4, extractor.getServiceId());
@Override
public StreamExtractor extractor() {
return extractor;
}
@Override
public StreamingService expectedService() {
return Bandcamp;
}
@Override
public String expectedName() {
return "Track #1";
}
@Override
public String expectedId() {
return "https://npet.bandcamp.com/track/track-1";
}
@Override
public String expectedUrlContains() {
return "https://npet.bandcamp.com/track/track-1";
}
@Override
public String expectedOriginalUrlContains() {
return "https://npet.bandcamp.com/track/track-1";
}
@Override
public StreamType expectedStreamType() {
return StreamType.AUDIO_STREAM;
}
@Override
public String expectedUploaderName() {
return "NewPipeExtractorTest";
}
@Override
public String expectedUploaderUrl() {
return "https://npet.bandcamp.com/";
}
@Override
public List<String> expectedDescriptionContains() {
return Collections.singletonList("This sample track was created using MuseScore.");
}
@Override
public long expectedLength() {
return 0;
}
@Override
public long expectedViewCountAtLeast() {
return Long.MIN_VALUE;
}
@Override
public String expectedUploadDate() {
return "2020-03-17 18:37:44.000";
}
@Override
public String expectedTextualUploadDate() {
return "17 Mar 2020 18:37:44 GMT";
}
@Override
public long expectedLikeCountAtLeast() {
return Long.MIN_VALUE;
}
@Override
public long expectedDislikeCountAtLeast() {
return Long.MIN_VALUE;
}
@Override
public boolean expectedHasVideoStreams() {
return false;
}
@Override
public boolean expectedHasRelatedStreams() {
return false;
}
@Override
public boolean expectedHasSubtitles() {
return false;
}
@Override
public boolean expectedHasFrames() {
return false;
}
@Override
public String expectedLicence() {
return "CC BY 3.0";
}
@Override
public String expectedCategory() {
return "acoustic";
}
@Test
public void testName() throws ParsingException {
assertEquals("kitchen", extractor.getName());
}
@Test
public void testUrl() throws ParsingException {
assertEquals("https://zachbenson.bandcamp.com/track/kitchen", extractor.getUrl());
}
@Test
public void testArtistUrl() throws ParsingException {
assertEquals("https://zachbenson.bandcamp.com/", extractor.getUploaderUrl());
}
@Test
public void testDescription() {
assertTrue(extractor.getDescription().getContent().contains("Boy, you've taken up my thoughts"));
}
@Test
public void testArtistProfilePicture() {
String url = extractor.getUploaderAvatarUrl();
public void testArtistProfilePicture() throws Exception {
String url = extractor().getUploaderAvatarUrl();
assertTrue(url.contains("://f4.bcbits.com/img/") && url.endsWith(".jpg"));
}
@Test
public void testUploadDate() throws ParsingException {
final Calendar expectedCalendar = Calendar.getInstance();
// 27 Sep 2019 21:49:14 GMT
expectedCalendar.setTimeZone(TimeZone.getTimeZone("GMT"));
expectedCalendar.set(2019, Calendar.SEPTEMBER, 27, 21, 49, 14);
expectedCalendar.set(Calendar.MILLISECOND, 0);
assertEquals(expectedCalendar.getTimeInMillis(), extractor.getUploadDate().date().getTimeInMillis());
}
@Test
public void testNoArtistProfilePicture() throws ExtractionException {
assertEquals("", Bandcamp.getStreamExtractor("https://powertothequeerkids.bandcamp.com/track/human-nature").getUploaderAvatarUrl());
}
@Test
public void testAudioStream() {
assertTrue(extractor.getAudioStreams().get(0).getUrl().contains("bcbits.com/stream"));
assertEquals(1, extractor.getAudioStreams().size());
}
@Test
public void testCategory() throws ExtractionException, IOException {
StreamExtractor se = Bandcamp.getStreamExtractor("https://npet.bandcamp.com/track/track-1");
se.fetchPage();
assertEquals("acoustic", se.getCategory());
}
@Test
public void testLicense() throws ExtractionException, IOException {
StreamExtractor se = Bandcamp.getStreamExtractor("https://npet.bandcamp.com/track/track-1");
se.fetchPage();
assertEquals("CC BY 3.0", se.getLicence());
}
@Test
public void testTranslateIdsToUrl() throws ParsingException {
assertEquals("https://zachbenson.bandcamp.com/album/covers", BandcampExtractorHelper.getStreamUrlFromIds(2862267535L, 2063639444L, "album"));
// TODO write more test cases
assertEquals("https://npet.bandcamp.com/track/track-1", BandcampExtractorHelper.getStreamUrlFromIds(3775652329L, 4207805220L, "track"));
}
}