From fcee247f9f75ef7a8abd100532b08781cbd92989 Mon Sep 17 00:00:00 2001 From: litetex <40789489+litetex@users.noreply.github.com> Date: Sun, 20 Mar 2022 20:55:04 +0100 Subject: [PATCH] Switched to mockonly tests * Made the reason why the tests are mockonly mandatory --- .../schabi/newpipe/downloader/MockOnly.java | 5 +++ .../YoutubeMusicSearchExtractorTest.java | 9 +++--- .../search/YoutubeSearchExtractorTest.java | 31 ++++++++++++------- .../YoutubeStreamExtractorRelatedMixTest.java | 2 +- 4 files changed, 31 insertions(+), 16 deletions(-) diff --git a/extractor/src/test/java/org/schabi/newpipe/downloader/MockOnly.java b/extractor/src/test/java/org/schabi/newpipe/downloader/MockOnly.java index d6ca17124..84bc16435 100644 --- a/extractor/src/test/java/org/schabi/newpipe/downloader/MockOnly.java +++ b/extractor/src/test/java/org/schabi/newpipe/downloader/MockOnly.java @@ -17,4 +17,9 @@ import java.lang.annotation.RetentionPolicy; @Retention(RetentionPolicy.RUNTIME) @ExtendWith(MockOnlyCondition.class) public @interface MockOnly { + + /** + * The reason why the test is mockonly. + */ + String value(); } diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/search/YoutubeMusicSearchExtractorTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/search/YoutubeMusicSearchExtractorTest.java index 62b6815c5..1ab8a0431 100644 --- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/search/YoutubeMusicSearchExtractorTest.java +++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/search/YoutubeMusicSearchExtractorTest.java @@ -1,8 +1,12 @@ package org.schabi.newpipe.extractor.services.youtube.search; +import static org.schabi.newpipe.extractor.ServiceList.YouTube; +import static java.util.Collections.singletonList; + import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Disabled; import org.schabi.newpipe.downloader.DownloaderTestImpl; +import org.schabi.newpipe.downloader.MockOnly; import org.schabi.newpipe.extractor.InfoItem; import org.schabi.newpipe.extractor.NewPipe; import org.schabi.newpipe.extractor.StreamingService; @@ -14,9 +18,6 @@ import java.net.URLEncoder; import javax.annotation.Nullable; -import static java.util.Collections.singletonList; -import static org.schabi.newpipe.extractor.ServiceList.YouTube; - // Doesn't work with mocks. Makes request with different `dataToSend` I think public class YoutubeMusicSearchExtractorTest { public static class MusicSongs extends DefaultSearchExtractorTest { @@ -130,7 +131,7 @@ public class YoutubeMusicSearchExtractorTest { @Override public InfoItem.InfoType expectedInfoItemType() { return InfoItem.InfoType.CHANNEL; } } - @Disabled("Currently constantly switching between \"Did you mean\" and \"Showing results for ...\" occurs") + @MockOnly("Currently constantly switching between \"Did you mean\" and \"Showing results for ...\" occurs") public static class Suggestion extends DefaultSearchExtractorTest { private static SearchExtractor extractor; private static final String QUERY = "megaman x3"; 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 069baa7ca..57a9ccb5e 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 @@ -1,10 +1,26 @@ package org.schabi.newpipe.extractor.services.youtube.search; +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.ExtractorAsserts.assertEmptyErrors; +import static org.schabi.newpipe.extractor.ServiceList.YouTube; +import static org.schabi.newpipe.extractor.services.DefaultTests.assertNoDuplicatedItems; +import static org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubeSearchQueryHandlerFactory.CHANNELS; +import static org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubeSearchQueryHandlerFactory.PLAYLISTS; +import static org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubeSearchQueryHandlerFactory.VIDEOS; +import static java.util.Collections.singletonList; + import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import org.schabi.newpipe.downloader.DownloaderFactory; -import org.schabi.newpipe.extractor.*; +import org.schabi.newpipe.downloader.MockOnly; +import org.schabi.newpipe.extractor.InfoItem; +import org.schabi.newpipe.extractor.ListExtractor; +import org.schabi.newpipe.extractor.MetaInfo; +import org.schabi.newpipe.extractor.NewPipe; +import org.schabi.newpipe.extractor.StreamingService; import org.schabi.newpipe.extractor.channel.ChannelInfoItem; import org.schabi.newpipe.extractor.exceptions.ExtractionException; import org.schabi.newpipe.extractor.search.SearchExtractor; @@ -13,7 +29,6 @@ import org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper; import org.schabi.newpipe.extractor.stream.Description; import org.schabi.newpipe.extractor.stream.StreamInfoItem; -import javax.annotation.Nullable; import java.io.IOException; import java.net.MalformedURLException; import java.net.URL; @@ -22,13 +37,7 @@ import java.util.Collections; import java.util.List; import java.util.Random; -import static java.util.Collections.singletonList; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.*; -import static org.schabi.newpipe.extractor.ExtractorAsserts.assertEmptyErrors; -import static org.schabi.newpipe.extractor.ServiceList.YouTube; -import static org.schabi.newpipe.extractor.services.DefaultTests.assertNoDuplicatedItems; -import static org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubeSearchQueryHandlerFactory.*; +import javax.annotation.Nullable; public class YoutubeSearchExtractorTest { @@ -132,7 +141,7 @@ public class YoutubeSearchExtractorTest { @Override public InfoItem.InfoType expectedInfoItemType() { return InfoItem.InfoType.STREAM; } } - @Disabled("Currently constantly switching between \"Did you mean\" and \"Showing results for ...\" occurs") + @MockOnly("Currently constantly switching between \"Did you mean\" and \"Showing results for ...\" occurs") public static class Suggestion extends DefaultSearchExtractorTest { private static SearchExtractor extractor; private static final String QUERY = "newpip"; 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 48c2d2243..916375ae5 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 @@ -88,7 +88,7 @@ public class YoutubeStreamExtractorRelatedMixTest extends DefaultStreamExtractor // @formatter:on @Test - @MockOnly // related items keep changing, and so do the mixes contained within them + @MockOnly("related items keep changing, and so do the mixes contained within them") @Override public void testRelatedItems() throws Exception { super.testRelatedItems();