Fix Java 7 incompatibility

This commit is contained in:
Mauricio Colli 2018-03-04 18:22:27 -03:00
parent 29afd0c29c
commit 6c07b7851b
6 changed files with 92 additions and 91 deletions

View file

@ -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<? extends InfoItem> itemsList, List<Throwable> 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<? extends InfoItem, ?> itemsCollector = extractor.getInfoItems();
final List<? extends InfoItem> itemsList = itemsCollector.getItemList();
List<Throwable> errors = itemsCollector.getErrors();
defaultTestListOfItems(expectedServiceId, itemsList, errors);
}
static ListExtractor.InfoItemPage<? extends InfoItem> defaultTestMoreItems(ListExtractor extractor, int expectedServiceId) throws Exception {
assertTrue("Doesn't have more items", extractor.hasNextPage());
ListExtractor.InfoItemPage<? extends InfoItem> 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<? extends InfoItem> page = newExtractor.getPage(nextPageUrl);
BaseListExtractorTest.defaultTestListOfItems(expectedServiceId, page.getItemsList(), page.getErrors());
}
}

View file

@ -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<? extends InfoItem> itemsList, List<Throwable> 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<? extends InfoItem, ?> itemsCollector = extractor.getInfoItems();
final List<? extends InfoItem> itemsList = itemsCollector.getItemList();
List<Throwable> errors = itemsCollector.getErrors();
defaultTestListOfItems(expectedServiceId, itemsList, errors);
}
public static ListExtractor.InfoItemPage<? extends InfoItem> defaultTestMoreItems(ListExtractor extractor, int expectedServiceId) throws Exception {
assertTrue("Doesn't have more items", extractor.hasNextPage());
ListExtractor.InfoItemPage<? extends InfoItem> 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<? extends InfoItem> page = newExtractor.getPage(nextPageUrl);
defaultTestListOfItems(expectedServiceId, page.getItemsList(), page.getErrors());
}
}

View file

@ -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());
}
/*//////////////////////////////////////////////////////////////////////////

View file

@ -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<? extends InfoItem> currentPage = BaseListExtractorTest.defaultTestMoreItems(extractor, ServiceList.SoundCloud.getServiceId());
ListExtractor.InfoItemPage<? extends InfoItem> 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());
}
}

View file

@ -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;
}

View file

@ -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<? extends InfoItem> currentPage = BaseListExtractorTest.defaultTestMoreItems(extractor, ServiceList.YouTube.getServiceId());
ListExtractor.InfoItemPage<? extends InfoItem> 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());
}
}