Skip to content

Commit 2c436d4

Browse files
committed
[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).
1 parent d381f3b commit 2c436d4

1 file changed

Lines changed: 22 additions & 1 deletion

File tree

extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeTestsUtils.java

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
package org.schabi.newpipe.extractor.services.youtube;
22

3+
import org.schabi.newpipe.extractor.ExtractorAsserts;
4+
import org.schabi.newpipe.extractor.Image;
5+
import org.schabi.newpipe.extractor.services.DefaultTests;
36
import org.schabi.newpipe.extractor.services.youtube.extractors.YoutubeStreamExtractor;
47

8+
import javax.annotation.Nullable;
9+
import java.util.Collection;
510
import java.util.Random;
611

712
/**
8-
* Utility class for keeping YouTube tests stateless.
13+
* Utility class for YouTube tests.
914
*/
1015
public final class YoutubeTestsUtils {
1116
private YoutubeTestsUtils() {
@@ -26,4 +31,20 @@ public static void ensureStateless() {
2631
YoutubeParsingHelper.setNumberGenerator(new Random(1));
2732
YoutubeStreamExtractor.resetDeobfuscationCode();
2833
}
34+
35+
/**
36+
* Test that YouTube images of a {@link Collection} respect
37+
* {@link DefaultTests#defaultTestImageCollection(Collection) default requirements} and contain
38+
* the string {@code yt} in their URL.
39+
*
40+
* @param images a YouTube {@link Image} {@link Collection}
41+
*/
42+
public static void testImages(@Nullable final Collection<Image> images) {
43+
DefaultTests.defaultTestImageCollection(images);
44+
// Disable NPE warning because if the collection is null, an AssertionError would be thrown
45+
// by DefaultTests.defaultTestImageCollection
46+
//noinspection DataFlowIssue
47+
images.forEach(image ->
48+
ExtractorAsserts.assertContains("yt", image.getUrl()));
49+
}
2950
}

0 commit comments

Comments
 (0)