Skip to content

Commit 0292c4f

Browse files
committed
[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.
1 parent 2578f22 commit 0292c4f

6 files changed

Lines changed: 76 additions & 54 deletions

File tree

extractor/src/test/java/org/schabi/newpipe/extractor/services/bandcamp/BandcampChannelExtractorTest.java

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@
1010
import org.schabi.newpipe.extractor.channel.tabs.ChannelTabs;
1111
import org.schabi.newpipe.extractor.services.BaseChannelExtractorTest;
1212

13-
import static org.junit.jupiter.api.Assertions.*;
13+
import static org.junit.jupiter.api.Assertions.assertEquals;
14+
import static org.junit.jupiter.api.Assertions.assertFalse;
15+
import static org.junit.jupiter.api.Assertions.assertNull;
16+
import static org.junit.jupiter.api.Assertions.assertTrue;
1417
import static org.schabi.newpipe.extractor.ExtractorAsserts.assertTabsContain;
1518
import static org.schabi.newpipe.extractor.ServiceList.Bandcamp;
1619

@@ -31,51 +34,61 @@ public void testDescription() throws Exception {
3134
assertEquals("making music:)", extractor.getDescription());
3235
}
3336

37+
@Test
3438
@Override
35-
public void testAvatarUrl() throws Exception {
36-
assertTrue(extractor.getAvatarUrl().contains("://f4.bcbits.com/"), "unexpected avatar URL");
39+
public void testAvatars() throws Exception {
40+
BandcampTestUtils.testImages(extractor.getAvatars());
3741
}
3842

43+
@Test
3944
@Override
40-
public void testBannerUrl() throws Exception {
41-
assertTrue(extractor.getBannerUrl().contains("://f4.bcbits.com/"), "unexpected banner URL");
45+
public void testBanners() throws Exception {
46+
BandcampTestUtils.testImages(extractor.getBanners());
4247
}
4348

49+
@Test
4450
@Override
4551
public void testFeedUrl() throws Exception {
4652
assertNull(extractor.getFeedUrl());
4753
}
4854

55+
@Test
4956
@Override
5057
public void testSubscriberCount() throws Exception {
5158
assertEquals(-1, extractor.getSubscriberCount());
5259
}
5360

61+
@Test
5462
@Override
5563
public void testVerified() throws Exception {
5664
assertFalse(extractor.isVerified());
5765
}
5866

67+
@Test
5968
@Override
6069
public void testServiceId() {
6170
assertEquals(Bandcamp.getServiceId(), extractor.getServiceId());
6271
}
6372

73+
@Test
6474
@Override
6575
public void testName() throws Exception {
6676
assertEquals("toupie", extractor.getName());
6777
}
6878

79+
@Test
6980
@Override
7081
public void testId() throws Exception {
7182
assertEquals("2450875064", extractor.getId());
7283
}
7384

85+
@Test
7486
@Override
7587
public void testUrl() throws Exception {
7688
assertEquals("https://toupie.bandcamp.com", extractor.getUrl());
7789
}
7890

91+
@Test
7992
@Override
8093
public void testOriginalUrl() throws Exception {
8194
assertEquals("https://toupie.bandcamp.com", extractor.getUrl());

extractor/src/test/java/org/schabi/newpipe/extractor/services/bandcamp/BandcampCommentsExtractorTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,22 +30,22 @@ public static void setUp() throws ExtractionException, IOException {
3030
}
3131

3232
@Test
33-
public void hasComments() throws IOException, ExtractionException {
33+
void hasComments() throws IOException, ExtractionException {
3434
assertTrue(extractor.getInitialPage().getItems().size() >= 3);
3535
}
3636

3737
@Test
38-
public void testGetCommentsAllData() throws IOException, ExtractionException {
38+
void testGetCommentsAllData() throws IOException, ExtractionException {
3939
ListExtractor.InfoItemsPage<CommentsInfoItem> comments = extractor.getInitialPage();
4040
assertTrue(comments.hasNextPage());
4141

4242
DefaultTests.defaultTestListOfItems(Bandcamp, comments.getItems(), comments.getErrors());
43-
for (CommentsInfoItem c : comments.getItems()) {
43+
for (final CommentsInfoItem c : comments.getItems()) {
4444
assertFalse(Utils.isBlank(c.getUploaderName()));
45-
assertFalse(Utils.isBlank(c.getUploaderAvatarUrl()));
45+
BandcampTestUtils.testImages(c.getUploaderAvatars());
4646
assertFalse(Utils.isBlank(c.getCommentText().getContent()));
4747
assertFalse(Utils.isBlank(c.getName()));
48-
assertFalse(Utils.isBlank(c.getThumbnailUrl()));
48+
BandcampTestUtils.testImages(c.getThumbnails());
4949
assertFalse(Utils.isBlank(c.getUrl()));
5050
assertEquals(-1, c.getLikeCount());
5151
assertTrue(Utils.isBlank(c.getTextualLikeCount()));

extractor/src/test/java/org/schabi/newpipe/extractor/services/bandcamp/BandcampPlaylistExtractorTest.java

Lines changed: 31 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,17 @@
1919
import java.io.IOException;
2020
import java.util.List;
2121

22-
import static org.junit.jupiter.api.Assertions.*;
22+
import static org.junit.jupiter.api.Assertions.assertEquals;
23+
import static org.junit.jupiter.api.Assertions.assertFalse;
24+
import static org.junit.jupiter.api.Assertions.assertNotEquals;
25+
import static org.junit.jupiter.api.Assertions.assertNotNull;
26+
import static org.junit.jupiter.api.Assertions.assertNull;
27+
import static org.junit.jupiter.api.Assertions.assertThrows;
28+
import static org.junit.jupiter.api.Assertions.assertTrue;
2329
import static org.schabi.newpipe.extractor.ExtractorAsserts.assertContains;
30+
import static org.schabi.newpipe.extractor.ExtractorAsserts.assertContainsOnlyEquivalentImages;
31+
import static org.schabi.newpipe.extractor.ExtractorAsserts.assertEmpty;
32+
import static org.schabi.newpipe.extractor.ExtractorAsserts.assertNotOnlyContainsEquivalentImages;
2433
import static org.schabi.newpipe.extractor.ServiceList.Bandcamp;
2534

2635
/**
@@ -37,7 +46,7 @@ public static void setUp() {
3746
* Test whether playlists contain the correct amount of items
3847
*/
3948
@Test
40-
public void testCount() throws ExtractionException, IOException {
49+
void testCount() throws ExtractionException, IOException {
4150
final PlaylistExtractor extractor = Bandcamp.getPlaylistExtractor("https://macbenson.bandcamp.com/album/coming-of-age");
4251
extractor.fetchPage();
4352

@@ -48,37 +57,37 @@ public void testCount() throws ExtractionException, IOException {
4857
* Tests whether different stream thumbnails (track covers) get loaded correctly
4958
*/
5059
@Test
51-
public void testDifferentTrackCovers() throws ExtractionException, IOException {
60+
void testDifferentTrackCovers() throws ExtractionException, IOException {
5261
final PlaylistExtractor extractor = Bandcamp.getPlaylistExtractor("https://zachbensonarchive.bandcamp.com/album/results-of-boredom");
5362
extractor.fetchPage();
5463

5564
final List<StreamInfoItem> l = extractor.getInitialPage().getItems();
56-
assertEquals(extractor.getThumbnailUrl(), l.get(0).getThumbnailUrl());
57-
assertNotEquals(extractor.getThumbnailUrl(), l.get(5).getThumbnailUrl());
65+
assertContainsOnlyEquivalentImages(extractor.getThumbnails(), l.get(0).getThumbnails());
66+
assertNotOnlyContainsEquivalentImages(extractor.getThumbnails(), l.get(5).getThumbnails());
5867
}
5968

6069
/**
6170
* Tests that no attempt to load every track's cover individually is made
6271
*/
6372
@Test
6473
@Timeout(10)
65-
public void testDifferentTrackCoversDuration() throws ExtractionException, IOException {
74+
void testDifferentTrackCoversDuration() throws ExtractionException, IOException {
6675
final PlaylistExtractor extractor = Bandcamp.getPlaylistExtractor("https://infiniteammo.bandcamp.com/album/night-in-the-woods-vol-1-at-the-end-of-everything");
6776
extractor.fetchPage();
6877

69-
/* All tracks in this album have the same cover art, but I don't know any albums with more than 10 tracks
70-
* that has at least one track with a cover art different from the rest.
78+
/* All tracks on this album have the same cover art, but I don't know any albums with more
79+
* than 10 tracks that has at least one track with a cover art different from the rest.
7180
*/
7281
final List<StreamInfoItem> l = extractor.getInitialPage().getItems();
73-
assertEquals(extractor.getThumbnailUrl(), l.get(0).getThumbnailUrl());
74-
assertEquals(extractor.getThumbnailUrl(), l.get(5).getThumbnailUrl());
82+
assertContainsOnlyEquivalentImages(extractor.getThumbnails(), l.get(0).getThumbnails());
83+
assertContainsOnlyEquivalentImages(extractor.getThumbnails(), l.get(5).getThumbnails());
7584
}
7685

7786
/**
7887
* Test playlists with locked content
7988
*/
8089
@Test
81-
public void testLockedContent() throws ExtractionException, IOException {
90+
void testLockedContent() throws ExtractionException {
8291
final PlaylistExtractor extractor = Bandcamp.getPlaylistExtractor("https://billwurtz.bandcamp.com/album/high-enough");
8392

8493
assertThrows(ContentNotAvailableException.class, extractor::fetchPage);
@@ -88,12 +97,11 @@ public void testLockedContent() throws ExtractionException, IOException {
8897
* Test playlist with just one track
8998
*/
9099
@Test
91-
public void testSingleStreamPlaylist() throws ExtractionException, IOException {
100+
void testSingleStreamPlaylist() throws ExtractionException, IOException {
92101
final PlaylistExtractor extractor = Bandcamp.getPlaylistExtractor("https://zachjohnson1.bandcamp.com/album/endless");
93102
extractor.fetchPage();
94103

95104
assertEquals(1, extractor.getStreamCount());
96-
97105
}
98106

99107
public static class ComingOfAge implements BasePlaylistExtractorTest {
@@ -108,17 +116,17 @@ public static void setUp() throws ExtractionException, IOException {
108116
}
109117

110118
@Test
111-
public void testThumbnailUrl() throws ParsingException {
112-
assertTrue(extractor.getThumbnailUrl().contains("f4.bcbits.com/img"));
119+
public void testThumbnails() throws ParsingException {
120+
BandcampTestUtils.testImages(extractor.getThumbnails());
113121
}
114122

115123
@Test
116-
public void testBannerUrl() throws ParsingException {
117-
assertEquals("", extractor.getBannerUrl());
124+
public void testBanners() throws ParsingException {
125+
assertEmpty(extractor.getBanners());
118126
}
119127

120128
@Test
121-
public void testUploaderUrl() throws ParsingException {
129+
void testUploaderUrl() throws ParsingException {
122130
assertTrue(extractor.getUploaderUrl().contains("macbenson.bandcamp.com"));
123131
}
124132

@@ -128,8 +136,8 @@ public void testUploaderName() throws ParsingException {
128136
}
129137

130138
@Test
131-
public void testUploaderAvatarUrl() throws ParsingException {
132-
assertTrue(extractor.getUploaderAvatarUrl().contains("f4.bcbits.com/img"));
139+
public void testUploaderAvatars() throws ParsingException {
140+
BandcampTestUtils.testImages(extractor.getUploaderAvatars());
133141
}
134142

135143
@Test
@@ -147,13 +155,14 @@ public void testDescription() throws ParsingException {
147155
assertContains("all rights reserved", description.getContent()); // license
148156
}
149157

158+
@Test
150159
@Override
151160
public void testUploaderVerified() throws Exception {
152161
assertFalse(extractor.isUploaderVerified());
153162
}
154163

155164
@Test
156-
public void testInitialPage() throws IOException, ExtractionException {
165+
void testInitialPage() throws IOException, ExtractionException {
157166
assertNotNull(extractor.getInitialPage().getItems().get(0));
158167
}
159168

@@ -183,7 +192,7 @@ public void testOriginalUrl() throws Exception {
183192
}
184193

185194
@Test
186-
public void testNextPageUrl() throws IOException, ExtractionException {
195+
void testNextPageUrl() throws IOException, ExtractionException {
187196
assertNull(extractor.getPage(extractor.getInitialPage().getNextPage()));
188197
}
189198

extractor/src/test/java/org/schabi/newpipe/extractor/services/bandcamp/BandcampRadioStreamExtractorTest.java

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@
33
import org.junit.jupiter.api.BeforeAll;
44
import org.junit.jupiter.api.Test;
55
import org.schabi.newpipe.downloader.DownloaderTestImpl;
6+
import org.schabi.newpipe.extractor.ExtractorAsserts;
67
import org.schabi.newpipe.extractor.NewPipe;
78
import org.schabi.newpipe.extractor.StreamingService;
89
import org.schabi.newpipe.extractor.exceptions.ContentNotSupportedException;
910
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
1011
import org.schabi.newpipe.extractor.exceptions.ParsingException;
1112
import org.schabi.newpipe.extractor.services.DefaultStreamExtractorTest;
13+
import org.schabi.newpipe.extractor.services.DefaultTests;
1214
import org.schabi.newpipe.extractor.services.bandcamp.extractors.BandcampRadioStreamExtractor;
1315
import org.schabi.newpipe.extractor.stream.StreamExtractor;
1416
import org.schabi.newpipe.extractor.stream.StreamType;
@@ -36,7 +38,7 @@ public static void setUp() throws IOException, ExtractionException {
3638
}
3739

3840
@Test
39-
public void testGettingCorrectStreamExtractor() throws ExtractionException {
41+
void testGettingCorrectStreamExtractor() throws ExtractionException {
4042
assertTrue(Bandcamp.getStreamExtractor("https://bandcamp.com/?show=3") instanceof BandcampRadioStreamExtractor);
4143
assertFalse(Bandcamp.getStreamExtractor("https://zachbenson.bandcamp.com/track/deflated")
4244
instanceof BandcampRadioStreamExtractor);
@@ -57,15 +59,16 @@ public void testGettingCorrectStreamExtractor() throws ExtractionException {
5759
@Override public int expectedStreamSegmentsCount() { return 30; }
5860

5961
@Test
60-
public void testGetUploaderUrl() {
62+
void testGetUploaderUrl() {
6163
assertThrows(ContentNotSupportedException.class, extractor::getUploaderUrl);
6264
}
6365

6466
@Test
6567
@Override
66-
public void testUploaderUrl() throws Exception {
68+
public void testUploaderUrl() {
6769
assertThrows(ContentNotSupportedException.class, super::testUploaderUrl);
6870
}
71+
6972
@Override public String expectedUploaderUrl() { return null; }
7073

7174
@Override
@@ -93,16 +96,19 @@ public void testUploadDate() throws ParsingException {
9396
}
9497

9598
@Test
96-
public void testGetThumbnailUrl() throws ParsingException {
97-
assertTrue(extractor.getThumbnailUrl().contains("bcbits.com/img"));
99+
void testGetThumbnails() throws ParsingException {
100+
BandcampTestUtils.testImages(extractor.getThumbnails());
98101
}
99102

100103
@Test
101-
public void testGetUploaderAvatarUrl() throws ParsingException {
102-
assertTrue(extractor.getUploaderAvatarUrl().contains("bandcamp-button"));
104+
void testGetUploaderAvatars() throws ParsingException {
105+
DefaultTests.defaultTestImageCollection(extractor.getUploaderAvatars());
106+
extractor.getUploaderAvatars().forEach(image ->
107+
ExtractorAsserts.assertContains("bandcamp-button", image.getUrl()));
103108
}
104109

105-
@Test public void testGetAudioStreams() throws ExtractionException, IOException {
110+
@Test
111+
void testGetAudioStreams() throws ExtractionException, IOException {
106112
assertEquals(1, extractor.getAudioStreams().size());
107113
}
108114
}

extractor/src/test/java/org/schabi/newpipe/extractor/services/bandcamp/BandcampSearchExtractorTest.java

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
package org.schabi.newpipe.extractor.services.bandcamp;
44

55
import static org.junit.jupiter.api.Assertions.assertEquals;
6-
import static org.junit.jupiter.api.Assertions.assertTrue;
76
import static org.schabi.newpipe.extractor.ServiceList.Bandcamp;
87

98
import org.junit.jupiter.api.BeforeAll;
@@ -50,8 +49,7 @@ void testStreamSearch() throws ExtractionException, IOException {
5049
// The track by Zach Benson should be the first result, no?
5150
assertEquals("Best Friend's Basement", bestFriendsBasement.getName());
5251
assertEquals("Zach Benson", bestFriendsBasement.getUploaderName());
53-
assertTrue(bestFriendsBasement.getThumbnailUrl().endsWith(".jpg"));
54-
assertTrue(bestFriendsBasement.getThumbnailUrl().contains("f4.bcbits.com/img/"));
52+
BandcampTestUtils.testImages(bestFriendsBasement.getThumbnails());
5553
assertEquals(InfoItem.InfoType.STREAM, bestFriendsBasement.getInfoType());
5654
}
5755

@@ -66,10 +64,8 @@ void testChannelSearch() throws ExtractionException, IOException {
6664

6765
// C418's artist profile should be the first result, no?
6866
assertEquals("C418", c418.getName());
69-
assertTrue(c418.getThumbnailUrl().endsWith(".jpg"));
70-
assertTrue(c418.getThumbnailUrl().contains("f4.bcbits.com/img/"));
67+
BandcampTestUtils.testImages(c418.getThumbnails());
7168
assertEquals("https://c418.bandcamp.com", c418.getUrl());
72-
7369
}
7470

7571
/**
@@ -82,9 +78,9 @@ void testAlbumSearch() throws ExtractionException, IOException {
8278

8379
// Minecraft volume alpha should be the first result, no?
8480
assertEquals("Minecraft - Volume Alpha", minecraft.getName());
85-
assertTrue(minecraft.getThumbnailUrl().endsWith(".jpg"));
86-
assertTrue(minecraft.getThumbnailUrl().contains("f4.bcbits.com/img/"));
87-
assertEquals("https://c418.bandcamp.com/album/minecraft-volume-alpha",
81+
BandcampTestUtils.testImages(minecraft.getThumbnails());
82+
assertEquals(
83+
"https://c418.bandcamp.com/album/minecraft-volume-alpha",
8884
minecraft.getUrl());
8985

9086
// Verify that playlist tracks counts get extracted correctly

extractor/src/test/java/org/schabi/newpipe/extractor/services/bandcamp/BandcampStreamExtractorTest.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import java.util.List;
2121

2222
import static org.junit.jupiter.api.Assertions.assertEquals;
23-
import static org.junit.jupiter.api.Assertions.assertTrue;
2423
import static org.schabi.newpipe.extractor.ServiceList.Bandcamp;
2524

2625
/**
@@ -150,13 +149,12 @@ public String expectedCategory() {
150149
}
151150

152151
@Test
153-
public void testArtistProfilePicture() throws Exception {
154-
final String url = extractor().getUploaderAvatarUrl();
155-
assertTrue(url.contains("://f4.bcbits.com/img/") && url.endsWith(".jpg"));
152+
void testArtistProfilePictures() {
153+
BandcampTestUtils.testImages(extractor.getUploaderAvatars());
156154
}
157155

158156
@Test
159-
public void testTranslateIdsToUrl() throws ParsingException {
157+
void testTranslateIdsToUrl() throws ParsingException {
160158
// To add tests: look at website's source, search for `band_id` and `item_id`
161159
assertEquals(
162160
"https://teaganbear.bandcamp.com/track/just-for-the-halibut-creative-commons-attribution",

0 commit comments

Comments
 (0)