From 349ba8db7f13423c62ee660b7e30a933bb8b2204 Mon Sep 17 00:00:00 2001 From: litetex <40789489+litetex@users.noreply.github.com> Date: Mon, 7 Feb 2022 21:23:38 +0100 Subject: [PATCH] Improve tests and randomness - Use the existing RNG inside YoutubeParsingHelper - Deduplicated test-setup for YouTube tests - Minor improvements --- .../youtube/YoutubeParsingHelper.java | 94 ++++++++----------- .../RandomStringFromAlphabetGenerator.java | 35 +++++++ .../schabi/newpipe/extractor/utils/Utils.java | 48 +--------- .../youtube/YoutubeChannelExtractorTest.java | 40 ++++---- .../YoutubeChannelLocalizationTest.java | 12 +-- .../youtube/YoutubeCommentsExtractorTest.java | 34 +++---- .../youtube/YoutubeFeedExtractorTest.java | 18 ++-- .../youtube/YoutubeKioskExtractorTest.java | 15 ++- .../YoutubeMixPlaylistExtractorTest.java | 21 ++--- .../youtube/YoutubeParsingHelperTest.java | 10 +- .../youtube/YoutubePlaylistExtractorTest.java | 42 ++++----- .../YoutubeSuggestionExtractorTest.java | 10 +- .../services/youtube/YoutubeTestsUtils.java | 28 ++++++ .../youtube/YoutubeTrendingKioskInfoTest.java | 13 +-- .../search/YoutubeSearchExtractorTest.java | 39 +++----- ...utubeStreamExtractorAgeRestrictedTest.java | 13 +-- ...utubeStreamExtractorControversialTest.java | 13 +-- .../YoutubeStreamExtractorDefaultTest.java | 74 +++++---------- .../YoutubeStreamExtractorLivestreamTest.java | 13 +-- .../YoutubeStreamExtractorRelatedMixTest.java | 6 +- .../YoutubeStreamExtractorUnlistedTest.java | 15 +-- 21 files changed, 251 insertions(+), 342 deletions(-) create mode 100644 extractor/src/main/java/org/schabi/newpipe/extractor/utils/RandomStringFromAlphabetGenerator.java create mode 100644 extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeTestsUtils.java diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeParsingHelper.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeParsingHelper.java index 8a99fef0..a36c511d 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeParsingHelper.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeParsingHelper.java @@ -1,3 +1,23 @@ +/* + * Created by Christian Schabesberger on 02.03.16. + * + * Copyright (C) Christian Schabesberger 2016 + * YoutubeParsingHelper.java is part of NewPipe Extractor. + * + * NewPipe Extractor is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * NewPipe Extractor is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with NewPipe Extractor. If not, see . + */ + package org.schabi.newpipe.extractor.services.youtube; import static org.schabi.newpipe.extractor.NewPipe.getDownloader; @@ -7,7 +27,6 @@ import static org.schabi.newpipe.extractor.utils.Utils.HTTPS; import static org.schabi.newpipe.extractor.utils.Utils.UTF_8; import static org.schabi.newpipe.extractor.utils.Utils.getStringResultFromRegexArray; import static org.schabi.newpipe.extractor.utils.Utils.isNullOrEmpty; -import static org.schabi.newpipe.extractor.utils.Utils.randomStringFromAlphabet; import com.grack.nanojson.JsonArray; import com.grack.nanojson.JsonBuilder; @@ -29,6 +48,7 @@ import org.schabi.newpipe.extractor.playlist.PlaylistInfo; import org.schabi.newpipe.extractor.stream.Description; import org.schabi.newpipe.extractor.utils.JsonUtils; import org.schabi.newpipe.extractor.utils.Parser; +import org.schabi.newpipe.extractor.utils.RandomStringFromAlphabetGenerator; import org.schabi.newpipe.extractor.utils.Utils; import java.io.IOException; @@ -37,6 +57,7 @@ import java.net.MalformedURLException; import java.net.URL; import java.net.URLDecoder; import java.nio.charset.StandardCharsets; +import java.security.SecureRandom; import java.time.LocalDate; import java.time.OffsetDateTime; import java.time.ZoneOffset; @@ -54,26 +75,6 @@ import java.util.Random; import javax.annotation.Nonnull; import javax.annotation.Nullable; -/* - * Created by Christian Schabesberger on 02.03.16. - * - * Copyright (C) Christian Schabesberger 2016 - * YoutubeParsingHelper.java is part of NewPipe Extractor. - * - * NewPipe Extractor is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * NewPipe Extractor is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with NewPipe Extractor. If not, see . - */ - public final class YoutubeParsingHelper { private YoutubeParsingHelper() { @@ -83,11 +84,6 @@ public final class YoutubeParsingHelper { public static final String CPN = "cpn"; public static final String VIDEO_ID = "videoId"; - /** - * Seed that will be used for video tests, in order to mock video requests. - */ - private static final long SEED_FOR_VIDEOS_TESTS = 3000; - private static final String HARDCODED_CLIENT_VERSION = "2.20220114.01.00"; private static final String HARDCODED_KEY = "AIzaSyAO_FJ2SlqU8Q4STEHLGCilw_Y9_11qcW8"; @@ -122,7 +118,7 @@ public final class YoutubeParsingHelper { private static final String CONTENT_PLAYBACK_NONCE_ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"; - private static Random numberGenerator = new Random(); + private static Random numberGenerator = new SecureRandom(); /** * {@code PENDING+} means that the user did not yet submit their choices. @@ -606,12 +602,13 @@ public final class YoutubeParsingHelper { if (keyAndVersionExtracted) { return clientVersion; - } else { - if (areHardcodedClientVersionAndKeyValid()) { - clientVersion = HARDCODED_CLIENT_VERSION; - return clientVersion; - } } + + if (areHardcodedClientVersionAndKeyValid()) { + clientVersion = HARDCODED_CLIENT_VERSION; + return clientVersion; + } + throw new ExtractionException("Could not get YouTube WEB client version"); } @@ -631,11 +628,11 @@ public final class YoutubeParsingHelper { if (keyAndVersionExtracted) { return key; - } else { - if (areHardcodedClientVersionAndKeyValid()) { - key = HARDCODED_KEY; - return key; - } + } + + if (areHardcodedClientVersionAndKeyValid()) { + key = HARDCODED_KEY; + return key; } // The ANDROID API key is also valid with the WEB client so return it if we couldn't @@ -1508,7 +1505,8 @@ public final class YoutubeParsingHelper { */ @Nonnull public static String generateContentPlaybackNonce() { - return randomStringFromAlphabet(CONTENT_PLAYBACK_NONCE_ALPHABET, 16); + return RandomStringFromAlphabetGenerator.generate( + CONTENT_PLAYBACK_NONCE_ALPHABET, 16, numberGenerator); } /** @@ -1524,23 +1522,7 @@ public final class YoutubeParsingHelper { */ @Nonnull public static String generateTParameter() { - return randomStringFromAlphabet(CONTENT_PLAYBACK_NONCE_ALPHABET, 12); - } - - /** - * Set the seed for video tests. - * - *

- * This seed will be used to generate the same {@code t} and {@code cpn} values between - * different execution of tests so mocks can be used for stream tests. - *

- * - *

- * This method will call {@link Utils#setSecureRandomSeed(long)} with the - * {@link #SEED_FOR_VIDEOS_TESTS value}. - *

- */ - public static void setSeedForVideoTests() { - Utils.setSecureRandomSeed(SEED_FOR_VIDEOS_TESTS); + return RandomStringFromAlphabetGenerator.generate( + CONTENT_PLAYBACK_NONCE_ALPHABET, 12, numberGenerator); } } diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/utils/RandomStringFromAlphabetGenerator.java b/extractor/src/main/java/org/schabi/newpipe/extractor/utils/RandomStringFromAlphabetGenerator.java new file mode 100644 index 00000000..ab1eec8d --- /dev/null +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/utils/RandomStringFromAlphabetGenerator.java @@ -0,0 +1,35 @@ +package org.schabi.newpipe.extractor.utils; + +import java.util.Random; + +import javax.annotation.Nonnull; + +/** + * Generates a random string from a predefined alphabet. + */ +public final class RandomStringFromAlphabetGenerator { + private RandomStringFromAlphabetGenerator() { + // No impl + } + + /** + * Generate a random string from an alphabet. + * + * @param alphabet the characters' alphabet to use + * @param length the length of the returned string (> 0) + * @param random {@link Random} (or better {@link java.security.SecureRandom}) used for generating the random string + * @return a random string of the requested length made of only characters from the provided + * alphabet + */ + @Nonnull + public static String generate( + final String alphabet, + final int length, + final Random random) { + final StringBuilder stringBuilder = new StringBuilder(length); + for (int i = 0; i < length; i++) { + stringBuilder.append(alphabet.charAt(random.nextInt(alphabet.length()))); + } + return stringBuilder.toString(); + } +} diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/utils/Utils.java b/extractor/src/main/java/org/schabi/newpipe/extractor/utils/Utils.java index 88ec9333..1cec52c5 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/utils/Utils.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/utils/Utils.java @@ -8,14 +8,13 @@ import java.io.UnsupportedEncodingException; import java.net.MalformedURLException; import java.net.URL; import java.net.URLDecoder; +import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.Iterator; import java.util.LinkedList; -import java.util.ArrayList; import java.util.List; import java.util.Map; -import java.security.SecureRandom; import java.util.regex.Pattern; public final class Utils { @@ -26,7 +25,6 @@ public final class Utils { public static final String EMPTY_STRING = ""; private static final Pattern M_PATTERN = Pattern.compile("(https?)?:\\/\\/m\\."); private static final Pattern WWW_PATTERN = Pattern.compile("(https?)?:\\/\\/www\\."); - private static final SecureRandom random = new SecureRandom(); private Utils() { // no instance @@ -75,8 +73,9 @@ public final class Utils { multiplier = Parser.matchGroup("[\\d]+([\\.,][\\d]+)?([KMBkmb])+", numberWord, 2); } catch (final ParsingException ignored) { } - final double count = Double.parseDouble( - Parser.matchGroup1("([\\d]+([\\.,][\\d]+)?)", numberWord).replace(",", ".")); + + final double count = Double.parseDouble(Parser.matchGroup1("([\\d]+([\\.,][\\d]+)?)", + numberWord).replace(",", ".")); switch (multiplier.toUpperCase()) { case "K": return (long) (count * 1e3); @@ -443,43 +442,4 @@ public final class Utils { } return result; } - - /** - * Generate a random string using the secure random device {@link #random}. - * - *

- * {@link #setSecureRandomSeed(long)} might be useful when mocking tests. - *

- * - * @param alphabet the characters' alphabet to use - * @param length the length of the returned string - * @return a random string of the requested length made of only characters from the provided - * alphabet - */ - @Nonnull - public static String randomStringFromAlphabet(final String alphabet, final int length) { - final StringBuilder stringBuilder = new StringBuilder(); - for (int i = 0; i < length; ++i) { - stringBuilder.append(alphabet.charAt(random.nextInt(alphabet.length()))); - } - return stringBuilder.toString(); - } - - /** - * Seed the secure random device used for {@link #randomStringFromAlphabet(String, int)}. - * - *

- * Use this in tests so that they can be mocked as the same random numbers are always - * generated. - *

- * - *

- * This is not intended to be used outside of tests. - *

- * - * @param seed the seed to pass to {@link SecureRandom#setSeed(long)} - */ - public static void setSecureRandomSeed(final long seed) { - random.setSeed(seed); - } } diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeChannelExtractorTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeChannelExtractorTest.java index 6b2c489d..aee006f5 100644 --- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeChannelExtractorTest.java +++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeChannelExtractorTest.java @@ -1,5 +1,17 @@ package org.schabi.newpipe.extractor.services.youtube; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; +import static org.schabi.newpipe.extractor.ExtractorAsserts.assertContains; +import static org.schabi.newpipe.extractor.ExtractorAsserts.assertIsSecureUrl; +import static org.schabi.newpipe.extractor.ServiceList.YouTube; +import static org.schabi.newpipe.extractor.services.DefaultTests.defaultTestGetPageInNewExtractor; +import static org.schabi.newpipe.extractor.services.DefaultTests.defaultTestMoreItems; +import static org.schabi.newpipe.extractor.services.DefaultTests.defaultTestRelatedItems; + import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; import org.schabi.newpipe.downloader.DownloaderFactory; @@ -15,13 +27,6 @@ import org.schabi.newpipe.extractor.services.BaseChannelExtractorTest; import org.schabi.newpipe.extractor.services.youtube.extractors.YoutubeChannelExtractor; import java.io.IOException; -import java.util.Random; - -import static org.junit.jupiter.api.Assertions.*; -import static org.schabi.newpipe.extractor.ExtractorAsserts.assertContains; -import static org.schabi.newpipe.extractor.ExtractorAsserts.assertIsSecureUrl; -import static org.schabi.newpipe.extractor.ServiceList.YouTube; -import static org.schabi.newpipe.extractor.services.DefaultTests.*; /** * Test for {@link ChannelExtractor} @@ -33,8 +38,7 @@ public class YoutubeChannelExtractorTest { public static class NotAvailable { @BeforeAll public static void setUp() throws IOException { - YoutubeParsingHelper.resetClientVersionAndKey(); - YoutubeParsingHelper.setNumberGenerator(new Random(1)); + YoutubeTestsUtils.ensureStateless(); NewPipe.init(DownloaderFactory.getDownloader(RESOURCE_PATH + "notAvailable")); } @@ -130,8 +134,7 @@ public class YoutubeChannelExtractorTest { public static class NotSupported { @BeforeAll public static void setUp() throws IOException { - YoutubeParsingHelper.resetClientVersionAndKey(); - YoutubeParsingHelper.setNumberGenerator(new Random(1)); + YoutubeTestsUtils.ensureStateless(); NewPipe.init(DownloaderFactory.getDownloader(RESOURCE_PATH + "notSupported")); } @@ -149,8 +152,7 @@ public class YoutubeChannelExtractorTest { @BeforeAll public static void setUp() throws Exception { - YoutubeParsingHelper.resetClientVersionAndKey(); - YoutubeParsingHelper.setNumberGenerator(new Random(1)); + YoutubeTestsUtils.ensureStateless(); NewPipe.init(DownloaderFactory.getDownloader(RESOURCE_PATH + "gronkh")); extractor = (YoutubeChannelExtractor) YouTube .getChannelExtractor("http://www.youtube.com/user/Gronkh"); @@ -246,8 +248,7 @@ public class YoutubeChannelExtractorTest { @BeforeAll public static void setUp() throws Exception { - YoutubeParsingHelper.resetClientVersionAndKey(); - YoutubeParsingHelper.setNumberGenerator(new Random(1)); + YoutubeTestsUtils.ensureStateless(); NewPipe.init(DownloaderFactory.getDownloader(RESOURCE_PATH + "VSauce")); extractor = (YoutubeChannelExtractor) YouTube .getChannelExtractor("https://www.youtube.com/user/Vsauce"); @@ -342,8 +343,7 @@ public class YoutubeChannelExtractorTest { @BeforeAll public static void setUp() throws Exception { - YoutubeParsingHelper.resetClientVersionAndKey(); - YoutubeParsingHelper.setNumberGenerator(new Random(1)); + YoutubeTestsUtils.ensureStateless(); NewPipe.init(DownloaderFactory.getDownloader(RESOURCE_PATH + "kurzgesagt")); extractor = (YoutubeChannelExtractor) YouTube .getChannelExtractor("https://www.youtube.com/channel/UCsXVk37bltHxD1rDPwtNM8Q"); @@ -460,8 +460,7 @@ public class YoutubeChannelExtractorTest { @BeforeAll public static void setUp() throws Exception { - YoutubeParsingHelper.resetClientVersionAndKey(); - YoutubeParsingHelper.setNumberGenerator(new Random(1)); + YoutubeTestsUtils.ensureStateless(); NewPipe.init(DownloaderFactory.getDownloader(RESOURCE_PATH + "captainDisillusion")); extractor = (YoutubeChannelExtractor) YouTube .getChannelExtractor("https://www.youtube.com/user/CaptainDisillusion/videos"); @@ -555,8 +554,7 @@ public class YoutubeChannelExtractorTest { @BeforeAll public static void setUp() throws Exception { - YoutubeParsingHelper.resetClientVersionAndKey(); - YoutubeParsingHelper.setNumberGenerator(new Random(1)); + YoutubeTestsUtils.ensureStateless(); NewPipe.init(DownloaderFactory.getDownloader(RESOURCE_PATH + "random")); extractor = (YoutubeChannelExtractor) YouTube .getChannelExtractor("https://www.youtube.com/channel/UCUaQMQS9lY5lit3vurpXQ6w"); diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeChannelLocalizationTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeChannelLocalizationTest.java index 5cf41a76..533ad7ee 100644 --- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeChannelLocalizationTest.java +++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeChannelLocalizationTest.java @@ -1,5 +1,9 @@ package org.schabi.newpipe.extractor.services.youtube; +import static org.junit.jupiter.api.Assertions.fail; +import static org.schabi.newpipe.extractor.ServiceList.YouTube; +import static org.schabi.newpipe.extractor.services.DefaultTests.defaultTestRelatedItems; + import org.junit.jupiter.api.Test; import org.schabi.newpipe.downloader.DownloaderFactory; import org.schabi.newpipe.extractor.ListExtractor; @@ -14,11 +18,6 @@ import java.time.temporal.ChronoUnit; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; -import java.util.Random; - -import static org.junit.jupiter.api.Assertions.fail; -import static org.schabi.newpipe.extractor.ServiceList.YouTube; -import static org.schabi.newpipe.extractor.services.DefaultTests.defaultTestRelatedItems; /** * A class that tests multiple channels and ranges of "time ago". @@ -30,8 +29,7 @@ public class YoutubeChannelLocalizationTest { @Test public void testAllSupportedLocalizations() throws Exception { - YoutubeParsingHelper.resetClientVersionAndKey(); - YoutubeParsingHelper.setNumberGenerator(new Random(1)); + YoutubeTestsUtils.ensureStateless(); NewPipe.init(DownloaderFactory.getDownloader(RESOURCE_PATH + "localization")); testLocalizationsFor("https://www.youtube.com/user/NBCNews"); diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeCommentsExtractorTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeCommentsExtractorTest.java index 2c5119d5..b0bb6447 100644 --- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeCommentsExtractorTest.java +++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeCommentsExtractorTest.java @@ -1,5 +1,11 @@ package org.schabi.newpipe.extractor.services.youtube; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.schabi.newpipe.extractor.ServiceList.YouTube; + import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; import org.schabi.newpipe.downloader.DownloaderFactory; @@ -17,13 +23,6 @@ import org.schabi.newpipe.extractor.utils.Utils; import java.io.IOException; import java.util.List; import java.util.Locale; -import java.util.Random; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.schabi.newpipe.extractor.ServiceList.YouTube; public class YoutubeCommentsExtractorTest { private static final String RESOURCE_PATH = DownloaderFactory.RESOURCE_PATH + "services/youtube/extractor/comments/"; @@ -38,8 +37,7 @@ public class YoutubeCommentsExtractorTest { @BeforeAll public static void setUp() throws Exception { - YoutubeParsingHelper.resetClientVersionAndKey(); - YoutubeParsingHelper.setNumberGenerator(new Random(1)); + YoutubeTestsUtils.ensureStateless(); NewPipe.init(DownloaderFactory.getDownloader(RESOURCE_PATH + "thomas")); extractor = (YoutubeCommentsExtractor) YouTube .getCommentsExtractor(url); @@ -127,8 +125,7 @@ public class YoutubeCommentsExtractorTest { @BeforeAll public static void setUp() throws Exception { - YoutubeParsingHelper.resetClientVersionAndKey(); - YoutubeParsingHelper.setNumberGenerator(new Random(1)); + YoutubeTestsUtils.ensureStateless(); NewPipe.init(DownloaderFactory.getDownloader(RESOURCE_PATH + "empty")); extractor = (YoutubeCommentsExtractor) YouTube .getCommentsExtractor(url); @@ -167,8 +164,7 @@ public class YoutubeCommentsExtractorTest { @BeforeAll public static void setUp() throws Exception { - YoutubeParsingHelper.resetClientVersionAndKey(); - YoutubeParsingHelper.setNumberGenerator(new Random(1)); + YoutubeTestsUtils.ensureStateless(); NewPipe.init(DownloaderFactory.getDownloader(RESOURCE_PATH + "hearted")); extractor = (YoutubeCommentsExtractor) YouTube .getCommentsExtractor(url); @@ -210,8 +206,7 @@ public class YoutubeCommentsExtractorTest { @BeforeAll public static void setUp() throws Exception { - YoutubeParsingHelper.resetClientVersionAndKey(); - YoutubeParsingHelper.setNumberGenerator(new Random(1)); + YoutubeTestsUtils.ensureStateless(); NewPipe.init(DownloaderFactory.getDownloader(RESOURCE_PATH + "pinned")); extractor = (YoutubeCommentsExtractor) YouTube .getCommentsExtractor(url); @@ -252,8 +247,7 @@ public class YoutubeCommentsExtractorTest { @BeforeAll public static void setUp() throws Exception { - YoutubeParsingHelper.resetClientVersionAndKey(); - YoutubeParsingHelper.setNumberGenerator(new Random(1)); + YoutubeTestsUtils.ensureStateless(); NewPipe.init(DownloaderFactory.getDownloader(RESOURCE_PATH + "likes")); extractor = (YoutubeCommentsExtractor) YouTube .getCommentsExtractor(url); @@ -284,8 +278,7 @@ public class YoutubeCommentsExtractorTest { @BeforeAll public static void setUp() throws Exception { - YoutubeParsingHelper.resetClientVersionAndKey(); - YoutubeParsingHelper.setNumberGenerator(new Random(1)); + YoutubeTestsUtils.ensureStateless(); NewPipe.init(DownloaderFactory.getDownloader(RESOURCE_PATH + "localized_vote_count")); extractor = (YoutubeCommentsExtractor) YouTube .getCommentsExtractor(url); @@ -313,8 +306,7 @@ public class YoutubeCommentsExtractorTest { @BeforeAll public static void setUp() throws Exception { - YoutubeParsingHelper.resetClientVersionAndKey(); - YoutubeParsingHelper.setNumberGenerator(new Random(1)); + YoutubeTestsUtils.ensureStateless(); NewPipe.init(DownloaderFactory.getDownloader(RESOURCE_PATH + "replies")); extractor = (YoutubeCommentsExtractor) YouTube .getCommentsExtractor(url); diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeFeedExtractorTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeFeedExtractorTest.java index ef160564..4169b0cd 100644 --- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeFeedExtractorTest.java +++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeFeedExtractorTest.java @@ -1,5 +1,12 @@ package org.schabi.newpipe.extractor.services.youtube; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.schabi.newpipe.extractor.ServiceList.YouTube; +import static org.schabi.newpipe.extractor.services.DefaultTests.assertNoMoreItems; +import static org.schabi.newpipe.extractor.services.DefaultTests.defaultTestRelatedItems; + import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; import org.schabi.newpipe.downloader.DownloaderFactory; @@ -10,14 +17,6 @@ import org.schabi.newpipe.extractor.services.BaseListExtractorTest; import org.schabi.newpipe.extractor.services.youtube.extractors.YoutubeFeedExtractor; import java.io.IOException; -import java.util.Random; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.schabi.newpipe.extractor.ServiceList.YouTube; -import static org.schabi.newpipe.extractor.services.DefaultTests.assertNoMoreItems; -import static org.schabi.newpipe.extractor.services.DefaultTests.defaultTestRelatedItems; public class YoutubeFeedExtractorTest { @@ -28,8 +27,7 @@ public class YoutubeFeedExtractorTest { @BeforeAll public static void setUp() throws Exception { - YoutubeParsingHelper.resetClientVersionAndKey(); - YoutubeParsingHelper.setNumberGenerator(new Random(1)); + YoutubeTestsUtils.ensureStateless(); NewPipe.init(DownloaderFactory.getDownloader(RESOURCE_PATH)); extractor = (YoutubeFeedExtractor) YouTube .getFeedExtractor("https://www.youtube.com/user/Kurzgesagt"); diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeKioskExtractorTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeKioskExtractorTest.java index 23db8a58..1b4c0368 100644 --- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeKioskExtractorTest.java +++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeKioskExtractorTest.java @@ -1,5 +1,10 @@ package org.schabi.newpipe.extractor.services.youtube; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.schabi.newpipe.extractor.ServiceList.YouTube; +import static org.schabi.newpipe.extractor.services.DefaultTests.assertNoMoreItems; +import static org.schabi.newpipe.extractor.services.DefaultTests.defaultTestRelatedItems; + import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; import org.schabi.newpipe.downloader.DownloaderFactory; @@ -8,13 +13,6 @@ import org.schabi.newpipe.extractor.exceptions.ParsingException; import org.schabi.newpipe.extractor.services.BaseListExtractorTest; import org.schabi.newpipe.extractor.services.youtube.extractors.YoutubeTrendingExtractor; -import java.util.Random; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.schabi.newpipe.extractor.ServiceList.YouTube; -import static org.schabi.newpipe.extractor.services.DefaultTests.assertNoMoreItems; -import static org.schabi.newpipe.extractor.services.DefaultTests.defaultTestRelatedItems; - public class YoutubeKioskExtractorTest { private static final String RESOURCE_PATH = DownloaderFactory.RESOURCE_PATH + "services/youtube/extractor/kiosk/"; @@ -24,8 +22,7 @@ public class YoutubeKioskExtractorTest { @BeforeAll public static void setUp() throws Exception { - YoutubeParsingHelper.resetClientVersionAndKey(); - YoutubeParsingHelper.setNumberGenerator(new Random(1)); + YoutubeTestsUtils.ensureStateless(); NewPipe.init(DownloaderFactory.getDownloader(RESOURCE_PATH + "trending")); extractor = (YoutubeTrendingExtractor) YouTube.getKioskList().getDefaultKioskExtractor(); extractor.fetchPage(); diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeMixPlaylistExtractorTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeMixPlaylistExtractorTest.java index 08734bfb..27d7d98e 100644 --- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeMixPlaylistExtractorTest.java +++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeMixPlaylistExtractorTest.java @@ -31,7 +31,6 @@ import java.nio.charset.StandardCharsets; import java.util.HashMap; import java.util.HashSet; import java.util.Map; -import java.util.Random; import java.util.Set; public class YoutubeMixPlaylistExtractorTest { @@ -47,8 +46,7 @@ public class YoutubeMixPlaylistExtractorTest { @BeforeAll public static void setUp() throws Exception { - YoutubeParsingHelper.resetClientVersionAndKey(); - YoutubeParsingHelper.setNumberGenerator(new Random(1)); + YoutubeTestsUtils.ensureStateless(); NewPipe.init(DownloaderFactory.getDownloader(RESOURCE_PATH + "mix")); dummyCookie.put(YoutubeMixPlaylistExtractor.COOKIE_NAME, "whatever"); extractor = (YoutubeMixPlaylistExtractor) YouTube @@ -142,8 +140,7 @@ public class YoutubeMixPlaylistExtractorTest { @BeforeAll public static void setUp() throws Exception { - YoutubeParsingHelper.resetClientVersionAndKey(); - YoutubeParsingHelper.setNumberGenerator(new Random(1)); + YoutubeTestsUtils.ensureStateless(); NewPipe.init(DownloaderFactory.getDownloader(RESOURCE_PATH + "mixWithIndex")); dummyCookie.put(YoutubeMixPlaylistExtractor.COOKIE_NAME, "whatever"); extractor = (YoutubeMixPlaylistExtractor) YouTube @@ -228,8 +225,7 @@ public class YoutubeMixPlaylistExtractorTest { @BeforeAll public static void setUp() throws Exception { - YoutubeParsingHelper.resetClientVersionAndKey(); - YoutubeParsingHelper.setNumberGenerator(new Random(1)); + YoutubeTestsUtils.ensureStateless(); NewPipe.init(DownloaderFactory.getDownloader(RESOURCE_PATH + "myMix")); dummyCookie.put(YoutubeMixPlaylistExtractor.COOKIE_NAME, "whatever"); extractor = (YoutubeMixPlaylistExtractor) YouTube @@ -318,8 +314,7 @@ public class YoutubeMixPlaylistExtractorTest { @BeforeAll public static void setUp() throws IOException { - YoutubeParsingHelper.resetClientVersionAndKey(); - YoutubeParsingHelper.setNumberGenerator(new Random(1)); + YoutubeTestsUtils.ensureStateless(); NewPipe.init(DownloaderFactory.getDownloader(RESOURCE_PATH + "invalid")); dummyCookie.put(YoutubeMixPlaylistExtractor.COOKIE_NAME, "whatever"); } @@ -353,8 +348,7 @@ public class YoutubeMixPlaylistExtractorTest { @BeforeAll public static void setUp() throws Exception { - YoutubeParsingHelper.resetClientVersionAndKey(); - YoutubeParsingHelper.setNumberGenerator(new Random(1)); + YoutubeTestsUtils.ensureStateless(); NewPipe.init(DownloaderFactory.getDownloader(RESOURCE_PATH + "channelMix")); dummyCookie.put(YoutubeMixPlaylistExtractor.COOKIE_NAME, "whatever"); extractor = (YoutubeMixPlaylistExtractor) YouTube @@ -417,9 +411,8 @@ public class YoutubeMixPlaylistExtractorTest { @BeforeAll public static void setUp() throws Exception { - YoutubeParsingHelper.resetClientVersionAndKey(); - YoutubeParsingHelper.setNumberGenerator(new Random(1)); - NewPipe.init(new DownloaderFactory().getDownloader(RESOURCE_PATH + "genreMix")); + YoutubeTestsUtils.ensureStateless(); + NewPipe.init(DownloaderFactory.getDownloader(RESOURCE_PATH + "genreMix")); dummyCookie.put(YoutubeMixPlaylistExtractor.COOKIE_NAME, "whatever"); extractor = (YoutubeMixPlaylistExtractor) YouTube .getPlaylistExtractor("https://www.youtube.com/watch?v=" + VIDEO_ID diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeParsingHelperTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeParsingHelperTest.java index 45643ec0..1fa89e94 100644 --- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeParsingHelperTest.java +++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeParsingHelperTest.java @@ -1,5 +1,8 @@ package org.schabi.newpipe.extractor.services.youtube; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; + import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; import org.schabi.newpipe.downloader.DownloaderFactory; @@ -8,10 +11,6 @@ import org.schabi.newpipe.extractor.exceptions.ExtractionException; import org.schabi.newpipe.extractor.exceptions.ParsingException; import java.io.IOException; -import java.util.Random; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; public class YoutubeParsingHelperTest { @@ -19,8 +18,7 @@ public class YoutubeParsingHelperTest { @BeforeAll public static void setUp() throws IOException { - YoutubeParsingHelper.resetClientVersionAndKey(); - YoutubeParsingHelper.setNumberGenerator(new Random(1)); + YoutubeTestsUtils.ensureStateless(); NewPipe.init(DownloaderFactory.getDownloader(RESOURCE_PATH + "youtubeParsingHelper")); } diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubePlaylistExtractorTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubePlaylistExtractorTest.java index 5a342b61..10a7a5ba 100644 --- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubePlaylistExtractorTest.java +++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubePlaylistExtractorTest.java @@ -1,5 +1,18 @@ package org.schabi.newpipe.extractor.services.youtube; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.schabi.newpipe.extractor.ExtractorAsserts.assertIsSecureUrl; +import static org.schabi.newpipe.extractor.ListExtractor.ITEM_COUNT_UNKNOWN; +import static org.schabi.newpipe.extractor.ServiceList.YouTube; +import static org.schabi.newpipe.extractor.services.DefaultTests.assertNoMoreItems; +import static org.schabi.newpipe.extractor.services.DefaultTests.defaultTestGetPageInNewExtractor; +import static org.schabi.newpipe.extractor.services.DefaultTests.defaultTestListOfItems; +import static org.schabi.newpipe.extractor.services.DefaultTests.defaultTestMoreItems; +import static org.schabi.newpipe.extractor.services.DefaultTests.defaultTestRelatedItems; + import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; @@ -16,20 +29,6 @@ import org.schabi.newpipe.extractor.services.youtube.extractors.YoutubePlaylistE import org.schabi.newpipe.extractor.stream.StreamInfoItem; import java.io.IOException; -import java.util.Random; - -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.schabi.newpipe.extractor.ExtractorAsserts.assertIsSecureUrl; -import static org.schabi.newpipe.extractor.ListExtractor.ITEM_COUNT_UNKNOWN; -import static org.schabi.newpipe.extractor.ServiceList.YouTube; -import static org.schabi.newpipe.extractor.services.DefaultTests.assertNoMoreItems; -import static org.schabi.newpipe.extractor.services.DefaultTests.defaultTestGetPageInNewExtractor; -import static org.schabi.newpipe.extractor.services.DefaultTests.defaultTestListOfItems; -import static org.schabi.newpipe.extractor.services.DefaultTests.defaultTestMoreItems; -import static org.schabi.newpipe.extractor.services.DefaultTests.defaultTestRelatedItems; /** * Test for {@link YoutubePlaylistExtractor} @@ -41,8 +40,7 @@ public class YoutubePlaylistExtractorTest { public static class NotAvailable { @BeforeAll public static void setUp() throws IOException { - YoutubeParsingHelper.resetClientVersionAndKey(); - YoutubeParsingHelper.setNumberGenerator(new Random(1)); + YoutubeTestsUtils.ensureStateless(); NewPipe.init(DownloaderFactory.getDownloader(RESOURCE_PATH + "notAvailable")); } @@ -66,8 +64,7 @@ public class YoutubePlaylistExtractorTest { @BeforeAll public static void setUp() throws Exception { - YoutubeParsingHelper.resetClientVersionAndKey(); - YoutubeParsingHelper.setNumberGenerator(new Random(1)); + YoutubeTestsUtils.ensureStateless(); NewPipe.init(DownloaderFactory.getDownloader(RESOURCE_PATH + "TimelessPopHits")); extractor = (YoutubePlaylistExtractor) YouTube .getPlaylistExtractor("http://www.youtube.com/watch?v=lp-EO5I60KA&list=PLMC9KNkIncKtPzgY-5rmhvj7fax8fdxoj"); @@ -174,8 +171,7 @@ public class YoutubePlaylistExtractorTest { @BeforeAll public static void setUp() throws Exception { - YoutubeParsingHelper.resetClientVersionAndKey(); - YoutubeParsingHelper.setNumberGenerator(new Random(1)); + YoutubeTestsUtils.ensureStateless(); NewPipe.init(DownloaderFactory.getDownloader(RESOURCE_PATH + "huge")); extractor = (YoutubePlaylistExtractor) YouTube .getPlaylistExtractor("https://www.youtube.com/watch?v=8SbUC-UaAxE&list=PLWwAypAcFRgKAIIFqBr9oy-ZYZnixa_Fj"); @@ -298,8 +294,7 @@ public class YoutubePlaylistExtractorTest { @BeforeAll public static void setUp() throws Exception { - YoutubeParsingHelper.resetClientVersionAndKey(); - YoutubeParsingHelper.setNumberGenerator(new Random(1)); + YoutubeTestsUtils.ensureStateless(); NewPipe.init(DownloaderFactory.getDownloader(RESOURCE_PATH + "learning")); extractor = (YoutubePlaylistExtractor) YouTube .getPlaylistExtractor("https://www.youtube.com/playlist?list=PL8dPuuaLjXtOAKed_MxxWBNaPno5h3Zs8"); @@ -407,8 +402,7 @@ public class YoutubePlaylistExtractorTest { @BeforeAll public static void setUp() throws IOException { - YoutubeParsingHelper.resetClientVersionAndKey(); - YoutubeParsingHelper.setNumberGenerator(new Random(1)); + YoutubeTestsUtils.ensureStateless(); NewPipe.init(DownloaderFactory.getDownloader(RESOURCE_PATH + "continuations")); } diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeSuggestionExtractorTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeSuggestionExtractorTest.java index 1855f8a0..38c92537 100644 --- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeSuggestionExtractorTest.java +++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeSuggestionExtractorTest.java @@ -20,6 +20,9 @@ package org.schabi.newpipe.extractor.services.youtube; * along with NewPipe. If not, see . */ +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.schabi.newpipe.extractor.ServiceList.YouTube; + import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; import org.schabi.newpipe.downloader.DownloaderFactory; @@ -29,10 +32,6 @@ import org.schabi.newpipe.extractor.localization.Localization; import org.schabi.newpipe.extractor.suggestion.SuggestionExtractor; import java.io.IOException; -import java.util.Random; - -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.schabi.newpipe.extractor.ServiceList.YouTube; /** * Test for {@link SuggestionExtractor} @@ -45,8 +44,7 @@ public class YoutubeSuggestionExtractorTest { @BeforeAll public static void setUp() throws Exception { - YoutubeParsingHelper.resetClientVersionAndKey(); - YoutubeParsingHelper.setNumberGenerator(new Random(1)); + YoutubeTestsUtils.ensureStateless(); NewPipe.init(DownloaderFactory.getDownloader(RESOURCE_PATH + ""), new Localization("de", "DE")); suggestionExtractor = YouTube.getSuggestionExtractor(); } 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 new file mode 100644 index 00000000..cc2b3111 --- /dev/null +++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeTestsUtils.java @@ -0,0 +1,28 @@ +package org.schabi.newpipe.extractor.services.youtube; + +import org.schabi.newpipe.extractor.services.youtube.extractors.YoutubeStreamExtractor; + +import java.util.Random; + +/** + * Utility class for keeping YouTube tests stateless. + */ +public final class YoutubeTestsUtils { + private YoutubeTestsUtils() { + // No impl + } + + /** + * Clears static YT states. + * + *

+ * This method needs to be called to generate all mocks of a test when running different tests + * at the same time. + *

+ */ + public static void ensureStateless() { + YoutubeParsingHelper.resetClientVersionAndKey(); + YoutubeParsingHelper.setNumberGenerator(new Random(1)); + YoutubeStreamExtractor.resetDeobfuscationCode(); + } +} diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeTrendingKioskInfoTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeTrendingKioskInfoTest.java index 164ffc8f..77696a04 100644 --- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeTrendingKioskInfoTest.java +++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeTrendingKioskInfoTest.java @@ -20,6 +20,10 @@ package org.schabi.newpipe.extractor.services.youtube; * along with NewPipe. If not, see . */ +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.schabi.newpipe.extractor.ServiceList.YouTube; + import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; import org.schabi.newpipe.downloader.DownloaderFactory; @@ -28,12 +32,6 @@ import org.schabi.newpipe.extractor.StreamingService; import org.schabi.newpipe.extractor.kiosk.KioskInfo; import org.schabi.newpipe.extractor.linkhandler.LinkHandlerFactory; -import java.util.Random; - -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.schabi.newpipe.extractor.ServiceList.YouTube; - /** * Test for {@link KioskInfo} */ @@ -46,8 +44,7 @@ public class YoutubeTrendingKioskInfoTest { @BeforeAll public static void setUp() throws Exception { - YoutubeParsingHelper.resetClientVersionAndKey(); - YoutubeParsingHelper.setNumberGenerator(new Random(1)); + YoutubeTestsUtils.ensureStateless(); NewPipe.init(DownloaderFactory.getDownloader(RESOURCE_PATH)); LinkHandlerFactory LinkHandlerFactory = ((StreamingService) YouTube).getKioskList().getListLinkHandlerFactoryByType("Trending"); diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/search/YoutubeSearchExtractorTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/search/YoutubeSearchExtractorTest.java index 57a9ccb5..29f88c49 100644 --- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/search/YoutubeSearchExtractorTest.java +++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/search/YoutubeSearchExtractorTest.java @@ -25,7 +25,7 @@ import org.schabi.newpipe.extractor.channel.ChannelInfoItem; import org.schabi.newpipe.extractor.exceptions.ExtractionException; import org.schabi.newpipe.extractor.search.SearchExtractor; import org.schabi.newpipe.extractor.services.DefaultSearchExtractorTest; -import org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper; +import org.schabi.newpipe.extractor.services.youtube.YoutubeTestsUtils; import org.schabi.newpipe.extractor.stream.Description; import org.schabi.newpipe.extractor.stream.StreamInfoItem; @@ -35,7 +35,6 @@ import java.net.URL; import java.util.ArrayList; import java.util.Collections; import java.util.List; -import java.util.Random; import javax.annotation.Nullable; @@ -49,8 +48,7 @@ public class YoutubeSearchExtractorTest { @BeforeAll public static void setUp() throws Exception { - YoutubeParsingHelper.resetClientVersionAndKey(); - YoutubeParsingHelper.setNumberGenerator(new Random(1)); + YoutubeTestsUtils.ensureStateless(); NewPipe.init(DownloaderFactory.getDownloader(RESOURCE_PATH + "all")); extractor = YouTube.getSearchExtractor(QUERY); extractor.fetchPage(); @@ -72,8 +70,7 @@ public class YoutubeSearchExtractorTest { @BeforeAll public static void setUp() throws Exception { - YoutubeParsingHelper.resetClientVersionAndKey(); - YoutubeParsingHelper.setNumberGenerator(new Random(1)); + YoutubeTestsUtils.ensureStateless(); NewPipe.init(DownloaderFactory.getDownloader(RESOURCE_PATH + "channel")); extractor = YouTube.getSearchExtractor(QUERY, singletonList(CHANNELS), ""); extractor.fetchPage(); @@ -97,8 +94,7 @@ public class YoutubeSearchExtractorTest { @BeforeAll public static void setUp() throws Exception { - YoutubeParsingHelper.resetClientVersionAndKey(); - YoutubeParsingHelper.setNumberGenerator(new Random(1)); + YoutubeTestsUtils.ensureStateless(); NewPipe.init(DownloaderFactory.getDownloader(RESOURCE_PATH + "playlist")); extractor = YouTube.getSearchExtractor(QUERY, singletonList(PLAYLISTS), ""); extractor.fetchPage(); @@ -122,8 +118,7 @@ public class YoutubeSearchExtractorTest { @BeforeAll public static void setUp() throws Exception { - YoutubeParsingHelper.resetClientVersionAndKey(); - YoutubeParsingHelper.setNumberGenerator(new Random(1)); + YoutubeTestsUtils.ensureStateless(); NewPipe.init(DownloaderFactory.getDownloader(RESOURCE_PATH + "videos")); extractor = YouTube.getSearchExtractor(QUERY, singletonList(VIDEOS), ""); extractor.fetchPage(); @@ -149,8 +144,7 @@ public class YoutubeSearchExtractorTest { @BeforeAll public static void setUp() throws Exception { - YoutubeParsingHelper.resetClientVersionAndKey(); - YoutubeParsingHelper.setNumberGenerator(new Random(1)); + YoutubeTestsUtils.ensureStateless(); NewPipe.init(DownloaderFactory.getDownloader(RESOURCE_PATH + "suggestions")); extractor = YouTube.getSearchExtractor(QUERY, singletonList(VIDEOS), ""); extractor.fetchPage(); @@ -174,8 +168,7 @@ public class YoutubeSearchExtractorTest { @BeforeAll public static void setUp() throws Exception { - YoutubeParsingHelper.resetClientVersionAndKey(); - YoutubeParsingHelper.setNumberGenerator(new Random(1)); + YoutubeTestsUtils.ensureStateless(); NewPipe.init(DownloaderFactory.getDownloader(RESOURCE_PATH + "corrected")); extractor = YouTube.getSearchExtractor(QUERY, singletonList(VIDEOS), ""); extractor.fetchPage(); @@ -199,8 +192,7 @@ public class YoutubeSearchExtractorTest { @BeforeAll public static void setUp() throws Exception { - YoutubeParsingHelper.resetClientVersionAndKey(); - YoutubeParsingHelper.setNumberGenerator(new Random(1)); + YoutubeTestsUtils.ensureStateless(); NewPipe.init(DownloaderFactory.getDownloader(RESOURCE_PATH + "random")); extractor = YouTube.getSearchExtractor(QUERY); extractor.fetchPage(); @@ -235,8 +227,7 @@ public class YoutubeSearchExtractorTest { public static class PagingTest { @Test public void duplicatedItemsCheck() throws Exception { - YoutubeParsingHelper.resetClientVersionAndKey(); - YoutubeParsingHelper.setNumberGenerator(new Random(1)); + YoutubeTestsUtils.ensureStateless(); NewPipe.init(DownloaderFactory.getDownloader(RESOURCE_PATH + "paging")); final SearchExtractor extractor = YouTube.getSearchExtractor("cirque du soleil", singletonList(VIDEOS), ""); extractor.fetchPage(); @@ -254,8 +245,7 @@ public class YoutubeSearchExtractorTest { @BeforeAll public static void setUp() throws Exception { - YoutubeParsingHelper.resetClientVersionAndKey(); - YoutubeParsingHelper.setNumberGenerator(new Random(1)); + YoutubeTestsUtils.ensureStateless(); NewPipe.init(DownloaderFactory.getDownloader(RESOURCE_PATH + "metaInfo")); extractor = YouTube.getSearchExtractor(QUERY, singletonList(VIDEOS), ""); extractor.fetchPage(); @@ -291,8 +281,7 @@ public class YoutubeSearchExtractorTest { @BeforeAll public static void setUp() throws Exception { - YoutubeParsingHelper.resetClientVersionAndKey(); - YoutubeParsingHelper.setNumberGenerator(new Random(1)); + YoutubeTestsUtils.ensureStateless(); NewPipe.init(DownloaderFactory.getDownloader(RESOURCE_PATH + "verified")); extractor = YouTube.getSearchExtractor(QUERY, singletonList(CHANNELS), ""); extractor.fetchPage(); @@ -329,8 +318,7 @@ public class YoutubeSearchExtractorTest { @BeforeAll public static void setUp() throws Exception { - YoutubeParsingHelper.resetClientVersionAndKey(); - YoutubeParsingHelper.setNumberGenerator(new Random(1)); + YoutubeTestsUtils.ensureStateless(); NewPipe.init(DownloaderFactory.getDownloader(RESOURCE_PATH + "video_uploader_avatar")); extractor = YouTube.getSearchExtractor(QUERY, singletonList(VIDEOS), ""); extractor.fetchPage(); @@ -361,8 +349,7 @@ public class YoutubeSearchExtractorTest { @BeforeAll public static void setUp() throws Exception { - YoutubeParsingHelper.resetClientVersionAndKey(); - YoutubeParsingHelper.setNumberGenerator(new Random(1)); + YoutubeTestsUtils.ensureStateless(); NewPipe.init(DownloaderFactory.getDownloader(RESOURCE_PATH + "video_description")); extractor = YouTube.getSearchExtractor(QUERY, singletonList(VIDEOS), ""); extractor.fetchPage(); diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/stream/YoutubeStreamExtractorAgeRestrictedTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/stream/YoutubeStreamExtractorAgeRestrictedTest.java index 5ee83f56..f72f598c 100644 --- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/stream/YoutubeStreamExtractorAgeRestrictedTest.java +++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/stream/YoutubeStreamExtractorAgeRestrictedTest.java @@ -1,23 +1,21 @@ package org.schabi.newpipe.extractor.services.youtube.stream; +import static org.schabi.newpipe.extractor.ServiceList.YouTube; + import org.junit.jupiter.api.BeforeAll; import org.schabi.newpipe.downloader.DownloaderFactory; import org.schabi.newpipe.extractor.NewPipe; import org.schabi.newpipe.extractor.StreamingService; import org.schabi.newpipe.extractor.services.DefaultStreamExtractorTest; -import org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper; -import org.schabi.newpipe.extractor.services.youtube.extractors.YoutubeStreamExtractor; +import org.schabi.newpipe.extractor.services.youtube.YoutubeTestsUtils; import org.schabi.newpipe.extractor.stream.StreamExtractor; import org.schabi.newpipe.extractor.stream.StreamType; import java.util.Collections; import java.util.List; -import java.util.Random; import javax.annotation.Nullable; -import static org.schabi.newpipe.extractor.ServiceList.YouTube; - public class YoutubeStreamExtractorAgeRestrictedTest extends DefaultStreamExtractorTest { private static final String RESOURCE_PATH = DownloaderFactory.RESOURCE_PATH + "services/youtube/extractor/stream/"; private static final String ID = "rwcfPqbAx-0"; @@ -27,10 +25,7 @@ public class YoutubeStreamExtractorAgeRestrictedTest extends DefaultStreamExtrac @BeforeAll public static void setUp() throws Exception { - YoutubeParsingHelper.resetClientVersionAndKey(); - YoutubeParsingHelper.setNumberGenerator(new Random(1)); - YoutubeParsingHelper.setSeedForVideoTests(); - YoutubeStreamExtractor.resetDeobfuscationCode(); + YoutubeTestsUtils.ensureStateless(); NewPipe.init(DownloaderFactory.getDownloader(RESOURCE_PATH + "ageRestricted")); extractor = YouTube.getStreamExtractor(URL); extractor.fetchPage(); diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/stream/YoutubeStreamExtractorControversialTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/stream/YoutubeStreamExtractorControversialTest.java index 4f692fd3..085fce5b 100644 --- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/stream/YoutubeStreamExtractorControversialTest.java +++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/stream/YoutubeStreamExtractorControversialTest.java @@ -1,24 +1,22 @@ package org.schabi.newpipe.extractor.services.youtube.stream; +import static org.schabi.newpipe.extractor.ServiceList.YouTube; + import org.junit.jupiter.api.BeforeAll; import org.schabi.newpipe.downloader.DownloaderFactory; import org.schabi.newpipe.extractor.NewPipe; import org.schabi.newpipe.extractor.StreamingService; import org.schabi.newpipe.extractor.services.DefaultStreamExtractorTest; -import org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper; -import org.schabi.newpipe.extractor.services.youtube.extractors.YoutubeStreamExtractor; +import org.schabi.newpipe.extractor.services.youtube.YoutubeTestsUtils; import org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubeStreamLinkHandlerFactory; import org.schabi.newpipe.extractor.stream.StreamExtractor; import org.schabi.newpipe.extractor.stream.StreamType; import java.util.Arrays; import java.util.List; -import java.util.Random; import javax.annotation.Nullable; -import static org.schabi.newpipe.extractor.ServiceList.YouTube; - /** * Test for {@link YoutubeStreamLinkHandlerFactory} */ @@ -31,10 +29,7 @@ public class YoutubeStreamExtractorControversialTest extends DefaultStreamExtrac @BeforeAll public static void setUp() throws Exception { - YoutubeParsingHelper.resetClientVersionAndKey(); - YoutubeParsingHelper.setNumberGenerator(new Random(1)); - YoutubeParsingHelper.setSeedForVideoTests(); - YoutubeStreamExtractor.resetDeobfuscationCode(); + YoutubeTestsUtils.ensureStateless(); NewPipe.init(DownloaderFactory.getDownloader(RESOURCE_PATH + "controversial")); extractor = YouTube.getStreamExtractor(URL); extractor.fetchPage(); diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/stream/YoutubeStreamExtractorDefaultTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/stream/YoutubeStreamExtractorDefaultTest.java index 95024aec..f1506154 100644 --- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/stream/YoutubeStreamExtractorDefaultTest.java +++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/stream/YoutubeStreamExtractorDefaultTest.java @@ -20,6 +20,12 @@ package org.schabi.newpipe.extractor.services.youtube.stream; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.schabi.newpipe.extractor.ServiceList.YouTube; +import static org.schabi.newpipe.extractor.utils.Utils.EMPTY_STRING; + import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; @@ -35,9 +41,12 @@ import org.schabi.newpipe.extractor.exceptions.ParsingException; import org.schabi.newpipe.extractor.exceptions.PrivateContentException; import org.schabi.newpipe.extractor.exceptions.YoutubeMusicPremiumContentException; import org.schabi.newpipe.extractor.services.DefaultStreamExtractorTest; -import org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper; +import org.schabi.newpipe.extractor.services.youtube.YoutubeTestsUtils; import org.schabi.newpipe.extractor.services.youtube.extractors.YoutubeStreamExtractor; -import org.schabi.newpipe.extractor.stream.*; +import org.schabi.newpipe.extractor.stream.Description; +import org.schabi.newpipe.extractor.stream.StreamExtractor; +import org.schabi.newpipe.extractor.stream.StreamSegment; +import org.schabi.newpipe.extractor.stream.StreamType; import java.io.IOException; import java.net.MalformedURLException; @@ -45,16 +54,9 @@ import java.net.URL; import java.util.Arrays; import java.util.Collections; import java.util.List; -import java.util.Random; import javax.annotation.Nullable; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.schabi.newpipe.extractor.ServiceList.YouTube; -import static org.schabi.newpipe.extractor.utils.Utils.EMPTY_STRING; - public class YoutubeStreamExtractorDefaultTest { private static final String RESOURCE_PATH = DownloaderFactory.RESOURCE_PATH + "services/youtube/extractor/stream/"; static final String BASE_URL = "https://www.youtube.com/watch?v="; @@ -63,10 +65,7 @@ public class YoutubeStreamExtractorDefaultTest { public static class NotAvailable { @BeforeAll public static void setUp() throws IOException { - YoutubeParsingHelper.resetClientVersionAndKey(); - YoutubeParsingHelper.setNumberGenerator(new Random(1)); - YoutubeParsingHelper.setSeedForVideoTests(); - YoutubeStreamExtractor.resetDeobfuscationCode(); + YoutubeTestsUtils.ensureStateless(); NewPipe.init(DownloaderFactory.getDownloader(RESOURCE_PATH + "notAvailable")); } @@ -121,10 +120,7 @@ public class YoutubeStreamExtractorDefaultTest { @BeforeAll public static void setUp() throws Exception { - YoutubeParsingHelper.resetClientVersionAndKey(); - YoutubeParsingHelper.setNumberGenerator(new Random(1)); - YoutubeParsingHelper.setSeedForVideoTests(); - YoutubeStreamExtractor.resetDeobfuscationCode(); + YoutubeTestsUtils.ensureStateless(); NewPipe.init(DownloaderFactory.getDownloader(RESOURCE_PATH + "pewdiwpie")); extractor = YouTube.getStreamExtractor(URL); extractor.fetchPage(); @@ -167,10 +163,7 @@ public class YoutubeStreamExtractorDefaultTest { @BeforeAll public static void setUp() throws Exception { - YoutubeParsingHelper.resetClientVersionAndKey(); - YoutubeParsingHelper.setNumberGenerator(new Random(1)); - YoutubeParsingHelper.setSeedForVideoTests(); - YoutubeStreamExtractor.resetDeobfuscationCode(); + YoutubeTestsUtils.ensureStateless(); NewPipe.init(DownloaderFactory.getDownloader(RESOURCE_PATH + "unboxing")); extractor = YouTube.getStreamExtractor(URL); extractor.fetchPage(); @@ -223,10 +216,7 @@ public class YoutubeStreamExtractorDefaultTest { @BeforeAll public static void setUp() throws Exception { - YoutubeParsingHelper.resetClientVersionAndKey(); - YoutubeParsingHelper.setNumberGenerator(new Random(1)); - YoutubeParsingHelper.setSeedForVideoTests(); - YoutubeStreamExtractor.resetDeobfuscationCode(); + YoutubeTestsUtils.ensureStateless(); NewPipe.init(DownloaderFactory.getDownloader(RESOURCE_PATH + "ratingsDisabled")); extractor = YouTube.getStreamExtractor(URL); extractor.fetchPage(); @@ -262,10 +252,7 @@ public class YoutubeStreamExtractorDefaultTest { @BeforeAll public static void setUp() throws Exception { - YoutubeParsingHelper.resetClientVersionAndKey(); - YoutubeParsingHelper.setNumberGenerator(new Random(1)); - YoutubeParsingHelper.setSeedForVideoTests(); - YoutubeStreamExtractor.resetDeobfuscationCode(); + YoutubeTestsUtils.ensureStateless(); NewPipe.init(DownloaderFactory.getDownloader(RESOURCE_PATH + "streamSegmentsTagesschau")); extractor = YouTube.getStreamExtractor(URL); extractor.fetchPage(); @@ -300,7 +287,7 @@ public class YoutubeStreamExtractorDefaultTest { // @formatter:on @Test - public void testStreamSegment0() throws Exception { + void testStreamSegment0() throws Exception { final StreamSegment segment = extractor.getStreamSegments().get(0); assertEquals(0, segment.getStartTimeSeconds()); assertEquals("Guten Abend", segment.getTitle()); @@ -309,7 +296,7 @@ public class YoutubeStreamExtractorDefaultTest { } @Test - public void testStreamSegment3() throws Exception { + void testStreamSegment3() throws Exception { final StreamSegment segment = extractor.getStreamSegments().get(3); assertEquals(224, segment.getStartTimeSeconds()); assertEquals("Pandemie dämpft Konjunkturprognose für 2021", segment.getTitle()); @@ -326,9 +313,7 @@ public class YoutubeStreamExtractorDefaultTest { @BeforeAll public static void setUp() throws Exception { - YoutubeParsingHelper.resetClientVersionAndKey(); - YoutubeParsingHelper.setNumberGenerator(new Random(1)); - YoutubeStreamExtractor.resetDeobfuscationCode(); + YoutubeTestsUtils.ensureStateless(); NewPipe.init(DownloaderFactory.getDownloader(RESOURCE_PATH + "streamSegmentsMaiLab")); extractor = YouTube.getStreamExtractor(URL); extractor.fetchPage(); @@ -369,7 +354,7 @@ public class YoutubeStreamExtractorDefaultTest { // @formatter:on @Test - public void testStreamSegment() throws Exception { + void testStreamSegment() throws Exception { final StreamSegment segment = extractor.getStreamSegments().get(1); assertEquals(164, segment.getStartTimeSeconds()); assertEquals("Was ist Vitamin D?", segment.getTitle()); @@ -396,10 +381,7 @@ public class YoutubeStreamExtractorDefaultTest { @BeforeAll public static void setUp() throws Exception { - YoutubeParsingHelper.resetClientVersionAndKey(); - YoutubeParsingHelper.setNumberGenerator(new Random(1)); - YoutubeParsingHelper.setSeedForVideoTests(); - YoutubeStreamExtractor.resetDeobfuscationCode(); + YoutubeTestsUtils.ensureStateless(); NewPipe.init(DownloaderFactory.getDownloader(RESOURCE_PATH + "publicBroadcast")); extractor = YouTube.getStreamExtractor(URL); extractor.fetchPage(); @@ -452,10 +434,7 @@ public class YoutubeStreamExtractorDefaultTest { @BeforeAll public static void setUp() throws Exception { - YoutubeParsingHelper.resetClientVersionAndKey(); - YoutubeParsingHelper.setNumberGenerator(new Random(1)); - YoutubeParsingHelper.setSeedForVideoTests(); - YoutubeStreamExtractor.resetDeobfuscationCode(); + YoutubeTestsUtils.ensureStateless(); NewPipe.init(DownloaderTestImpl.getInstance()); extractor = (YoutubeStreamExtractor) YouTube .getStreamExtractor("https://www.youtube.com/watch?v=tjz2u2DiveM"); @@ -463,7 +442,7 @@ public class YoutubeStreamExtractorDefaultTest { } @Test - public void testGetUnlisted() { + void testGetUnlisted() { assertEquals(StreamExtractor.Privacy.UNLISTED, extractor.getPrivacy()); } } @@ -475,17 +454,14 @@ public class YoutubeStreamExtractorDefaultTest { @BeforeAll public static void setUp() throws Exception { - YoutubeParsingHelper.resetClientVersionAndKey(); - YoutubeParsingHelper.setNumberGenerator(new Random(1)); - YoutubeParsingHelper.setSeedForVideoTests(); - YoutubeStreamExtractor.resetDeobfuscationCode(); + YoutubeTestsUtils.ensureStateless(); NewPipe.init(DownloaderTestImpl.getInstance()); extractor = YouTube.getStreamExtractor(URL); extractor.fetchPage(); } @Test - public void testGetLicence() throws ParsingException { + void testGetLicence() throws ParsingException { assertEquals("Creative Commons Attribution licence (reuse allowed)", extractor.getLicence()); } } diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/stream/YoutubeStreamExtractorLivestreamTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/stream/YoutubeStreamExtractorLivestreamTest.java index 78743241..81fbf126 100644 --- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/stream/YoutubeStreamExtractorLivestreamTest.java +++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/stream/YoutubeStreamExtractorLivestreamTest.java @@ -1,24 +1,22 @@ package org.schabi.newpipe.extractor.services.youtube.stream; +import static org.schabi.newpipe.extractor.ServiceList.YouTube; + import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; import org.schabi.newpipe.downloader.DownloaderFactory; import org.schabi.newpipe.extractor.NewPipe; import org.schabi.newpipe.extractor.StreamingService; import org.schabi.newpipe.extractor.services.DefaultStreamExtractorTest; -import org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper; -import org.schabi.newpipe.extractor.services.youtube.extractors.YoutubeStreamExtractor; +import org.schabi.newpipe.extractor.services.youtube.YoutubeTestsUtils; import org.schabi.newpipe.extractor.stream.StreamExtractor; import org.schabi.newpipe.extractor.stream.StreamType; import java.util.Arrays; import java.util.List; -import java.util.Random; import javax.annotation.Nullable; -import static org.schabi.newpipe.extractor.ServiceList.YouTube; - public class YoutubeStreamExtractorLivestreamTest extends DefaultStreamExtractorTest { private static final String RESOURCE_PATH = DownloaderFactory.RESOURCE_PATH + "services/youtube/extractor/stream/"; private static final String ID = "5qap5aO4i9A"; @@ -28,10 +26,7 @@ public class YoutubeStreamExtractorLivestreamTest extends DefaultStreamExtractor @BeforeAll public static void setUp() throws Exception { - YoutubeParsingHelper.resetClientVersionAndKey(); - YoutubeParsingHelper.setNumberGenerator(new Random(1)); - YoutubeParsingHelper.setSeedForVideoTests(); - YoutubeStreamExtractor.resetDeobfuscationCode(); + YoutubeTestsUtils.ensureStateless(); NewPipe.init(DownloaderFactory.getDownloader(RESOURCE_PATH + "live")); extractor = YouTube.getStreamExtractor(URL); extractor.fetchPage(); diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/stream/YoutubeStreamExtractorRelatedMixTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/stream/YoutubeStreamExtractorRelatedMixTest.java index f414276a..6dd80f18 100644 --- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/stream/YoutubeStreamExtractorRelatedMixTest.java +++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/stream/YoutubeStreamExtractorRelatedMixTest.java @@ -19,6 +19,7 @@ import org.schabi.newpipe.extractor.playlist.PlaylistInfo.PlaylistType; import org.schabi.newpipe.extractor.playlist.PlaylistInfoItem; import org.schabi.newpipe.extractor.services.DefaultStreamExtractorTest; import org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper; +import org.schabi.newpipe.extractor.services.youtube.YoutubeTestsUtils; import org.schabi.newpipe.extractor.services.youtube.extractors.YoutubeStreamExtractor; import org.schabi.newpipe.extractor.stream.StreamExtractor; import org.schabi.newpipe.extractor.stream.StreamType; @@ -40,10 +41,7 @@ public class YoutubeStreamExtractorRelatedMixTest extends DefaultStreamExtractor @BeforeAll public static void setUp() throws Exception { - YoutubeParsingHelper.resetClientVersionAndKey(); - YoutubeParsingHelper.setNumberGenerator(new Random(1)); - YoutubeParsingHelper.setSeedForVideoTests(); - YoutubeStreamExtractor.resetDeobfuscationCode(); + YoutubeTestsUtils.ensureStateless(); NewPipe.init(DownloaderFactory.getDownloader(RESOURCE_PATH + "relatedMix")); extractor = YouTube.getStreamExtractor(URL); extractor.fetchPage(); diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/stream/YoutubeStreamExtractorUnlistedTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/stream/YoutubeStreamExtractorUnlistedTest.java index 800676cc..691ec591 100644 --- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/stream/YoutubeStreamExtractorUnlistedTest.java +++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/stream/YoutubeStreamExtractorUnlistedTest.java @@ -1,24 +1,22 @@ package org.schabi.newpipe.extractor.services.youtube.stream; +import static org.schabi.newpipe.extractor.ServiceList.YouTube; +import static org.schabi.newpipe.extractor.stream.StreamExtractor.Privacy.UNLISTED; + import org.junit.jupiter.api.BeforeAll; import org.schabi.newpipe.downloader.DownloaderFactory; import org.schabi.newpipe.extractor.NewPipe; import org.schabi.newpipe.extractor.StreamingService; import org.schabi.newpipe.extractor.services.DefaultStreamExtractorTest; -import org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper; -import org.schabi.newpipe.extractor.services.youtube.extractors.YoutubeStreamExtractor; +import org.schabi.newpipe.extractor.services.youtube.YoutubeTestsUtils; import org.schabi.newpipe.extractor.stream.StreamExtractor; import org.schabi.newpipe.extractor.stream.StreamType; import java.util.Arrays; import java.util.List; -import java.util.Random; import javax.annotation.Nullable; -import static org.schabi.newpipe.extractor.ServiceList.YouTube; -import static org.schabi.newpipe.extractor.stream.StreamExtractor.Privacy.UNLISTED; - public class YoutubeStreamExtractorUnlistedTest extends DefaultStreamExtractorTest { private static final String RESOURCE_PATH = DownloaderFactory.RESOURCE_PATH + "services/youtube/extractor/stream/"; static final String ID = "udsB8KnIJTg"; @@ -27,10 +25,7 @@ public class YoutubeStreamExtractorUnlistedTest extends DefaultStreamExtractorTe @BeforeAll public static void setUp() throws Exception { - YoutubeParsingHelper.resetClientVersionAndKey(); - YoutubeParsingHelper.setNumberGenerator(new Random(1)); - YoutubeParsingHelper.setSeedForVideoTests(); - YoutubeStreamExtractor.resetDeobfuscationCode(); + YoutubeTestsUtils.ensureStateless(); NewPipe.init(DownloaderFactory.getDownloader(RESOURCE_PATH + "unlisted")); extractor = YouTube.getStreamExtractor(URL); extractor.fetchPage();