[YouTube] Add utility test method to test images in YoutubeTestsUtils

This method, testImages(Collection<Image>), 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).
This commit is contained in:
AudricV 2022-08-03 16:06:21 +02:00
parent d381f3b70b
commit 2c436d428c
No known key found for this signature in database
GPG Key ID: DA92EC7905614198
1 changed files with 22 additions and 1 deletions

View File

@ -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<Image> 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()));
}
}