diff --git a/extractor/src/test/java/org/schabi/newpipe/downloader/DownloaderFactory.java b/extractor/src/test/java/org/schabi/newpipe/downloader/DownloaderFactory.java index ee207c412..0fbbe242c 100644 --- a/extractor/src/test/java/org/schabi/newpipe/downloader/DownloaderFactory.java +++ b/extractor/src/test/java/org/schabi/newpipe/downloader/DownloaderFactory.java @@ -36,7 +36,7 @@ public class DownloaderFactory { * @param path The path to the folder where mocks are saved/retrieved. * Preferably starting with {@link DownloaderFactory#RESOURCE_PATH} */ - public static Downloader getDownloader(final String path) throws IOException { + public static Downloader getDownloader(final String path) { final DownloaderType type = getDownloaderType(); switch (type) { case REAL: diff --git a/extractor/src/test/java/org/schabi/newpipe/downloader/MockDownloader.java b/extractor/src/test/java/org/schabi/newpipe/downloader/MockDownloader.java index bcf72b213..d24cd8631 100644 --- a/extractor/src/test/java/org/schabi/newpipe/downloader/MockDownloader.java +++ b/extractor/src/test/java/org/schabi/newpipe/downloader/MockDownloader.java @@ -10,6 +10,7 @@ import java.io.File; import java.io.FileInputStream; import java.io.InputStreamReader; import java.io.IOException; +import java.io.UncheckedIOException; import java.nio.charset.StandardCharsets; import java.util.HashMap; import java.util.Map; @@ -26,19 +27,22 @@ class MockDownloader extends Downloader { private final String path; private final Map mocks; - public MockDownloader(@Nonnull final String path) throws IOException { + public MockDownloader(@Nonnull final String path) { this.path = path; this.mocks = new HashMap<>(); final File[] files = new File(path).listFiles(); if (files != null) { for (final File file : files) { if (file.getName().startsWith(RecordingDownloader.FILE_NAME_PREFIX)) { - final InputStreamReader reader = new InputStreamReader(new FileInputStream( - file), StandardCharsets.UTF_8); - final TestRequestResponse response = new GsonBuilder() - .create() - .fromJson(reader, TestRequestResponse.class); - reader.close(); + final TestRequestResponse response; + try(final InputStreamReader reader = new InputStreamReader( + new FileInputStream(file), StandardCharsets.UTF_8)) { + response = new GsonBuilder() + .create() + .fromJson(reader, TestRequestResponse.class); + } catch (IOException e) { + throw new UncheckedIOException(e); + } mocks.put(response.getRequest(), response.getResponse()); } } diff --git a/extractor/src/test/java/org/schabi/newpipe/downloader/RecordingDownloader.java b/extractor/src/test/java/org/schabi/newpipe/downloader/RecordingDownloader.java index f5b2cf533..bd91257b6 100644 --- a/extractor/src/test/java/org/schabi/newpipe/downloader/RecordingDownloader.java +++ b/extractor/src/test/java/org/schabi/newpipe/downloader/RecordingDownloader.java @@ -11,6 +11,7 @@ import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStreamWriter; +import java.io.UncheckedIOException; import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; @@ -51,7 +52,7 @@ class RecordingDownloader extends Downloader { * Deletes existing files starting with {@link RecordingDownloader#FILE_NAME_PREFIX}. * @param stringPath Path to the folder where the json files will be saved to. */ - public RecordingDownloader(final String stringPath) throws IOException { + public RecordingDownloader(final String stringPath) { this.path = stringPath; final Path path = Paths.get(stringPath); final File folder = path.toFile(); @@ -62,7 +63,11 @@ class RecordingDownloader extends Downloader { } } } else { - Files.createDirectories(path); + try { + Files.createDirectories(path); + } catch (IOException e) { + throw new UncheckedIOException(e); + } } } 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 e205a61a8..e8dbee17c 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 @@ -41,13 +41,13 @@ public class YoutubeChannelExtractorTest { public static class NotAvailable { @BeforeAll - public static void setUp() throws IOException { + public static void setUp() { YoutubeTestsUtils.ensureStateless(); NewPipe.init(DownloaderFactory.getDownloader(RESOURCE_PATH + "notAvailable")); } @Test - public void deletedFetch() throws Exception { + void deletedFetch() throws Exception { final ChannelExtractor extractor = YouTube.getChannelExtractor("https://www.youtube.com/channel/UCAUc4iz6edWerIjlnL8OSSw"); @@ -55,7 +55,7 @@ public class YoutubeChannelExtractorTest { } @Test - public void nonExistentFetch() throws Exception { + void nonExistentFetch() throws Exception { final ChannelExtractor extractor = YouTube.getChannelExtractor("https://www.youtube.com/channel/DOESNT-EXIST"); @@ -63,7 +63,7 @@ public class YoutubeChannelExtractorTest { } @Test - public void accountTerminatedTOSFetch() throws Exception { + void accountTerminatedTOSFetch() throws Exception { // "This account has been terminated for a violation of YouTube's Terms of Service." final ChannelExtractor extractor = YouTube.getChannelExtractor("https://www.youtube.com/channel/UCTGjY2I-ZUGnwVoWAGRd7XQ"); @@ -74,7 +74,7 @@ public class YoutubeChannelExtractorTest { } @Test - public void accountTerminatedCommunityFetch() throws Exception { + void accountTerminatedCommunityFetch() throws Exception { // "This account has been terminated for violating YouTube's Community Guidelines." final ChannelExtractor extractor = YouTube.getChannelExtractor("https://www.youtube.com/channel/UC0AuOxCr9TZ0TtEgL1zpIgA"); @@ -85,7 +85,7 @@ public class YoutubeChannelExtractorTest { } @Test - public void accountTerminatedHateFetch() throws Exception { + void accountTerminatedHateFetch() throws Exception { // "This account has been terminated due to multiple or severe violations // of YouTube's policy prohibiting hate speech." final ChannelExtractor extractor = @@ -97,7 +97,7 @@ public class YoutubeChannelExtractorTest { } @Test - public void accountTerminatedBullyFetch() throws Exception { + void accountTerminatedBullyFetch() throws Exception { // "This account has been terminated due to multiple or severe violations // of YouTube's policy prohibiting content designed to harass, bully or threaten." final ChannelExtractor extractor = @@ -109,7 +109,7 @@ public class YoutubeChannelExtractorTest { } @Test - public void accountTerminatedSpamFetch() throws Exception { + void accountTerminatedSpamFetch() throws Exception { // "This account has been terminated due to multiple or severe violations // of YouTube's policy against spam, deceptive practices and misleading content // or other Terms of Service violations." @@ -122,7 +122,7 @@ public class YoutubeChannelExtractorTest { } @Test - public void accountTerminatedCopyrightFetch() throws Exception { + void accountTerminatedCopyrightFetch() throws Exception { // "This account has been terminated because we received multiple third-party claims // of copyright infringement regarding material that the user posted." final ChannelExtractor extractor = @@ -137,7 +137,7 @@ public class YoutubeChannelExtractorTest { static class SystemTopic { @BeforeAll - static void setUp() throws IOException { + static void setUp() { YoutubeTestsUtils.ensureStateless(); NewPipe.init(DownloaderFactory.getDownloader(RESOURCE_PATH + "systemTopic")); } 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 4169b0cdf..f433f6528 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 @@ -81,7 +81,8 @@ public class YoutubeFeedExtractorTest { public static class NotAvailable { @BeforeAll - public static void setUp() throws IOException { + public static void setUp() { + YoutubeTestsUtils.ensureStateless(); NewPipe.init(DownloaderFactory.getDownloader(RESOURCE_PATH + "notAvailable/")); } 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 e58c8731c..ccaf41416 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 @@ -310,7 +310,7 @@ public class YoutubeMixPlaylistExtractorTest { private static final String VIDEO_ID = "QMVCAPd5cwBcg"; @BeforeAll - public static void setUp() throws IOException { + public static void setUp() { YoutubeTestsUtils.ensureStateless(); YoutubeParsingHelper.setConsentAccepted(true); NewPipe.init(DownloaderFactory.getDownloader(RESOURCE_PATH + "invalid")); 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 dc7733344..e47b9ee07 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 @@ -19,7 +19,7 @@ public class YoutubeParsingHelperTest { private static final String RESOURCE_PATH = DownloaderFactory.RESOURCE_PATH + "services/youtube/"; @BeforeAll - public static void setUp() throws IOException { + public static void setUp() { 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 a9ff46023..e568175d9 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 @@ -40,7 +40,7 @@ public class YoutubePlaylistExtractorTest { public static class NotAvailable { @BeforeAll - public static void setUp() throws IOException { + public static void setUp() { YoutubeTestsUtils.ensureStateless(); NewPipe.init(DownloaderFactory.getDownloader(RESOURCE_PATH + "notAvailable")); } @@ -549,7 +549,7 @@ public class YoutubePlaylistExtractorTest { public static class ContinuationsTests { @BeforeAll - public static void setUp() throws IOException { + public static void setUp() { YoutubeTestsUtils.ensureStateless(); NewPipe.init(DownloaderFactory.getDownloader(RESOURCE_PATH + "continuations")); } diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeSignaturesTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeSignaturesTest.java index 5edec3ecd..421cd438f 100644 --- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeSignaturesTest.java +++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeSignaturesTest.java @@ -19,7 +19,7 @@ class YoutubeSignaturesTest { DownloaderFactory.RESOURCE_PATH + "services/youtube/extractor/signatures"; @BeforeEach - void setUp() throws IOException { + void setUp() { YoutubeTestsUtils.ensureStateless(); NewPipe.init(DownloaderFactory.getDownloader(RESOURCE_PATH)); } 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 67eb1a6fe..38fac562d 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 @@ -28,14 +28,13 @@ 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.kiosk.KioskInfo; import org.schabi.newpipe.extractor.linkhandler.LinkHandlerFactory; /** * Test for {@link KioskInfo} */ -public class YoutubeTrendingKioskInfoTest { +class YoutubeTrendingKioskInfoTest { private static final String RESOURCE_PATH = DownloaderFactory.RESOURCE_PATH + "kiosk"; @@ -46,24 +45,24 @@ public class YoutubeTrendingKioskInfoTest { throws Exception { YoutubeTestsUtils.ensureStateless(); NewPipe.init(DownloaderFactory.getDownloader(RESOURCE_PATH)); - LinkHandlerFactory LinkHandlerFactory = ((StreamingService) YouTube).getKioskList().getListLinkHandlerFactoryByType("Trending"); + LinkHandlerFactory linkHandlerFactory = YouTube.getKioskList().getListLinkHandlerFactoryByType("Trending"); - kioskInfo = KioskInfo.getInfo(YouTube, LinkHandlerFactory.fromId("Trending").getUrl()); + kioskInfo = KioskInfo.getInfo(YouTube, linkHandlerFactory.fromId("Trending").getUrl()); } @Test - public void getStreams() { + void getStreams() { assertFalse(kioskInfo.getRelatedItems().isEmpty()); } @Test - public void getId() { + void getId() { assertTrue(kioskInfo.getId().equals("Trending") || kioskInfo.getId().equals("Trends")); } @Test - public void getName() { + void getName() { assertFalse(kioskInfo.getName().isEmpty()); } }