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 b7ed738c7..64bcbf26f 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 @@ -3,6 +3,7 @@ package org.schabi.newpipe.extractor.services.youtube; import org.junit.BeforeClass; import org.junit.Ignore; import org.junit.Test; +import org.schabi.newpipe.downloader.DownloaderFactory; import org.schabi.newpipe.downloader.DownloaderTestImpl; import org.schabi.newpipe.extractor.NewPipe; import org.schabi.newpipe.extractor.channel.ChannelExtractor; @@ -12,21 +13,29 @@ import org.schabi.newpipe.extractor.exceptions.ParsingException; import org.schabi.newpipe.extractor.services.BaseChannelExtractorTest; import org.schabi.newpipe.extractor.services.youtube.extractors.YoutubeChannelExtractor; -import static org.junit.Assert.*; -import static org.schabi.newpipe.extractor.ExtractorAsserts.assertEmpty; +import java.io.IOException; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; import static org.schabi.newpipe.extractor.ExtractorAsserts.assertIsSecureUrl; import static org.schabi.newpipe.extractor.ServiceList.YouTube; -import static org.schabi.newpipe.extractor.services.DefaultTests.*; +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; /** * Test for {@link ChannelExtractor} */ public class YoutubeChannelExtractorTest { + private static final String RESOURCE_PATH = DownloaderFactory.RESOURCE_PATH + "services/youtube/extractor/channel/"; + public static class NotAvailable { @BeforeClass - public static void setUp() { - NewPipe.init(DownloaderTestImpl.getInstance()); + public static void setUp() throws IOException { + YoutubeParsingHelper.resetClientVersionAndKey(); + NewPipe.init(new DownloaderFactory().getDownloader(RESOURCE_PATH + "notAvailable")); } @Test(expected = ContentNotAvailableException.class) @@ -46,8 +55,9 @@ public class YoutubeChannelExtractorTest { public static class NotSupported { @BeforeClass - public static void setUp() { - NewPipe.init(DownloaderTestImpl.getInstance()); + public static void setUp() throws IOException { + YoutubeParsingHelper.resetClientVersionAndKey(); + NewPipe.init(new DownloaderFactory().getDownloader(RESOURCE_PATH + "notSupported")); } @Test(expected = ContentNotSupportedException.class) @@ -63,7 +73,8 @@ public class YoutubeChannelExtractorTest { @BeforeClass public static void setUp() throws Exception { - NewPipe.init(DownloaderTestImpl.getInstance()); + YoutubeParsingHelper.resetClientVersionAndKey(); + NewPipe.init(new DownloaderFactory().getDownloader(RESOURCE_PATH + "gronkh")); extractor = (YoutubeChannelExtractor) YouTube .getChannelExtractor("http://www.youtube.com/user/Gronkh"); extractor.fetchPage(); @@ -153,7 +164,8 @@ public class YoutubeChannelExtractorTest { @BeforeClass public static void setUp() throws Exception { - NewPipe.init(DownloaderTestImpl.getInstance()); + YoutubeParsingHelper.resetClientVersionAndKey(); + NewPipe.init(new DownloaderFactory().getDownloader(RESOURCE_PATH + "VSauce")); extractor = (YoutubeChannelExtractor) YouTube .getChannelExtractor("https://www.youtube.com/user/Vsauce"); extractor.fetchPage(); @@ -244,22 +256,13 @@ public class YoutubeChannelExtractorTest { @BeforeClass public static void setUp() throws Exception { - NewPipe.init(DownloaderTestImpl.getInstance()); + YoutubeParsingHelper.resetClientVersionAndKey(); + NewPipe.init(new DownloaderFactory().getDownloader(RESOURCE_PATH + "kurzgesagt")); extractor = (YoutubeChannelExtractor) YouTube .getChannelExtractor("https://www.youtube.com/channel/UCsXVk37bltHxD1rDPwtNM8Q"); extractor.fetchPage(); } - /*////////////////////////////////////////////////////////////////////////// - // Additional Testing - //////////////////////////////////////////////////////////////////////////*/ - - @Test - public void testGetPageInNewExtractor() throws Exception { - final ChannelExtractor newExtractor = YouTube.getChannelExtractor(extractor.getUrl()); - defaultTestGetPageInNewExtractor(extractor, newExtractor); - } - /*////////////////////////////////////////////////////////////////////////// // Extractor //////////////////////////////////////////////////////////////////////////*/ @@ -341,12 +344,33 @@ public class YoutubeChannelExtractorTest { } } + public static class KurzgesagtAdditional { + + private static YoutubeChannelExtractor extractor; + + @BeforeClass + public static void setUp() throws Exception { + // Test is not deterministic, mocks can't be used + NewPipe.init(DownloaderTestImpl.getInstance()); + extractor = (YoutubeChannelExtractor) YouTube + .getChannelExtractor("https://www.youtube.com/channel/UCsXVk37bltHxD1rDPwtNM8Q"); + extractor.fetchPage(); + } + + @Test + public void testGetPageInNewExtractor() throws Exception { + final ChannelExtractor newExtractor = YouTube.getChannelExtractor(extractor.getUrl()); + defaultTestGetPageInNewExtractor(extractor, newExtractor); + } + } + public static class CaptainDisillusion implements BaseChannelExtractorTest { private static YoutubeChannelExtractor extractor; @BeforeClass public static void setUp() throws Exception { - NewPipe.init(DownloaderTestImpl.getInstance()); + YoutubeParsingHelper.resetClientVersionAndKey(); + NewPipe.init(new DownloaderFactory().getDownloader(RESOURCE_PATH + "captainDisillusion")); extractor = (YoutubeChannelExtractor) YouTube .getChannelExtractor("https://www.youtube.com/user/CaptainDisillusion/videos"); extractor.fetchPage(); @@ -435,7 +459,8 @@ public class YoutubeChannelExtractorTest { @BeforeClass public static void setUp() throws Exception { - NewPipe.init(DownloaderTestImpl.getInstance()); + YoutubeParsingHelper.resetClientVersionAndKey(); + NewPipe.init(new DownloaderFactory().getDownloader(RESOURCE_PATH + "random")); extractor = (YoutubeChannelExtractor) YouTube .getChannelExtractor("https://www.youtube.com/channel/UCUaQMQS9lY5lit3vurpXQ6w"); extractor.fetchPage();