[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.
This commit is contained in:
AudricV 2022-08-03 17:47:58 +02:00
parent ba5315c72d
commit 2578f22054
No known key found for this signature in database
GPG Key ID: DA92EC7905614198
1 changed files with 34 additions and 0 deletions

View File

@ -0,0 +1,34 @@
package org.schabi.newpipe.extractor.services.bandcamp;
import org.schabi.newpipe.extractor.Image;
import org.schabi.newpipe.extractor.services.DefaultTests;
import javax.annotation.Nullable;
import java.util.Collection;
import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* Utility class for Bandcamp tests.
*/
public final class BandcampTestUtils {
private BandcampTestUtils() {
}
/**
* Test that Bandcamp images of a {@link Collection} respect
* {@link DefaultTests#defaultTestImageCollection(Collection) default requirements}, contain
* the string {@code f4.bcbits.com/img} in their URL and end with {@code .jpg} or {@code .png}.
*
* @param images a Bandcamp {@link Image} {@link Collection}
*/
public static void testImages(@Nullable final Collection<Image> images) {
DefaultTests.defaultTestImageCollection(images);
// Disable NPE warning because if the collection is null, an AssertionError would be thrown
// by DefaultTests.defaultTestImageCollection
//noinspection DataFlowIssue
assertTrue(images.stream()
.allMatch(image -> image.getUrl().contains("f4.bcbits.com/img")
&& (image.getUrl().endsWith(".jpg") || image.getUrl().endsWith(".png"))));
}
}