Skip to content

Commit 5237694

Browse files
committed
Add setSeedForVideoTests method in YoutubeStreamExtractor tests
In order to use still use mocks with the generation of random strings in player requests, we need to use YoutubeParsingHelper.setSeedForVideoTests() method in every stream test.
1 parent d0d91e6 commit 5237694

6 files changed

Lines changed: 38 additions & 20 deletions

extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/stream/YoutubeStreamExtractorAgeRestrictedTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ public class YoutubeStreamExtractorAgeRestrictedTest extends DefaultStreamExtrac
2929
public static void setUp() throws Exception {
3030
YoutubeParsingHelper.resetClientVersionAndKey();
3131
YoutubeParsingHelper.setNumberGenerator(new Random(1));
32+
YoutubeParsingHelper.setSeedForVideoTests();
3233
YoutubeStreamExtractor.resetDeobfuscationCode();
3334
NewPipe.init(DownloaderFactory.getDownloader(RESOURCE_PATH + "ageRestricted"));
3435
extractor = YouTube.getStreamExtractor(URL);

extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/stream/YoutubeStreamExtractorControversialTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ public class YoutubeStreamExtractorControversialTest extends DefaultStreamExtrac
3333
public static void setUp() throws Exception {
3434
YoutubeParsingHelper.resetClientVersionAndKey();
3535
YoutubeParsingHelper.setNumberGenerator(new Random(1));
36+
YoutubeParsingHelper.setSeedForVideoTests();
3637
YoutubeStreamExtractor.resetDeobfuscationCode();
3738
NewPipe.init(DownloaderFactory.getDownloader(RESOURCE_PATH + "controversial"));
3839
extractor = YouTube.getStreamExtractor(URL);

extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/stream/YoutubeStreamExtractorDefaultTest.java

Lines changed: 33 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,23 @@
1+
/*
2+
* Created by Christian Schabesberger on 30.12.15.
3+
*
4+
* Copyright (C) Christian Schabesberger 2015 <chris.schabesberger@mailbox.org>
5+
* YoutubeVideoExtractorDefault.java is part of NewPipe Extractor.
6+
*
7+
* NewPipe Extractor is free software: you can redistribute it and/or modify
8+
* it under the terms of the GNU General Public License as published by
9+
* the Free Software Foundation, either version 3 of the License, or
10+
* (at your option) any later version.
11+
*
12+
* NewPipe Extractor is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU General Public License
18+
* along with NewPipe Extractor. If not, see <https://www.gnu.org/licenses/>.
19+
*/
20+
121
package org.schabi.newpipe.extractor.services.youtube.stream;
222

323
import org.junit.jupiter.api.BeforeAll;
@@ -35,25 +55,6 @@
3555
import static org.schabi.newpipe.extractor.ServiceList.YouTube;
3656
import static org.schabi.newpipe.extractor.utils.Utils.EMPTY_STRING;
3757

38-
/*
39-
* Created by Christian Schabesberger on 30.12.15.
40-
*
41-
* Copyright (C) Christian Schabesberger 2015 <chris.schabesberger@mailbox.org>
42-
* YoutubeVideoExtractorDefault.java is part of NewPipe.
43-
*
44-
* NewPipe is free software: you can redistribute it and/or modify
45-
* it under the terms of the GNU General Public License as published by
46-
* the Free Software Foundation, either version 3 of the License, or
47-
* (at your option) any later version.
48-
*
49-
* NewPipe is distributed in the hope that it will be useful,
50-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
51-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
52-
* GNU General Public License for more details.
53-
*
54-
* You should have received a copy of the GNU General Public License
55-
* along with NewPipe. If not, see <http://www.gnu.org/licenses/>.
56-
*/
5758
public class YoutubeStreamExtractorDefaultTest {
5859
private static final String RESOURCE_PATH = DownloaderFactory.RESOURCE_PATH + "services/youtube/extractor/stream/";
5960
static final String BASE_URL = "https://www.youtube.com/watch?v=";
@@ -64,6 +65,7 @@ public static class NotAvailable {
6465
public static void setUp() throws IOException {
6566
YoutubeParsingHelper.resetClientVersionAndKey();
6667
YoutubeParsingHelper.setNumberGenerator(new Random(1));
68+
YoutubeParsingHelper.setSeedForVideoTests();
6769
YoutubeStreamExtractor.resetDeobfuscationCode();
6870
NewPipe.init(DownloaderFactory.getDownloader(RESOURCE_PATH + "notAvailable"));
6971
}
@@ -121,6 +123,7 @@ public static class DescriptionTestPewdiepie extends DefaultStreamExtractorTest
121123
public static void setUp() throws Exception {
122124
YoutubeParsingHelper.resetClientVersionAndKey();
123125
YoutubeParsingHelper.setNumberGenerator(new Random(1));
126+
YoutubeParsingHelper.setSeedForVideoTests();
124127
YoutubeStreamExtractor.resetDeobfuscationCode();
125128
NewPipe.init(DownloaderFactory.getDownloader(RESOURCE_PATH + "pewdiwpie"));
126129
extractor = YouTube.getStreamExtractor(URL);
@@ -166,6 +169,7 @@ public static class DescriptionTestUnboxing extends DefaultStreamExtractorTest {
166169
public static void setUp() throws Exception {
167170
YoutubeParsingHelper.resetClientVersionAndKey();
168171
YoutubeParsingHelper.setNumberGenerator(new Random(1));
172+
YoutubeParsingHelper.setSeedForVideoTests();
169173
YoutubeStreamExtractor.resetDeobfuscationCode();
170174
NewPipe.init(DownloaderFactory.getDownloader(RESOURCE_PATH + "unboxing"));
171175
extractor = YouTube.getStreamExtractor(URL);
@@ -221,6 +225,7 @@ public static class RatingsDisabledTest extends DefaultStreamExtractorTest {
221225
public static void setUp() throws Exception {
222226
YoutubeParsingHelper.resetClientVersionAndKey();
223227
YoutubeParsingHelper.setNumberGenerator(new Random(1));
228+
YoutubeParsingHelper.setSeedForVideoTests();
224229
YoutubeStreamExtractor.resetDeobfuscationCode();
225230
NewPipe.init(DownloaderFactory.getDownloader(RESOURCE_PATH + "ratingsDisabled"));
226231
extractor = YouTube.getStreamExtractor(URL);
@@ -259,6 +264,7 @@ public static class StreamSegmentsTestTagesschau extends DefaultStreamExtractorT
259264
public static void setUp() throws Exception {
260265
YoutubeParsingHelper.resetClientVersionAndKey();
261266
YoutubeParsingHelper.setNumberGenerator(new Random(1));
267+
YoutubeParsingHelper.setSeedForVideoTests();
262268
YoutubeStreamExtractor.resetDeobfuscationCode();
263269
NewPipe.init(DownloaderFactory.getDownloader(RESOURCE_PATH + "streamSegmentsTagesschau"));
264270
extractor = YouTube.getStreamExtractor(URL);
@@ -392,9 +398,10 @@ public static class PublicBroadcasterTest extends DefaultStreamExtractorTest {
392398
public static void setUp() throws Exception {
393399
YoutubeParsingHelper.resetClientVersionAndKey();
394400
YoutubeParsingHelper.setNumberGenerator(new Random(1));
401+
YoutubeParsingHelper.setSeedForVideoTests();
402+
YoutubeStreamExtractor.resetDeobfuscationCode();
395403
NewPipe.init(DownloaderFactory.getDownloader(RESOURCE_PATH + "publicBroadcast"));
396404
extractor = YouTube.getStreamExtractor(URL);
397-
YoutubeStreamExtractor.resetDeobfuscationCode();
398405
extractor.fetchPage();
399406
}
400407

@@ -445,6 +452,9 @@ public static class UnlistedTest {
445452

446453
@BeforeAll
447454
public static void setUp() throws Exception {
455+
YoutubeParsingHelper.resetClientVersionAndKey();
456+
YoutubeParsingHelper.setNumberGenerator(new Random(1));
457+
YoutubeParsingHelper.setSeedForVideoTests();
448458
YoutubeStreamExtractor.resetDeobfuscationCode();
449459
NewPipe.init(DownloaderTestImpl.getInstance());
450460
extractor = (YoutubeStreamExtractor) YouTube
@@ -465,6 +475,9 @@ public static class CCLicensed {
465475

466476
@BeforeAll
467477
public static void setUp() throws Exception {
478+
YoutubeParsingHelper.resetClientVersionAndKey();
479+
YoutubeParsingHelper.setNumberGenerator(new Random(1));
480+
YoutubeParsingHelper.setSeedForVideoTests();
468481
YoutubeStreamExtractor.resetDeobfuscationCode();
469482
NewPipe.init(DownloaderTestImpl.getInstance());
470483
extractor = YouTube.getStreamExtractor(URL);

extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/stream/YoutubeStreamExtractorLivestreamTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ public class YoutubeStreamExtractorLivestreamTest extends DefaultStreamExtractor
3030
public static void setUp() throws Exception {
3131
YoutubeParsingHelper.resetClientVersionAndKey();
3232
YoutubeParsingHelper.setNumberGenerator(new Random(1));
33+
YoutubeParsingHelper.setSeedForVideoTests();
3334
YoutubeStreamExtractor.resetDeobfuscationCode();
3435
NewPipe.init(DownloaderFactory.getDownloader(RESOURCE_PATH + "live"));
3536
extractor = YouTube.getStreamExtractor(URL);

extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/stream/YoutubeStreamExtractorRelatedMixTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ public class YoutubeStreamExtractorRelatedMixTest extends DefaultStreamExtractor
4242
public static void setUp() throws Exception {
4343
YoutubeParsingHelper.resetClientVersionAndKey();
4444
YoutubeParsingHelper.setNumberGenerator(new Random(1));
45+
YoutubeParsingHelper.setSeedForVideoTests();
4546
YoutubeStreamExtractor.resetDeobfuscationCode();
4647
NewPipe.init(DownloaderFactory.getDownloader(RESOURCE_PATH + "relatedMix"));
4748
extractor = YouTube.getStreamExtractor(URL);

extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/stream/YoutubeStreamExtractorUnlistedTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ public class YoutubeStreamExtractorUnlistedTest extends DefaultStreamExtractorTe
2929
public static void setUp() throws Exception {
3030
YoutubeParsingHelper.resetClientVersionAndKey();
3131
YoutubeParsingHelper.setNumberGenerator(new Random(1));
32+
YoutubeParsingHelper.setSeedForVideoTests();
3233
YoutubeStreamExtractor.resetDeobfuscationCode();
3334
NewPipe.init(DownloaderFactory.getDownloader(RESOURCE_PATH + "unlisted"));
3435
extractor = YouTube.getStreamExtractor(URL);

0 commit comments

Comments
 (0)