Skip to content

Commit 2578f22

Browse files
committed
[Bandcamp] Add utility test method to test images
This method, testImages(Collection<Image>), will use first the default image collection test in DefaultTests and then will check that each image URL contains f4.bcbits.com/img and ends with .jpg or .png. To do so, a new non-instantiable final class has been added: BandcampTestUtils.
1 parent ba5315c commit 2578f22

1 file changed

Lines changed: 34 additions & 0 deletions

File tree

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package org.schabi.newpipe.extractor.services.bandcamp;
2+
3+
import org.schabi.newpipe.extractor.Image;
4+
import org.schabi.newpipe.extractor.services.DefaultTests;
5+
6+
import javax.annotation.Nullable;
7+
import java.util.Collection;
8+
9+
import static org.junit.jupiter.api.Assertions.assertTrue;
10+
11+
/**
12+
* Utility class for Bandcamp tests.
13+
*/
14+
public final class BandcampTestUtils {
15+
private BandcampTestUtils() {
16+
}
17+
18+
/**
19+
* Test that Bandcamp images of a {@link Collection} respect
20+
* {@link DefaultTests#defaultTestImageCollection(Collection) default requirements}, contain
21+
* the string {@code f4.bcbits.com/img} in their URL and end with {@code .jpg} or {@code .png}.
22+
*
23+
* @param images a Bandcamp {@link Image} {@link Collection}
24+
*/
25+
public static void testImages(@Nullable final Collection<Image> images) {
26+
DefaultTests.defaultTestImageCollection(images);
27+
// Disable NPE warning because if the collection is null, an AssertionError would be thrown
28+
// by DefaultTests.defaultTestImageCollection
29+
//noinspection DataFlowIssue
30+
assertTrue(images.stream()
31+
.allMatch(image -> image.getUrl().contains("f4.bcbits.com/img")
32+
&& (image.getUrl().endsWith(".jpg") || image.getUrl().endsWith(".png"))));
33+
}
34+
}

0 commit comments

Comments
 (0)