[Bandcamp] Apply changes in extractor tests

Also remove some public test methods modifiers, add missing Test annotations on
old Junit 4 tests (and update them if needed), and use final in some places
where it was possible.

BandcampChannelExtractorTest.testLength has been removed as the test is always
true.
This commit is contained in:
AudricV 2022-08-03 18:05:44 +02:00
parent 2578f22054
commit 0292c4f3e8
No known key found for this signature in database
GPG Key ID: DA92EC7905614198
6 changed files with 76 additions and 54 deletions

View File

@ -10,7 +10,10 @@ import org.schabi.newpipe.extractor.channel.ChannelExtractor;
import org.schabi.newpipe.extractor.channel.tabs.ChannelTabs; import org.schabi.newpipe.extractor.channel.tabs.ChannelTabs;
import org.schabi.newpipe.extractor.services.BaseChannelExtractorTest; import org.schabi.newpipe.extractor.services.BaseChannelExtractorTest;
import static org.junit.jupiter.api.Assertions.*; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.schabi.newpipe.extractor.ExtractorAsserts.assertTabsContain; import static org.schabi.newpipe.extractor.ExtractorAsserts.assertTabsContain;
import static org.schabi.newpipe.extractor.ServiceList.Bandcamp; import static org.schabi.newpipe.extractor.ServiceList.Bandcamp;
@ -31,51 +34,61 @@ public class BandcampChannelExtractorTest implements BaseChannelExtractorTest {
assertEquals("making music:)", extractor.getDescription()); assertEquals("making music:)", extractor.getDescription());
} }
@Test
@Override @Override
public void testAvatarUrl() throws Exception { public void testAvatars() throws Exception {
assertTrue(extractor.getAvatarUrl().contains("://f4.bcbits.com/"), "unexpected avatar URL"); BandcampTestUtils.testImages(extractor.getAvatars());
} }
@Test
@Override @Override
public void testBannerUrl() throws Exception { public void testBanners() throws Exception {
assertTrue(extractor.getBannerUrl().contains("://f4.bcbits.com/"), "unexpected banner URL"); BandcampTestUtils.testImages(extractor.getBanners());
} }
@Test
@Override @Override
public void testFeedUrl() throws Exception { public void testFeedUrl() throws Exception {
assertNull(extractor.getFeedUrl()); assertNull(extractor.getFeedUrl());
} }
@Test
@Override @Override
public void testSubscriberCount() throws Exception { public void testSubscriberCount() throws Exception {
assertEquals(-1, extractor.getSubscriberCount()); assertEquals(-1, extractor.getSubscriberCount());
} }
@Test
@Override @Override
public void testVerified() throws Exception { public void testVerified() throws Exception {
assertFalse(extractor.isVerified()); assertFalse(extractor.isVerified());
} }
@Test
@Override @Override
public void testServiceId() { public void testServiceId() {
assertEquals(Bandcamp.getServiceId(), extractor.getServiceId()); assertEquals(Bandcamp.getServiceId(), extractor.getServiceId());
} }
@Test
@Override @Override
public void testName() throws Exception { public void testName() throws Exception {
assertEquals("toupie", extractor.getName()); assertEquals("toupie", extractor.getName());
} }
@Test
@Override @Override
public void testId() throws Exception { public void testId() throws Exception {
assertEquals("2450875064", extractor.getId()); assertEquals("2450875064", extractor.getId());
} }
@Test
@Override @Override
public void testUrl() throws Exception { public void testUrl() throws Exception {
assertEquals("https://toupie.bandcamp.com", extractor.getUrl()); assertEquals("https://toupie.bandcamp.com", extractor.getUrl());
} }
@Test
@Override @Override
public void testOriginalUrl() throws Exception { public void testOriginalUrl() throws Exception {
assertEquals("https://toupie.bandcamp.com", extractor.getUrl()); assertEquals("https://toupie.bandcamp.com", extractor.getUrl());

View File

@ -30,22 +30,22 @@ public class BandcampCommentsExtractorTest {
} }
@Test @Test
public void hasComments() throws IOException, ExtractionException { void hasComments() throws IOException, ExtractionException {
assertTrue(extractor.getInitialPage().getItems().size() >= 3); assertTrue(extractor.getInitialPage().getItems().size() >= 3);
} }
@Test @Test
public void testGetCommentsAllData() throws IOException, ExtractionException { void testGetCommentsAllData() throws IOException, ExtractionException {
ListExtractor.InfoItemsPage<CommentsInfoItem> comments = extractor.getInitialPage(); ListExtractor.InfoItemsPage<CommentsInfoItem> comments = extractor.getInitialPage();
assertTrue(comments.hasNextPage()); assertTrue(comments.hasNextPage());
DefaultTests.defaultTestListOfItems(Bandcamp, comments.getItems(), comments.getErrors()); DefaultTests.defaultTestListOfItems(Bandcamp, comments.getItems(), comments.getErrors());
for (CommentsInfoItem c : comments.getItems()) { for (final CommentsInfoItem c : comments.getItems()) {
assertFalse(Utils.isBlank(c.getUploaderName())); assertFalse(Utils.isBlank(c.getUploaderName()));
assertFalse(Utils.isBlank(c.getUploaderAvatarUrl())); BandcampTestUtils.testImages(c.getUploaderAvatars());
assertFalse(Utils.isBlank(c.getCommentText().getContent())); assertFalse(Utils.isBlank(c.getCommentText().getContent()));
assertFalse(Utils.isBlank(c.getName())); assertFalse(Utils.isBlank(c.getName()));
assertFalse(Utils.isBlank(c.getThumbnailUrl())); BandcampTestUtils.testImages(c.getThumbnails());
assertFalse(Utils.isBlank(c.getUrl())); assertFalse(Utils.isBlank(c.getUrl()));
assertEquals(-1, c.getLikeCount()); assertEquals(-1, c.getLikeCount());
assertTrue(Utils.isBlank(c.getTextualLikeCount())); assertTrue(Utils.isBlank(c.getTextualLikeCount()));

View File

@ -19,8 +19,17 @@ import org.schabi.newpipe.extractor.stream.StreamInfoItem;
import java.io.IOException; import java.io.IOException;
import java.util.List; import java.util.List;
import static org.junit.jupiter.api.Assertions.*; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.schabi.newpipe.extractor.ExtractorAsserts.assertContains; import static org.schabi.newpipe.extractor.ExtractorAsserts.assertContains;
import static org.schabi.newpipe.extractor.ExtractorAsserts.assertContainsOnlyEquivalentImages;
import static org.schabi.newpipe.extractor.ExtractorAsserts.assertEmpty;
import static org.schabi.newpipe.extractor.ExtractorAsserts.assertNotOnlyContainsEquivalentImages;
import static org.schabi.newpipe.extractor.ServiceList.Bandcamp; import static org.schabi.newpipe.extractor.ServiceList.Bandcamp;
/** /**
@ -37,7 +46,7 @@ public class BandcampPlaylistExtractorTest {
* Test whether playlists contain the correct amount of items * Test whether playlists contain the correct amount of items
*/ */
@Test @Test
public void testCount() throws ExtractionException, IOException { void testCount() throws ExtractionException, IOException {
final PlaylistExtractor extractor = Bandcamp.getPlaylistExtractor("https://macbenson.bandcamp.com/album/coming-of-age"); final PlaylistExtractor extractor = Bandcamp.getPlaylistExtractor("https://macbenson.bandcamp.com/album/coming-of-age");
extractor.fetchPage(); extractor.fetchPage();
@ -48,13 +57,13 @@ public class BandcampPlaylistExtractorTest {
* Tests whether different stream thumbnails (track covers) get loaded correctly * Tests whether different stream thumbnails (track covers) get loaded correctly
*/ */
@Test @Test
public void testDifferentTrackCovers() throws ExtractionException, IOException { void testDifferentTrackCovers() throws ExtractionException, IOException {
final PlaylistExtractor extractor = Bandcamp.getPlaylistExtractor("https://zachbensonarchive.bandcamp.com/album/results-of-boredom"); final PlaylistExtractor extractor = Bandcamp.getPlaylistExtractor("https://zachbensonarchive.bandcamp.com/album/results-of-boredom");
extractor.fetchPage(); extractor.fetchPage();
final List<StreamInfoItem> l = extractor.getInitialPage().getItems(); final List<StreamInfoItem> l = extractor.getInitialPage().getItems();
assertEquals(extractor.getThumbnailUrl(), l.get(0).getThumbnailUrl()); assertContainsOnlyEquivalentImages(extractor.getThumbnails(), l.get(0).getThumbnails());
assertNotEquals(extractor.getThumbnailUrl(), l.get(5).getThumbnailUrl()); assertNotOnlyContainsEquivalentImages(extractor.getThumbnails(), l.get(5).getThumbnails());
} }
/** /**
@ -62,23 +71,23 @@ public class BandcampPlaylistExtractorTest {
*/ */
@Test @Test
@Timeout(10) @Timeout(10)
public void testDifferentTrackCoversDuration() throws ExtractionException, IOException { void testDifferentTrackCoversDuration() throws ExtractionException, IOException {
final PlaylistExtractor extractor = Bandcamp.getPlaylistExtractor("https://infiniteammo.bandcamp.com/album/night-in-the-woods-vol-1-at-the-end-of-everything"); final PlaylistExtractor extractor = Bandcamp.getPlaylistExtractor("https://infiniteammo.bandcamp.com/album/night-in-the-woods-vol-1-at-the-end-of-everything");
extractor.fetchPage(); extractor.fetchPage();
/* All tracks in this album have the same cover art, but I don't know any albums with more than 10 tracks /* All tracks on this album have the same cover art, but I don't know any albums with more
* that has at least one track with a cover art different from the rest. * than 10 tracks that has at least one track with a cover art different from the rest.
*/ */
final List<StreamInfoItem> l = extractor.getInitialPage().getItems(); final List<StreamInfoItem> l = extractor.getInitialPage().getItems();
assertEquals(extractor.getThumbnailUrl(), l.get(0).getThumbnailUrl()); assertContainsOnlyEquivalentImages(extractor.getThumbnails(), l.get(0).getThumbnails());
assertEquals(extractor.getThumbnailUrl(), l.get(5).getThumbnailUrl()); assertContainsOnlyEquivalentImages(extractor.getThumbnails(), l.get(5).getThumbnails());
} }
/** /**
* Test playlists with locked content * Test playlists with locked content
*/ */
@Test @Test
public void testLockedContent() throws ExtractionException, IOException { void testLockedContent() throws ExtractionException {
final PlaylistExtractor extractor = Bandcamp.getPlaylistExtractor("https://billwurtz.bandcamp.com/album/high-enough"); final PlaylistExtractor extractor = Bandcamp.getPlaylistExtractor("https://billwurtz.bandcamp.com/album/high-enough");
assertThrows(ContentNotAvailableException.class, extractor::fetchPage); assertThrows(ContentNotAvailableException.class, extractor::fetchPage);
@ -88,12 +97,11 @@ public class BandcampPlaylistExtractorTest {
* Test playlist with just one track * Test playlist with just one track
*/ */
@Test @Test
public void testSingleStreamPlaylist() throws ExtractionException, IOException { void testSingleStreamPlaylist() throws ExtractionException, IOException {
final PlaylistExtractor extractor = Bandcamp.getPlaylistExtractor("https://zachjohnson1.bandcamp.com/album/endless"); final PlaylistExtractor extractor = Bandcamp.getPlaylistExtractor("https://zachjohnson1.bandcamp.com/album/endless");
extractor.fetchPage(); extractor.fetchPage();
assertEquals(1, extractor.getStreamCount()); assertEquals(1, extractor.getStreamCount());
} }
public static class ComingOfAge implements BasePlaylistExtractorTest { public static class ComingOfAge implements BasePlaylistExtractorTest {
@ -108,17 +116,17 @@ public class BandcampPlaylistExtractorTest {
} }
@Test @Test
public void testThumbnailUrl() throws ParsingException { public void testThumbnails() throws ParsingException {
assertTrue(extractor.getThumbnailUrl().contains("f4.bcbits.com/img")); BandcampTestUtils.testImages(extractor.getThumbnails());
} }
@Test @Test
public void testBannerUrl() throws ParsingException { public void testBanners() throws ParsingException {
assertEquals("", extractor.getBannerUrl()); assertEmpty(extractor.getBanners());
} }
@Test @Test
public void testUploaderUrl() throws ParsingException { void testUploaderUrl() throws ParsingException {
assertTrue(extractor.getUploaderUrl().contains("macbenson.bandcamp.com")); assertTrue(extractor.getUploaderUrl().contains("macbenson.bandcamp.com"));
} }
@ -128,8 +136,8 @@ public class BandcampPlaylistExtractorTest {
} }
@Test @Test
public void testUploaderAvatarUrl() throws ParsingException { public void testUploaderAvatars() throws ParsingException {
assertTrue(extractor.getUploaderAvatarUrl().contains("f4.bcbits.com/img")); BandcampTestUtils.testImages(extractor.getUploaderAvatars());
} }
@Test @Test
@ -147,13 +155,14 @@ public class BandcampPlaylistExtractorTest {
assertContains("all rights reserved", description.getContent()); // license assertContains("all rights reserved", description.getContent()); // license
} }
@Test
@Override @Override
public void testUploaderVerified() throws Exception { public void testUploaderVerified() throws Exception {
assertFalse(extractor.isUploaderVerified()); assertFalse(extractor.isUploaderVerified());
} }
@Test @Test
public void testInitialPage() throws IOException, ExtractionException { void testInitialPage() throws IOException, ExtractionException {
assertNotNull(extractor.getInitialPage().getItems().get(0)); assertNotNull(extractor.getInitialPage().getItems().get(0));
} }
@ -183,7 +192,7 @@ public class BandcampPlaylistExtractorTest {
} }
@Test @Test
public void testNextPageUrl() throws IOException, ExtractionException { void testNextPageUrl() throws IOException, ExtractionException {
assertNull(extractor.getPage(extractor.getInitialPage().getNextPage())); assertNull(extractor.getPage(extractor.getInitialPage().getNextPage()));
} }

View File

@ -3,12 +3,14 @@ package org.schabi.newpipe.extractor.services.bandcamp;
import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.schabi.newpipe.downloader.DownloaderTestImpl; import org.schabi.newpipe.downloader.DownloaderTestImpl;
import org.schabi.newpipe.extractor.ExtractorAsserts;
import org.schabi.newpipe.extractor.NewPipe; import org.schabi.newpipe.extractor.NewPipe;
import org.schabi.newpipe.extractor.StreamingService; import org.schabi.newpipe.extractor.StreamingService;
import org.schabi.newpipe.extractor.exceptions.ContentNotSupportedException; import org.schabi.newpipe.extractor.exceptions.ContentNotSupportedException;
import org.schabi.newpipe.extractor.exceptions.ExtractionException; import org.schabi.newpipe.extractor.exceptions.ExtractionException;
import org.schabi.newpipe.extractor.exceptions.ParsingException; import org.schabi.newpipe.extractor.exceptions.ParsingException;
import org.schabi.newpipe.extractor.services.DefaultStreamExtractorTest; import org.schabi.newpipe.extractor.services.DefaultStreamExtractorTest;
import org.schabi.newpipe.extractor.services.DefaultTests;
import org.schabi.newpipe.extractor.services.bandcamp.extractors.BandcampRadioStreamExtractor; import org.schabi.newpipe.extractor.services.bandcamp.extractors.BandcampRadioStreamExtractor;
import org.schabi.newpipe.extractor.stream.StreamExtractor; import org.schabi.newpipe.extractor.stream.StreamExtractor;
import org.schabi.newpipe.extractor.stream.StreamType; import org.schabi.newpipe.extractor.stream.StreamType;
@ -36,7 +38,7 @@ public class BandcampRadioStreamExtractorTest extends DefaultStreamExtractorTest
} }
@Test @Test
public void testGettingCorrectStreamExtractor() throws ExtractionException { void testGettingCorrectStreamExtractor() throws ExtractionException {
assertTrue(Bandcamp.getStreamExtractor("https://bandcamp.com/?show=3") instanceof BandcampRadioStreamExtractor); assertTrue(Bandcamp.getStreamExtractor("https://bandcamp.com/?show=3") instanceof BandcampRadioStreamExtractor);
assertFalse(Bandcamp.getStreamExtractor("https://zachbenson.bandcamp.com/track/deflated") assertFalse(Bandcamp.getStreamExtractor("https://zachbenson.bandcamp.com/track/deflated")
instanceof BandcampRadioStreamExtractor); instanceof BandcampRadioStreamExtractor);
@ -57,15 +59,16 @@ public class BandcampRadioStreamExtractorTest extends DefaultStreamExtractorTest
@Override public int expectedStreamSegmentsCount() { return 30; } @Override public int expectedStreamSegmentsCount() { return 30; }
@Test @Test
public void testGetUploaderUrl() { void testGetUploaderUrl() {
assertThrows(ContentNotSupportedException.class, extractor::getUploaderUrl); assertThrows(ContentNotSupportedException.class, extractor::getUploaderUrl);
} }
@Test @Test
@Override @Override
public void testUploaderUrl() throws Exception { public void testUploaderUrl() {
assertThrows(ContentNotSupportedException.class, super::testUploaderUrl); assertThrows(ContentNotSupportedException.class, super::testUploaderUrl);
} }
@Override public String expectedUploaderUrl() { return null; } @Override public String expectedUploaderUrl() { return null; }
@Override @Override
@ -93,16 +96,19 @@ public class BandcampRadioStreamExtractorTest extends DefaultStreamExtractorTest
} }
@Test @Test
public void testGetThumbnailUrl() throws ParsingException { void testGetThumbnails() throws ParsingException {
assertTrue(extractor.getThumbnailUrl().contains("bcbits.com/img")); BandcampTestUtils.testImages(extractor.getThumbnails());
} }
@Test @Test
public void testGetUploaderAvatarUrl() throws ParsingException { void testGetUploaderAvatars() throws ParsingException {
assertTrue(extractor.getUploaderAvatarUrl().contains("bandcamp-button")); DefaultTests.defaultTestImageCollection(extractor.getUploaderAvatars());
extractor.getUploaderAvatars().forEach(image ->
ExtractorAsserts.assertContains("bandcamp-button", image.getUrl()));
} }
@Test public void testGetAudioStreams() throws ExtractionException, IOException { @Test
void testGetAudioStreams() throws ExtractionException, IOException {
assertEquals(1, extractor.getAudioStreams().size()); assertEquals(1, extractor.getAudioStreams().size());
} }
} }

View File

@ -3,7 +3,6 @@
package org.schabi.newpipe.extractor.services.bandcamp; package org.schabi.newpipe.extractor.services.bandcamp;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.schabi.newpipe.extractor.ServiceList.Bandcamp; import static org.schabi.newpipe.extractor.ServiceList.Bandcamp;
import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeAll;
@ -50,8 +49,7 @@ public class BandcampSearchExtractorTest {
// The track by Zach Benson should be the first result, no? // The track by Zach Benson should be the first result, no?
assertEquals("Best Friend's Basement", bestFriendsBasement.getName()); assertEquals("Best Friend's Basement", bestFriendsBasement.getName());
assertEquals("Zach Benson", bestFriendsBasement.getUploaderName()); assertEquals("Zach Benson", bestFriendsBasement.getUploaderName());
assertTrue(bestFriendsBasement.getThumbnailUrl().endsWith(".jpg")); BandcampTestUtils.testImages(bestFriendsBasement.getThumbnails());
assertTrue(bestFriendsBasement.getThumbnailUrl().contains("f4.bcbits.com/img/"));
assertEquals(InfoItem.InfoType.STREAM, bestFriendsBasement.getInfoType()); assertEquals(InfoItem.InfoType.STREAM, bestFriendsBasement.getInfoType());
} }
@ -66,10 +64,8 @@ public class BandcampSearchExtractorTest {
// C418's artist profile should be the first result, no? // C418's artist profile should be the first result, no?
assertEquals("C418", c418.getName()); assertEquals("C418", c418.getName());
assertTrue(c418.getThumbnailUrl().endsWith(".jpg")); BandcampTestUtils.testImages(c418.getThumbnails());
assertTrue(c418.getThumbnailUrl().contains("f4.bcbits.com/img/"));
assertEquals("https://c418.bandcamp.com", c418.getUrl()); assertEquals("https://c418.bandcamp.com", c418.getUrl());
} }
/** /**
@ -82,9 +78,9 @@ public class BandcampSearchExtractorTest {
// Minecraft volume alpha should be the first result, no? // Minecraft volume alpha should be the first result, no?
assertEquals("Minecraft - Volume Alpha", minecraft.getName()); assertEquals("Minecraft - Volume Alpha", minecraft.getName());
assertTrue(minecraft.getThumbnailUrl().endsWith(".jpg")); BandcampTestUtils.testImages(minecraft.getThumbnails());
assertTrue(minecraft.getThumbnailUrl().contains("f4.bcbits.com/img/")); assertEquals(
assertEquals("https://c418.bandcamp.com/album/minecraft-volume-alpha", "https://c418.bandcamp.com/album/minecraft-volume-alpha",
minecraft.getUrl()); minecraft.getUrl());
// Verify that playlist tracks counts get extracted correctly // Verify that playlist tracks counts get extracted correctly

View File

@ -20,7 +20,6 @@ import java.util.Collections;
import java.util.List; import java.util.List;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.schabi.newpipe.extractor.ServiceList.Bandcamp; import static org.schabi.newpipe.extractor.ServiceList.Bandcamp;
/** /**
@ -150,13 +149,12 @@ public class BandcampStreamExtractorTest extends DefaultStreamExtractorTest {
} }
@Test @Test
public void testArtistProfilePicture() throws Exception { void testArtistProfilePictures() {
final String url = extractor().getUploaderAvatarUrl(); BandcampTestUtils.testImages(extractor.getUploaderAvatars());
assertTrue(url.contains("://f4.bcbits.com/img/") && url.endsWith(".jpg"));
} }
@Test @Test
public void testTranslateIdsToUrl() throws ParsingException { void testTranslateIdsToUrl() throws ParsingException {
// To add tests: look at website's source, search for `band_id` and `item_id` // To add tests: look at website's source, search for `band_id` and `item_id`
assertEquals( assertEquals(
"https://teaganbear.bandcamp.com/track/just-for-the-halibut-creative-commons-attribution", "https://teaganbear.bandcamp.com/track/just-for-the-halibut-creative-commons-attribution",