package org.schabi.newpipe.extractor.services; import org.schabi.newpipe.extractor.InfoItem; 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 ListExtractor.InfoItemsPage defaultTestRelatedItems(ListExtractor extractor, int expectedServiceId) throws Exception { final ListExtractor.InfoItemsPage page = extractor.getInitialPage(); final List itemsList = page.getItems(); List errors = page.getErrors(); defaultTestListOfItems(expectedServiceId, itemsList, errors); return page; } public static ListExtractor.InfoItemsPage defaultTestMoreItems(ListExtractor extractor, int expectedServiceId) throws Exception { assertTrue("Doesn't have more items", extractor.hasNextPage()); ListExtractor.InfoItemsPage nextPage = extractor.getPage(extractor.getNextPageUrl()); final List items = nextPage.getItems(); assertTrue("Next page is empty", !items.isEmpty()); assertEmptyErrors("Next page have errors", nextPage.getErrors()); defaultTestListOfItems(expectedServiceId, nextPage.getItems(), nextPage.getErrors()); return nextPage; } public static void defaultTestGetPageInNewExtractor(ListExtractor extractor, ListExtractor newExtractor, int expectedServiceId) throws Exception { final String nextPageUrl = extractor.getNextPageUrl(); final ListExtractor.InfoItemsPage page = newExtractor.getPage(nextPageUrl); defaultTestListOfItems(expectedServiceId, page.getItems(), page.getErrors()); } }