From 2578f220540b04ed68ef1f971f7bf75d5e48e8c4 Mon Sep 17 00:00:00 2001 From: AudricV <74829229+AudricV@users.noreply.github.com> Date: Wed, 3 Aug 2022 17:47:58 +0200 Subject: [PATCH] [Bandcamp] Add utility test method to test images This method, testImages(Collection), 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. --- .../services/bandcamp/BandcampTestUtils.java | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 extractor/src/test/java/org/schabi/newpipe/extractor/services/bandcamp/BandcampTestUtils.java diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/bandcamp/BandcampTestUtils.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/bandcamp/BandcampTestUtils.java new file mode 100644 index 000000000..bc17fc515 --- /dev/null +++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/bandcamp/BandcampTestUtils.java @@ -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 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")))); + } +}