diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeTestsUtils.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeTestsUtils.java index a98039873..fec933c00 100644 --- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeTestsUtils.java +++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeTestsUtils.java @@ -1,11 +1,16 @@ package org.schabi.newpipe.extractor.services.youtube; +import org.schabi.newpipe.extractor.ExtractorAsserts; +import org.schabi.newpipe.extractor.Image; +import org.schabi.newpipe.extractor.services.DefaultTests; import org.schabi.newpipe.extractor.services.youtube.extractors.YoutubeStreamExtractor; +import javax.annotation.Nullable; +import java.util.Collection; import java.util.Random; /** - * Utility class for keeping YouTube tests stateless. + * Utility class for YouTube tests. */ public final class YoutubeTestsUtils { private YoutubeTestsUtils() { @@ -26,4 +31,20 @@ public final class YoutubeTestsUtils { YoutubeParsingHelper.setNumberGenerator(new Random(1)); YoutubeStreamExtractor.resetDeobfuscationCode(); } + + /** + * Test that YouTube images of a {@link Collection} respect + * {@link DefaultTests#defaultTestImageCollection(Collection) default requirements} and contain + * the string {@code yt} in their URL. + * + * @param images a YouTube {@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 + images.forEach(image -> + ExtractorAsserts.assertContains("yt", image.getUrl())); + } }