From 2c436d428cf7e27d9df68f46002935f6408a8171 Mon Sep 17 00:00:00 2001 From: AudricV <74829229+AudricV@users.noreply.github.com> Date: Wed, 3 Aug 2022 16:06:21 +0200 Subject: [PATCH] [YouTube] Add utility test method to test images in YoutubeTestsUtils This method, testImages(Collection), will use first the default image collection test in DefaultTests and then will check that each image URL contains the string yt. The JavaDoc of the class has been also updated to reflect the changes made in it (it is now more general). --- .../services/youtube/YoutubeTestsUtils.java | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) 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())); + } }