diff --git a/src/test/java/org/schabi/newpipe/extractor/services/BaseListExtractorTest.java b/src/test/java/org/schabi/newpipe/extractor/services/BaseListExtractorTest.java index 55a4b416e..fd119ac20 100644 --- a/src/test/java/org/schabi/newpipe/extractor/services/BaseListExtractorTest.java +++ b/src/test/java/org/schabi/newpipe/extractor/services/BaseListExtractorTest.java @@ -1,65 +1,7 @@ package org.schabi.newpipe.extractor.services; -import org.schabi.newpipe.extractor.InfoItem; -import org.schabi.newpipe.extractor.InfoItemsCollector; -import org.schabi.newpipe.extractor.ListExtractor; -import org.schabi.newpipe.extractor.stream.StreamInfoItem; - -import java.util.List; - -import static org.junit.Assert.*; -import static org.schabi.newpipe.extractor.ExtractorAsserts.*; - +@SuppressWarnings("unused") public interface BaseListExtractorTest extends BaseExtractorTest { - @SuppressWarnings("unused") void testRelatedItems() throws Exception; - @SuppressWarnings("unused") void testMoreRelatedItems() throws Exception; - - - static void defaultTestListOfItems(int expectedServiceId, List itemsList, List errors) { - assertTrue("List of items is empty", !itemsList.isEmpty()); - assertFalse("List of items contains a null element", itemsList.contains(null)); - assertEmptyErrors("Errors during stream list extraction", errors); - - for (InfoItem item : itemsList) { - assertIsSecureUrl(item.getUrl()); - if (item.getThumbnailUrl() != null && !item.getThumbnailUrl().isEmpty()) { - assertIsSecureUrl(item.getThumbnailUrl()); - } - assertNotNull("InfoItem type not set: " + item, item.getInfoType()); - assertEquals("Service id doesn't match: " + item, expectedServiceId, item.getServiceId()); - - if (item instanceof StreamInfoItem) { - StreamInfoItem streamInfoItem = (StreamInfoItem) item; - assertNotEmpty("Uploader name not set: " + item, streamInfoItem.getUploaderName()); - assertNotEmpty("Uploader url not set: " + item, streamInfoItem.getUploaderUrl()); - } - } - } - - static void defaultTestRelatedItems(ListExtractor extractor, int expectedServiceId) throws Exception { - final InfoItemsCollector itemsCollector = extractor.getInfoItems(); - final List itemsList = itemsCollector.getItemList(); - List errors = itemsCollector.getErrors(); - - defaultTestListOfItems(expectedServiceId, itemsList, errors); - } - - static ListExtractor.InfoItemPage defaultTestMoreItems(ListExtractor extractor, int expectedServiceId) throws Exception { - assertTrue("Doesn't have more items", extractor.hasNextPage()); - ListExtractor.InfoItemPage nextPage = extractor.getPage(extractor.getNextPageUrl()); - assertTrue("Next page is empty", !nextPage.getItemsList().isEmpty()); - assertEmptyErrors("Next page have errors", nextPage.getErrors()); - - defaultTestListOfItems(expectedServiceId, nextPage.getItemsList(), nextPage.getErrors()); - return nextPage; - } - - static void defaultTestGetPageInNewExtractor(ListExtractor extractor, ListExtractor newExtractor, int expectedServiceId) throws Exception { - final String nextPageUrl = extractor.getNextPageUrl(); - - final ListExtractor.InfoItemPage page = newExtractor.getPage(nextPageUrl); - BaseListExtractorTest.defaultTestListOfItems(expectedServiceId, page.getItemsList(), page.getErrors()); - } } diff --git a/src/test/java/org/schabi/newpipe/extractor/services/DefaultTests.java b/src/test/java/org/schabi/newpipe/extractor/services/DefaultTests.java new file mode 100644 index 000000000..18fea5432 --- /dev/null +++ b/src/test/java/org/schabi/newpipe/extractor/services/DefaultTests.java @@ -0,0 +1,59 @@ +package org.schabi.newpipe.extractor.services; + +import org.schabi.newpipe.extractor.InfoItem; +import org.schabi.newpipe.extractor.InfoItemsCollector; +import org.schabi.newpipe.extractor.ListExtractor; +import org.schabi.newpipe.extractor.stream.StreamInfoItem; + +import java.util.List; + +import static org.junit.Assert.*; +import static org.schabi.newpipe.extractor.ExtractorAsserts.*; + +public final class DefaultTests { + public static void defaultTestListOfItems(int expectedServiceId, List itemsList, List errors) { + assertTrue("List of items is empty", !itemsList.isEmpty()); + assertFalse("List of items contains a null element", itemsList.contains(null)); + assertEmptyErrors("Errors during stream list extraction", errors); + + for (InfoItem item : itemsList) { + assertIsSecureUrl(item.getUrl()); + if (item.getThumbnailUrl() != null && !item.getThumbnailUrl().isEmpty()) { + assertIsSecureUrl(item.getThumbnailUrl()); + } + assertNotNull("InfoItem type not set: " + item, item.getInfoType()); + assertEquals("Service id doesn't match: " + item, expectedServiceId, item.getServiceId()); + + if (item instanceof StreamInfoItem) { + StreamInfoItem streamInfoItem = (StreamInfoItem) item; + assertNotEmpty("Uploader name not set: " + item, streamInfoItem.getUploaderName()); + assertNotEmpty("Uploader url not set: " + item, streamInfoItem.getUploaderUrl()); + } + } + } + + public static void defaultTestRelatedItems(ListExtractor extractor, int expectedServiceId) throws Exception { + final InfoItemsCollector itemsCollector = extractor.getInfoItems(); + final List itemsList = itemsCollector.getItemList(); + List errors = itemsCollector.getErrors(); + + defaultTestListOfItems(expectedServiceId, itemsList, errors); + } + + public static ListExtractor.InfoItemPage defaultTestMoreItems(ListExtractor extractor, int expectedServiceId) throws Exception { + assertTrue("Doesn't have more items", extractor.hasNextPage()); + ListExtractor.InfoItemPage nextPage = extractor.getPage(extractor.getNextPageUrl()); + assertTrue("Next page is empty", !nextPage.getItemsList().isEmpty()); + assertEmptyErrors("Next page have errors", nextPage.getErrors()); + + defaultTestListOfItems(expectedServiceId, nextPage.getItemsList(), nextPage.getErrors()); + return nextPage; + } + + public static void defaultTestGetPageInNewExtractor(ListExtractor extractor, ListExtractor newExtractor, int expectedServiceId) throws Exception { + final String nextPageUrl = extractor.getNextPageUrl(); + + final ListExtractor.InfoItemPage page = newExtractor.getPage(nextPageUrl); + defaultTestListOfItems(expectedServiceId, page.getItemsList(), page.getErrors()); + } +} diff --git a/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudChannelExtractorTest.java b/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudChannelExtractorTest.java index fcd51c124..5a8766076 100644 --- a/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudChannelExtractorTest.java +++ b/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudChannelExtractorTest.java @@ -8,12 +8,12 @@ import org.schabi.newpipe.Downloader; import org.schabi.newpipe.extractor.NewPipe; import org.schabi.newpipe.extractor.channel.ChannelExtractor; import org.schabi.newpipe.extractor.services.BaseChannelExtractorTest; -import org.schabi.newpipe.extractor.services.BaseListExtractorTest; import static org.junit.Assert.*; import static org.schabi.newpipe.extractor.ExtractorAsserts.assertEmpty; import static org.schabi.newpipe.extractor.ExtractorAsserts.assertIsSecureUrl; import static org.schabi.newpipe.extractor.ServiceList.SoundCloud; +import static org.schabi.newpipe.extractor.services.DefaultTests.*; /** * Test for {@link SoundcloudChannelExtractor} @@ -66,12 +66,12 @@ public class SoundcloudChannelExtractorTest { @Test public void testRelatedItems() throws Exception { - BaseListExtractorTest.defaultTestRelatedItems(extractor, SoundCloud.getServiceId()); + defaultTestRelatedItems(extractor, SoundCloud.getServiceId()); } @Test public void testMoreRelatedItems() throws Exception { - BaseListExtractorTest.defaultTestMoreItems(extractor, SoundCloud.getServiceId()); + defaultTestMoreItems(extractor, SoundCloud.getServiceId()); } /*////////////////////////////////////////////////////////////////////////// @@ -122,7 +122,7 @@ public class SoundcloudChannelExtractorTest { @Test public void testGetPageInNewExtractor() throws Exception { final ChannelExtractor newExtractor = SoundCloud.getChannelExtractor(extractor.getCleanUrl()); - BaseListExtractorTest.defaultTestGetPageInNewExtractor(extractor, newExtractor, SoundCloud.getServiceId()); + defaultTestGetPageInNewExtractor(extractor, newExtractor, SoundCloud.getServiceId()); } /*////////////////////////////////////////////////////////////////////////// @@ -160,12 +160,12 @@ public class SoundcloudChannelExtractorTest { @Test public void testRelatedItems() throws Exception { - BaseListExtractorTest.defaultTestRelatedItems(extractor, SoundCloud.getServiceId()); + defaultTestRelatedItems(extractor, SoundCloud.getServiceId()); } @Test public void testMoreRelatedItems() throws Exception { - BaseListExtractorTest.defaultTestMoreItems(extractor, SoundCloud.getServiceId()); + defaultTestMoreItems(extractor, SoundCloud.getServiceId()); } /*////////////////////////////////////////////////////////////////////////// diff --git a/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudPlaylistExtractorTest.java b/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudPlaylistExtractorTest.java index ebc2f4e8d..2a396f963 100644 --- a/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudPlaylistExtractorTest.java +++ b/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudPlaylistExtractorTest.java @@ -11,12 +11,12 @@ import org.schabi.newpipe.extractor.ListExtractor; import org.schabi.newpipe.extractor.NewPipe; import org.schabi.newpipe.extractor.ServiceList; import org.schabi.newpipe.extractor.playlist.PlaylistExtractor; -import org.schabi.newpipe.extractor.services.BaseListExtractorTest; import org.schabi.newpipe.extractor.services.BasePlaylistExtractorTest; import static org.junit.Assert.*; import static org.schabi.newpipe.extractor.ExtractorAsserts.assertIsSecureUrl; import static org.schabi.newpipe.extractor.ServiceList.SoundCloud; +import static org.schabi.newpipe.extractor.services.DefaultTests.*; /** * Test for {@link PlaylistExtractor} @@ -69,13 +69,13 @@ public class SoundcloudPlaylistExtractorTest { @Test public void testRelatedItems() throws Exception { - BaseListExtractorTest.defaultTestRelatedItems(extractor, SoundCloud.getServiceId()); + defaultTestRelatedItems(extractor, SoundCloud.getServiceId()); } @Test public void testMoreRelatedItems() { try { - BaseListExtractorTest.defaultTestMoreItems(extractor, SoundCloud.getServiceId()); + defaultTestMoreItems(extractor, SoundCloud.getServiceId()); } catch (Throwable ignored) { return; } @@ -167,12 +167,12 @@ public class SoundcloudPlaylistExtractorTest { @Test public void testRelatedItems() throws Exception { - BaseListExtractorTest.defaultTestRelatedItems(extractor, SoundCloud.getServiceId()); + defaultTestRelatedItems(extractor, SoundCloud.getServiceId()); } @Test public void testMoreRelatedItems() throws Exception { - BaseListExtractorTest.defaultTestMoreItems(extractor, SoundCloud.getServiceId()); + defaultTestMoreItems(extractor, SoundCloud.getServiceId()); } /*////////////////////////////////////////////////////////////////////////// @@ -231,7 +231,7 @@ public class SoundcloudPlaylistExtractorTest { @Test public void testGetPageInNewExtractor() throws Exception { final PlaylistExtractor newExtractor = SoundCloud.getPlaylistExtractor(extractor.getCleanUrl()); - BaseListExtractorTest.defaultTestGetPageInNewExtractor(extractor, newExtractor, SoundCloud.getServiceId()); + defaultTestGetPageInNewExtractor(extractor, newExtractor, SoundCloud.getServiceId()); } /*////////////////////////////////////////////////////////////////////////// @@ -269,16 +269,16 @@ public class SoundcloudPlaylistExtractorTest { @Test public void testRelatedItems() throws Exception { - BaseListExtractorTest.defaultTestRelatedItems(extractor, SoundCloud.getServiceId()); + defaultTestRelatedItems(extractor, SoundCloud.getServiceId()); } @Test public void testMoreRelatedItems() throws Exception { - ListExtractor.InfoItemPage currentPage = BaseListExtractorTest.defaultTestMoreItems(extractor, ServiceList.SoundCloud.getServiceId()); + ListExtractor.InfoItemPage currentPage = defaultTestMoreItems(extractor, ServiceList.SoundCloud.getServiceId()); // Test for 2 more levels for (int i = 0; i < 2; i++) { currentPage = extractor.getPage(currentPage.getNextPageUrl()); - BaseListExtractorTest.defaultTestListOfItems(SoundCloud.getServiceId(), currentPage.getItemsList(), currentPage.getErrors()); + defaultTestListOfItems(SoundCloud.getServiceId(), currentPage.getItemsList(), currentPage.getErrors()); } } diff --git a/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeChannelExtractorTest.java b/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeChannelExtractorTest.java index 7c07511ee..696aec07c 100644 --- a/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeChannelExtractorTest.java +++ b/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeChannelExtractorTest.java @@ -9,11 +9,11 @@ import org.schabi.newpipe.extractor.NewPipe; import org.schabi.newpipe.extractor.ServiceList; import org.schabi.newpipe.extractor.channel.ChannelExtractor; import org.schabi.newpipe.extractor.services.BaseChannelExtractorTest; -import org.schabi.newpipe.extractor.services.BaseListExtractorTest; import static org.junit.Assert.*; 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} @@ -66,12 +66,12 @@ public class YoutubeChannelExtractorTest { @Test public void testRelatedItems() throws Exception { - BaseListExtractorTest.defaultTestRelatedItems(extractor, YouTube.getServiceId()); + defaultTestRelatedItems(extractor, YouTube.getServiceId()); } @Test public void testMoreRelatedItems() throws Exception { - BaseListExtractorTest.defaultTestMoreItems(extractor, ServiceList.YouTube.getServiceId()); + defaultTestMoreItems(extractor, ServiceList.YouTube.getServiceId()); } /*////////////////////////////////////////////////////////////////////////// @@ -126,7 +126,7 @@ public class YoutubeChannelExtractorTest { @Test public void testGetPageInNewExtractor() throws Exception { final ChannelExtractor newExtractor = YouTube.getChannelExtractor(extractor.getCleanUrl()); - BaseListExtractorTest.defaultTestGetPageInNewExtractor(extractor, newExtractor, YouTube.getServiceId()); + defaultTestGetPageInNewExtractor(extractor, newExtractor, YouTube.getServiceId()); } /*////////////////////////////////////////////////////////////////////////// @@ -165,12 +165,12 @@ public class YoutubeChannelExtractorTest { @Test public void testRelatedItems() throws Exception { - BaseListExtractorTest.defaultTestRelatedItems(extractor, YouTube.getServiceId()); + defaultTestRelatedItems(extractor, YouTube.getServiceId()); } @Test public void testMoreRelatedItems() throws Exception { - BaseListExtractorTest.defaultTestMoreItems(extractor, ServiceList.YouTube.getServiceId()); + defaultTestMoreItems(extractor, ServiceList.YouTube.getServiceId()); } /*////////////////////////////////////////////////////////////////////////// @@ -256,12 +256,12 @@ public class YoutubeChannelExtractorTest { @Test public void testRelatedItems() throws Exception { - BaseListExtractorTest.defaultTestRelatedItems(extractor, YouTube.getServiceId()); + defaultTestRelatedItems(extractor, YouTube.getServiceId()); } @Test public void testMoreRelatedItems() throws Exception { - BaseListExtractorTest.defaultTestMoreItems(extractor, ServiceList.YouTube.getServiceId()); + defaultTestMoreItems(extractor, ServiceList.YouTube.getServiceId()); } /*////////////////////////////////////////////////////////////////////////// @@ -345,13 +345,13 @@ public class YoutubeChannelExtractorTest { @Test public void testRelatedItems() throws Exception { - BaseListExtractorTest.defaultTestRelatedItems(extractor, YouTube.getServiceId()); + defaultTestRelatedItems(extractor, YouTube.getServiceId()); } @Test public void testMoreRelatedItems() { try { - BaseListExtractorTest.defaultTestMoreItems(extractor, YouTube.getServiceId()); + defaultTestMoreItems(extractor, YouTube.getServiceId()); } catch (Throwable ignored) { return; } diff --git a/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubePlaylistExtractorTest.java b/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubePlaylistExtractorTest.java index 2f62e572c..874526223 100644 --- a/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubePlaylistExtractorTest.java +++ b/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubePlaylistExtractorTest.java @@ -10,13 +10,13 @@ import org.schabi.newpipe.extractor.ListExtractor; import org.schabi.newpipe.extractor.NewPipe; import org.schabi.newpipe.extractor.ServiceList; import org.schabi.newpipe.extractor.playlist.PlaylistExtractor; -import org.schabi.newpipe.extractor.services.BaseListExtractorTest; import org.schabi.newpipe.extractor.services.BasePlaylistExtractorTest; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; 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 YoutubePlaylistExtractor} @@ -70,12 +70,12 @@ public class YoutubePlaylistExtractorTest { @Test public void testRelatedItems() throws Exception { - BaseListExtractorTest.defaultTestRelatedItems(extractor, YouTube.getServiceId()); + defaultTestRelatedItems(extractor, YouTube.getServiceId()); } @Test public void testMoreRelatedItems() throws Exception { - BaseListExtractorTest.defaultTestMoreItems(extractor, ServiceList.YouTube.getServiceId()); + defaultTestMoreItems(extractor, ServiceList.YouTube.getServiceId()); } /*////////////////////////////////////////////////////////////////////////// @@ -137,7 +137,7 @@ public class YoutubePlaylistExtractorTest { @Test public void testGetPageInNewExtractor() throws Exception { final PlaylistExtractor newExtractor = YouTube.getPlaylistExtractor(extractor.getCleanUrl()); - BaseListExtractorTest.defaultTestGetPageInNewExtractor(extractor, newExtractor, YouTube.getServiceId()); + defaultTestGetPageInNewExtractor(extractor, newExtractor, YouTube.getServiceId()); } /*////////////////////////////////////////////////////////////////////////// @@ -176,16 +176,16 @@ public class YoutubePlaylistExtractorTest { @Test public void testRelatedItems() throws Exception { - BaseListExtractorTest.defaultTestRelatedItems(extractor, YouTube.getServiceId()); + defaultTestRelatedItems(extractor, YouTube.getServiceId()); } @Test public void testMoreRelatedItems() throws Exception { - ListExtractor.InfoItemPage currentPage = BaseListExtractorTest.defaultTestMoreItems(extractor, ServiceList.YouTube.getServiceId()); + ListExtractor.InfoItemPage currentPage = defaultTestMoreItems(extractor, ServiceList.YouTube.getServiceId()); // Test for 2 more levels for (int i = 0; i < 2; i++) { currentPage = extractor.getPage(currentPage.getNextPageUrl()); - BaseListExtractorTest.defaultTestListOfItems(YouTube.getServiceId(), currentPage.getItemsList(), currentPage.getErrors()); + defaultTestListOfItems(YouTube.getServiceId(), currentPage.getItemsList(), currentPage.getErrors()); } }