Code cleanup / improvements

* Deprecated Utils#UTF-8; see StandardCharsets
* Added more helpful methods to ``ExtractorAsserts``
* Use parameterized (cool new) tests
* Restore functionality of some tests + updated mockdata
* Other code cleanups + Sonarlint improvements
This commit is contained in:
litetex 2022-01-04 17:28:31 +01:00
parent 4291a90251
commit 3712a669b1
24 changed files with 2048 additions and 314 deletions

View File

@ -13,6 +13,10 @@ public class Utils {
public static final String HTTP = "http://";
public static final String HTTPS = "https://";
/**
* @deprecated Use {@link java.nio.charset.StandardCharsets#UTF_8} instead
*/
@Deprecated
public static final String UTF_8 = "UTF-8";
public static final String EMPTY_STRING = "";
private static final Pattern M_PATTERN = Pattern.compile("(https?)?:\\/\\/m\\.");

View File

@ -64,8 +64,52 @@ public class ExtractorAsserts {
}
}
public static void assertAtLeast(long expected, long actual) {
assertTrue(actual >= expected, actual + " is not at least " + expected);
public static void assertGreater(final long expected, final long actual) {
assertGreater(expected, actual, actual + " is not > " + expected);
}
public static void assertGreater(
final long expected,
final long actual,
final String message
) {
assertTrue(actual > expected, message);
}
public static void assertGreaterOrEqual(final long expected, final long actual) {
assertGreaterOrEqual(expected, actual, actual + " is not >= " + expected);
}
public static void assertGreaterOrEqual(
final long expected,
final long actual,
final String message
) {
assertTrue(actual >= expected, message);
}
public static void assertLess(final long expected, final long actual) {
assertLess(expected, actual, actual + " is not < " + expected);
}
public static void assertLess(
final long expected,
final long actual,
final String message
) {
assertTrue(actual < expected, message);
}
public static void assertLessOrEqual(final long expected, final long actual) {
assertLessOrEqual(expected, actual, actual + " is not <= " + expected);
}
public static void assertLessOrEqual(
final long expected,
final long actual,
final String message
) {
assertTrue(actual <= expected, message);
}
// this assumes that sorting a and b in-place is not an issue, so it's only intended for tests

View File

@ -1,6 +1,5 @@
package org.schabi.newpipe.extractor.services;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.schabi.newpipe.extractor.ExtractorAsserts;
import org.schabi.newpipe.extractor.InfoItemsCollector;
@ -30,7 +29,7 @@ import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.schabi.newpipe.extractor.ExtractorAsserts.assertAtLeast;
import static org.schabi.newpipe.extractor.ExtractorAsserts.assertGreaterOrEqual;
import static org.schabi.newpipe.extractor.ExtractorAsserts.assertEqualsOrderIndependent;
import static org.schabi.newpipe.extractor.ExtractorAsserts.assertIsSecureUrl;
import static org.schabi.newpipe.extractor.ExtractorAsserts.assertIsValidUrl;
@ -174,7 +173,7 @@ public abstract class DefaultStreamExtractorTest extends DefaultExtractorTest<St
@Test
@Override
public void testViewCount() throws Exception {
assertAtLeast(expectedViewCountAtLeast(), extractor().getViewCount());
assertGreaterOrEqual(expectedViewCountAtLeast(), extractor().getViewCount());
}
@Test
@ -207,7 +206,7 @@ public abstract class DefaultStreamExtractorTest extends DefaultExtractorTest<St
if (expectedLikeCountAtLeast() == -1) {
assertEquals(-1, extractor().getLikeCount());
} else {
assertAtLeast(expectedLikeCountAtLeast(), extractor().getLikeCount());
assertGreaterOrEqual(expectedLikeCountAtLeast(), extractor().getLikeCount());
}
}
@ -217,7 +216,7 @@ public abstract class DefaultStreamExtractorTest extends DefaultExtractorTest<St
if (expectedDislikeCountAtLeast() == -1) {
assertEquals(-1, extractor().getDislikeCount());
} else {
assertAtLeast(expectedDislikeCountAtLeast(), extractor().getDislikeCount());
assertGreaterOrEqual(expectedDislikeCountAtLeast(), extractor().getDislikeCount());
}
}

View File

@ -2,13 +2,19 @@ package org.schabi.newpipe.extractor.services.media_ccc;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
import org.schabi.newpipe.downloader.DownloaderTestImpl;
import org.schabi.newpipe.extractor.ExtractorAsserts;
import org.schabi.newpipe.extractor.Info;
import org.schabi.newpipe.extractor.InfoItem;
import org.schabi.newpipe.extractor.NewPipe;
import org.schabi.newpipe.extractor.kiosk.KioskExtractor;
import org.schabi.newpipe.extractor.services.media_ccc.extractors.MediaCCCConferenceKiosk;
import org.schabi.newpipe.extractor.stream.StreamInfoItem;
import java.util.List;
import java.util.Objects;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.schabi.newpipe.extractor.ServiceList.MediaCCC;
@ -29,30 +35,25 @@ public class MediaCCCConferenceListExtractorTest {
}
@Test
public void getConferencesListTest() throws Exception {
assertTrue(extractor.getInitialPage().getItems().size() >= 174,
"returned list was to small");
void getConferencesListTest() throws Exception {
ExtractorAsserts.assertGreaterOrEqual(174, extractor.getInitialPage().getItems().size());
}
@Test
public void conferenceTypeTest() throws Exception {
assertTrue(contains(extractor.getInitialPage().getItems(), "FrOSCon 2016"));
assertTrue(contains(extractor.getInitialPage().getItems(), "ChaosWest @ 35c3"));
assertTrue(contains(extractor.getInitialPage().getItems(), "CTreffOS chaOStalks"));
assertTrue(contains(extractor.getInitialPage().getItems(), "Datenspuren 2015"));
assertTrue(contains(extractor.getInitialPage().getItems(), "Chaos Singularity 2017"));
assertTrue(contains(extractor.getInitialPage().getItems(), "SIGINT10"));
assertTrue(contains(extractor.getInitialPage().getItems(), "Vintage Computing Festival Berlin 2015"));
assertTrue(contains(extractor.getInitialPage().getItems(), "FIfFKon 2015"));
assertTrue(contains(extractor.getInitialPage().getItems(), "33C3: trailers"));
assertTrue(contains(extractor.getInitialPage().getItems(), "Blinkenlights"));
}
private boolean contains(List<InfoItem> itemList, String name) {
for (InfoItem item : itemList) {
if (item.getName().equals(name))
return true;
}
return false;
@ParameterizedTest
@ValueSource(strings = {
"FrOSCon 2016",
"ChaosWest @ 35c3",
"CTreffOS chaOStalks",
"Datenspuren 2015",
"Chaos Singularity 2017",
"SIGINT10",
"Vintage Computing Festival Berlin 2015",
"FIfFKon 2015",
"33C3: trailers",
"Blinkenlights"
})
void conferenceTypeTest(final String name) throws Exception {
final List<InfoItem> itemList = extractor.getInitialPage().getItems();
assertTrue(itemList.stream().anyMatch(item -> name.equals(item.getName())));
}
}

View File

@ -3,6 +3,7 @@ package org.schabi.newpipe.extractor.services.peertube;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.schabi.newpipe.downloader.DownloaderTestImpl;
import org.schabi.newpipe.extractor.ExtractorAsserts;
import org.schabi.newpipe.extractor.NewPipe;
import org.schabi.newpipe.extractor.channel.ChannelExtractor;
import org.schabi.newpipe.extractor.exceptions.ParsingException;
@ -101,7 +102,7 @@ public class PeertubeAccountExtractorTest {
@Test
public void testSubscriberCount() throws ParsingException {
assertTrue(extractor.getSubscriberCount() >= 700, "Wrong subscriber count");
ExtractorAsserts.assertGreaterOrEqual(700, extractor.getSubscriberCount());
}
@Override
@ -202,7 +203,7 @@ public class PeertubeAccountExtractorTest {
@Test
public void testSubscriberCount() throws ParsingException {
assertTrue(extractor.getSubscriberCount() >= 100, "Wrong subscriber count");
ExtractorAsserts.assertGreaterOrEqual(100, extractor.getSubscriberCount());
}
@Override

View File

@ -3,6 +3,7 @@ package org.schabi.newpipe.extractor.services.peertube;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.schabi.newpipe.downloader.DownloaderTestImpl;
import org.schabi.newpipe.extractor.ExtractorAsserts;
import org.schabi.newpipe.extractor.NewPipe;
import org.schabi.newpipe.extractor.channel.ChannelExtractor;
import org.schabi.newpipe.extractor.exceptions.ParsingException;
@ -116,7 +117,7 @@ public class PeertubeChannelExtractorTest {
@Test
public void testSubscriberCount() throws ParsingException {
assertTrue(extractor.getSubscriberCount() >= 230, "Wrong subscriber count");
ExtractorAsserts.assertGreaterOrEqual(230, extractor.getSubscriberCount());
}
@Override
@ -233,7 +234,7 @@ public class PeertubeChannelExtractorTest {
@Test
public void testSubscriberCount() throws ParsingException {
assertTrue(extractor.getSubscriberCount() >= 700, "Wrong subscriber count");
ExtractorAsserts.assertGreaterOrEqual(700, extractor.getSubscriberCount());
}
@Override

View File

@ -53,7 +53,7 @@ public class PeertubePlaylistExtractorTest {
@Test
public void testGetStreamCount() throws ParsingException {
ExtractorAsserts.assertAtLeast(39, extractor.getStreamCount());
ExtractorAsserts.assertGreaterOrEqual(39, extractor.getStreamCount());
}
@Test

View File

@ -91,7 +91,7 @@ public class SoundcloudPlaylistExtractorTest {
}
@Test
public void testUploaderUrl() {
void testUploaderUrl() {
final String uploaderUrl = extractor.getUploaderUrl();
assertIsSecureUrl(uploaderUrl);
ExtractorAsserts.assertContains("liluzivert", uploaderUrl);
@ -109,11 +109,10 @@ public class SoundcloudPlaylistExtractorTest {
@Test
public void testStreamCount() {
assertTrue(extractor.getStreamCount() >= 10,
"Stream count does not fit: " + extractor.getStreamCount());
ExtractorAsserts.assertGreaterOrEqual(10, extractor.getStreamCount());
}
@Override
@Test
public void testUploaderVerified() throws Exception {
assertTrue(extractor.isUploaderVerified());
}
@ -189,7 +188,7 @@ public class SoundcloudPlaylistExtractorTest {
}
@Test
public void testUploaderUrl() {
void testUploaderUrl() {
final String uploaderUrl = extractor.getUploaderUrl();
assertIsSecureUrl(uploaderUrl);
ExtractorAsserts.assertContains("micky96", uploaderUrl);
@ -207,11 +206,10 @@ public class SoundcloudPlaylistExtractorTest {
@Test
public void testStreamCount() {
assertTrue(extractor.getStreamCount() >= 10,
"Stream count does not fit: " + extractor.getStreamCount());
ExtractorAsserts.assertGreaterOrEqual(10, extractor.getStreamCount());
}
@Override
@Test
public void testUploaderVerified() throws Exception {
assertFalse(extractor.isUploaderVerified());
}
@ -233,7 +231,7 @@ public class SoundcloudPlaylistExtractorTest {
//////////////////////////////////////////////////////////////////////////*/
@Test
public void testGetPageInNewExtractor() throws Exception {
void testGetPageInNewExtractor() throws Exception {
PlaylistExtractor newExtractor = SoundCloud.getPlaylistExtractor(extractor.getUrl());
defaultTestGetPageInNewExtractor(extractor, newExtractor);
}
@ -302,7 +300,7 @@ public class SoundcloudPlaylistExtractorTest {
}
@Test
public void testUploaderUrl() {
void testUploaderUrl() {
final String uploaderUrl = extractor.getUploaderUrl();
assertIsSecureUrl(uploaderUrl);
ExtractorAsserts.assertContains("user350509423", uploaderUrl);
@ -320,11 +318,10 @@ public class SoundcloudPlaylistExtractorTest {
@Test
public void testStreamCount() {
assertTrue(extractor.getStreamCount() >= 370,
"Stream count does not fit: " + extractor.getStreamCount());
ExtractorAsserts.assertGreaterOrEqual(370, extractor.getStreamCount());
}
@Override
@Test
public void testUploaderVerified() throws Exception {
assertFalse(extractor.isUploaderVerified());
}
@ -407,7 +404,7 @@ public class SoundcloudPlaylistExtractorTest {
}
@Test
public void testUploaderUrl() {
void testUploaderUrl() {
final String uploaderUrl = extractor.getUploaderUrl();
assertIsSecureUrl(uploaderUrl);
ExtractorAsserts.assertContains("breezy-123", uploaderUrl);
@ -428,7 +425,7 @@ public class SoundcloudPlaylistExtractorTest {
assertEquals(2, extractor.getStreamCount());
}
@Override
@Test
public void testUploaderVerified() throws Exception {
assertFalse(extractor.isUploaderVerified());
}

View File

@ -2,6 +2,8 @@ package org.schabi.newpipe.extractor.services.soundcloud;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
import org.schabi.newpipe.downloader.DownloaderTestImpl;
import org.schabi.newpipe.extractor.NewPipe;
import org.schabi.newpipe.extractor.ServiceList;
@ -31,47 +33,42 @@ public class SoundcloudSubscriptionExtractorTest {
urlHandler = ServiceList.SoundCloud.getChannelLHFactory();
}
@Test
public void testFromChannelUrl() throws Exception {
testList(subscriptionExtractor.fromChannelUrl("https://soundcloud.com/monstercat"));
testList(subscriptionExtractor.fromChannelUrl("http://soundcloud.com/monstercat"));
testList(subscriptionExtractor.fromChannelUrl("soundcloud.com/monstercat"));
testList(subscriptionExtractor.fromChannelUrl("monstercat"));
//Empty followings user
testList(subscriptionExtractor.fromChannelUrl("some-random-user-184047028"));
}
@Test
public void testInvalidSourceException() {
List<String> invalidList = Arrays.asList(
"httttps://invalid.com/user",
".com/monstercat",
"ithinkthatthisuserdontexist",
"",
null
);
for (String invalidUser : invalidList) {
try {
subscriptionExtractor.fromChannelUrl(invalidUser);
fail("didn't throw exception");
} catch (IOException e) {
// Ignore it, could be an unstable network on the CI server
} catch (Exception e) {
boolean isExpectedException = e instanceof SubscriptionExtractor.InvalidSourceException;
assertTrue(isExpectedException, e.getClass().getSimpleName() + " is not the expected exception");
}
}
}
private void testList(List<SubscriptionItem> subscriptionItems) throws ParsingException {
for (SubscriptionItem item : subscriptionItems) {
@ParameterizedTest
@ValueSource(strings = {
"https://soundcloud.com/monstercat",
"http://soundcloud.com/monstercat",
"soundcloud.com/monstercat",
"monstercat",
// Empty followings user
"some-random-user-184047028"
})
void testFromChannelUrl(final String channelUrl) throws Exception {
for (SubscriptionItem item : subscriptionExtractor.fromChannelUrl(channelUrl)) {
assertNotNull(item.getName());
assertNotNull(item.getUrl());
assertTrue(urlHandler.acceptUrl(item.getUrl()));
assertFalse(item.getServiceId() == -1);
assertNotEquals(-1, item.getServiceId());
}
}
@ParameterizedTest
@ValueSource(strings = {
"httttps://invalid.com/user",
".com/monstercat",
"ithinkthatthisuserdontexist",
""
})
void testInvalidSourceException(final String invalidUser) {
assertThrows(
SubscriptionExtractor.InvalidSourceException.class,
() -> subscriptionExtractor.fromChannelUrl(invalidUser));
}
// null can't be added to the above value source because it's not a constant
@Test
void testInvalidSourceExceptionWhenUrlIsNull() {
assertThrows(
SubscriptionExtractor.InvalidSourceException.class,
() -> subscriptionExtractor.fromChannelUrl(null));
}
}

View File

@ -136,13 +136,11 @@ public class YoutubeChannelExtractorTest {
}
@Test
public void noVideoTab() throws Exception {
void noVideoTab() throws Exception {
final ChannelExtractor extractor = YouTube.getChannelExtractor("https://invidio.us/channel/UC-9-kyTW8ZkZNDHQJ6FgpwQ");
assertThrows(ContentNotSupportedException.class, () -> {
extractor.fetchPage();
extractor.getInitialPage();
});
extractor.fetchPage();
assertThrows(ContentNotSupportedException.class, extractor::getInitialPage);
}
}
@ -215,14 +213,14 @@ public class YoutubeChannelExtractorTest {
public void testAvatarUrl() throws Exception {
String avatarUrl = extractor.getAvatarUrl();
assertIsSecureUrl(avatarUrl);
assertTrue(avatarUrl.contains("yt3"), avatarUrl);
ExtractorAsserts.assertContains("yt3", avatarUrl);
}
@Test
public void testBannerUrl() throws Exception {
String bannerUrl = extractor.getBannerUrl();
assertIsSecureUrl(bannerUrl);
assertTrue(bannerUrl.contains("yt3"), bannerUrl);
ExtractorAsserts.assertContains("yt3", bannerUrl);
}
@Test
@ -232,8 +230,7 @@ public class YoutubeChannelExtractorTest {
@Test
public void testSubscriberCount() throws Exception {
assertTrue(extractor.getSubscriberCount() >= 0, "Wrong subscriber count");
assertTrue(extractor.getSubscriberCount() >= 4e6, "Subscriber count too small");
ExtractorAsserts.assertGreaterOrEqual(4_900_000, extractor.getSubscriberCount());
}
@Override
@ -313,14 +310,14 @@ public class YoutubeChannelExtractorTest {
public void testAvatarUrl() throws Exception {
String avatarUrl = extractor.getAvatarUrl();
assertIsSecureUrl(avatarUrl);
assertTrue(avatarUrl.contains("yt3"), avatarUrl);
ExtractorAsserts.assertContains("yt3", avatarUrl);
}
@Test
public void testBannerUrl() throws Exception {
String bannerUrl = extractor.getBannerUrl();
assertIsSecureUrl(bannerUrl);
assertTrue(bannerUrl.contains("yt3"), bannerUrl);
ExtractorAsserts.assertContains("yt3", bannerUrl);
}
@Test
@ -330,11 +327,10 @@ public class YoutubeChannelExtractorTest {
@Test
public void testSubscriberCount() throws Exception {
assertTrue(extractor.getSubscriberCount() >= 0, "Wrong subscriber count");
assertTrue(extractor.getSubscriberCount() >= 10e6, "Subscriber count too small");
ExtractorAsserts.assertGreaterOrEqual(17_000_000, extractor.getSubscriberCount());
}
@Override
@Test
public void testVerified() throws Exception {
assertTrue(extractor.isVerified());
}
@ -412,14 +408,14 @@ public class YoutubeChannelExtractorTest {
public void testAvatarUrl() throws Exception {
String avatarUrl = extractor.getAvatarUrl();
assertIsSecureUrl(avatarUrl);
assertTrue(avatarUrl.contains("yt3"), avatarUrl);
ExtractorAsserts.assertContains("yt3", avatarUrl);
}
@Test
public void testBannerUrl() throws Exception {
String bannerUrl = extractor.getBannerUrl();
assertIsSecureUrl(bannerUrl);
assertTrue(bannerUrl.contains("yt3"), bannerUrl);
ExtractorAsserts.assertContains("yt3", bannerUrl);
}
@Test
@ -429,10 +425,10 @@ public class YoutubeChannelExtractorTest {
@Test
public void testSubscriberCount() throws Exception {
assertTrue(extractor.getSubscriberCount() >= 5e6, "Wrong subscriber count");
ExtractorAsserts.assertGreaterOrEqual(17_000_000, extractor.getSubscriberCount());
}
@Override
@Test
public void testVerified() throws Exception {
assertTrue(extractor.isVerified());
}
@ -527,14 +523,14 @@ public class YoutubeChannelExtractorTest {
public void testAvatarUrl() throws Exception {
String avatarUrl = extractor.getAvatarUrl();
assertIsSecureUrl(avatarUrl);
assertTrue(avatarUrl.contains("yt3"), avatarUrl);
ExtractorAsserts.assertContains("yt3", avatarUrl);
}
@Test
public void testBannerUrl() throws Exception {
String bannerUrl = extractor.getBannerUrl();
assertIsSecureUrl(bannerUrl);
assertTrue(bannerUrl.contains("yt3"), bannerUrl);
ExtractorAsserts.assertContains("yt3", bannerUrl);
}
@Test
@ -544,10 +540,10 @@ public class YoutubeChannelExtractorTest {
@Test
public void testSubscriberCount() throws Exception {
assertTrue(extractor.getSubscriberCount() >= 5e5, "Wrong subscriber count");
ExtractorAsserts.assertGreaterOrEqual(2_000_000, extractor.getSubscriberCount());
}
@Override
@Test
public void testVerified() throws Exception {
assertTrue(extractor.isVerified());
}
@ -628,14 +624,14 @@ public class YoutubeChannelExtractorTest {
public void testAvatarUrl() throws Exception {
String avatarUrl = extractor.getAvatarUrl();
assertIsSecureUrl(avatarUrl);
assertTrue(avatarUrl.contains("yt3"), avatarUrl);
ExtractorAsserts.assertContains("yt3", avatarUrl);
}
@Test
public void testBannerUrl() throws Exception {
String bannerUrl = extractor.getBannerUrl();
assertIsSecureUrl(bannerUrl);
assertTrue(bannerUrl.contains("yt3"), bannerUrl);
ExtractorAsserts.assertContains("yt3", bannerUrl);
}
@Test
@ -645,10 +641,10 @@ public class YoutubeChannelExtractorTest {
@Test
public void testSubscriberCount() throws Exception {
assertTrue(extractor.getSubscriberCount() >= 50, "Wrong subscriber count");
ExtractorAsserts.assertGreaterOrEqual(50, extractor.getSubscriberCount());
}
@Override
@Test
public void testVerified() throws Exception {
assertFalse(extractor.isVerified());
}

View File

@ -15,6 +15,7 @@ import org.schabi.newpipe.extractor.services.youtube.extractors.YoutubeMixPlayli
import org.schabi.newpipe.extractor.stream.StreamInfoItem;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.*;
import static org.junit.jupiter.api.Assertions.assertEquals;
@ -24,19 +25,16 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.schabi.newpipe.extractor.ExtractorAsserts.assertIsSecureUrl;
import static org.schabi.newpipe.extractor.ServiceList.YouTube;
import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.*;
import static org.schabi.newpipe.extractor.utils.Utils.UTF_8;
public class YoutubeMixPlaylistExtractorTest {
private static final String VIDEO_ID = "_AzeUSL9lZc";
private static final String VIDEO_TITLE =
"Most Beautiful And Emotional Piano: Anime Music Shigatsu wa Kimi no Uso OST IMO";
private static final String VIDEO_ID = "QMVCAPd5cwBcg";
private static final String VIDEO_TITLE = "Mix ";
private static final String RESOURCE_PATH = DownloaderFactory.RESOURCE_PATH + "services/youtube/extractor/mix/";
private static final Map<String, String> dummyCookie = new HashMap<>();
private static YoutubeMixPlaylistExtractor extractor;
@Disabled("Test broken, video was blocked by SME and is only available in Japan")
public static class Mix {
@BeforeAll
@ -52,19 +50,19 @@ public class YoutubeMixPlaylistExtractorTest {
}
@Test
public void getServiceId() {
void getServiceId() {
assertEquals(YouTube.getServiceId(), extractor.getServiceId());
}
@Test
public void getName() throws Exception {
void getName() throws Exception {
final String name = extractor.getName();
ExtractorAsserts.assertContains("Mix", name);
ExtractorAsserts.assertContains(VIDEO_TITLE, name);
}
@Test
public void getThumbnailUrl() throws Exception {
void getThumbnailUrl() throws Exception {
final String thumbnailUrl = extractor.getThumbnailUrl();
assertIsSecureUrl(thumbnailUrl);
ExtractorAsserts.assertContains("yt", thumbnailUrl);
@ -72,21 +70,21 @@ public class YoutubeMixPlaylistExtractorTest {
}
@Test
public void getInitialPage() throws Exception {
void getInitialPage() throws Exception {
final InfoItemsPage<StreamInfoItem> streams = extractor.getInitialPage();
assertFalse(streams.getItems().isEmpty());
assertTrue(streams.hasNextPage());
}
@Test
public void getPage() throws Exception {
void getPage() throws Exception {
final byte[] body = JsonWriter.string(prepareDesktopJsonBuilder(
NewPipe.getPreferredLocalization(), NewPipe.getPreferredContentCountry())
.value("videoId", VIDEO_ID)
.value("playlistId", "RD" + VIDEO_ID)
.value("params", "OAE%3D")
.done())
.getBytes(UTF_8);
.getBytes(StandardCharsets.UTF_8);
final InfoItemsPage<StreamInfoItem> streams = extractor.getPage(new Page(
YOUTUBEI_V1_URL + "next?key=" + getKey(), null, null, dummyCookie, body));
@ -95,7 +93,7 @@ public class YoutubeMixPlaylistExtractorTest {
}
@Test
public void getContinuations() throws Exception {
void getContinuations() throws Exception {
InfoItemsPage<StreamInfoItem> streams = extractor.getInitialPage();
final Set<String> urls = new HashSet<>();
@ -117,16 +115,15 @@ public class YoutubeMixPlaylistExtractorTest {
}
@Test
public void getStreamCount() {
void getStreamCount() {
assertEquals(ListExtractor.ITEM_COUNT_INFINITE, extractor.getStreamCount());
}
}
@Disabled("Test broken, video was removed by the uploader")
public static class MixWithIndex {
private static final int INDEX = 13;
private static final String VIDEO_ID_NUMBER_13 = "qHtzO49SDmk";
private static final int INDEX = 4;
private static final String VIDEO_ID_NUMBER_4 = "lWA2pjMjpBs";
@BeforeAll
public static void setUp() throws Exception {
@ -135,20 +132,20 @@ public class YoutubeMixPlaylistExtractorTest {
NewPipe.init(new DownloaderFactory().getDownloader(RESOURCE_PATH + "mixWithIndex"));
dummyCookie.put(YoutubeMixPlaylistExtractor.COOKIE_NAME, "whatever");
extractor = (YoutubeMixPlaylistExtractor) YouTube
.getPlaylistExtractor("https://www.youtube.com/watch?v=" + VIDEO_ID_NUMBER_13
.getPlaylistExtractor("https://www.youtube.com/watch?v=" + VIDEO_ID_NUMBER_4
+ "&list=RD" + VIDEO_ID + "&index=" + INDEX);
extractor.fetchPage();
}
@Test
public void getName() throws Exception {
void getName() throws Exception {
final String name = extractor.getName();
ExtractorAsserts.assertContains("Mix", name);
ExtractorAsserts.assertContains(VIDEO_TITLE, name);
}
@Test
public void getThumbnailUrl() throws Exception {
void getThumbnailUrl() throws Exception {
final String thumbnailUrl = extractor.getThumbnailUrl();
assertIsSecureUrl(thumbnailUrl);
ExtractorAsserts.assertContains("yt", thumbnailUrl);
@ -156,14 +153,14 @@ public class YoutubeMixPlaylistExtractorTest {
}
@Test
public void getInitialPage() throws Exception {
void getInitialPage() throws Exception {
final InfoItemsPage<StreamInfoItem> streams = extractor.getInitialPage();
assertFalse(streams.getItems().isEmpty());
assertTrue(streams.hasNextPage());
}
@Test
public void getPage() throws Exception {
void getPage() throws Exception {
final byte[] body = JsonWriter.string(prepareDesktopJsonBuilder(
NewPipe.getPreferredLocalization(), NewPipe.getPreferredContentCountry())
.value("videoId", VIDEO_ID)
@ -171,7 +168,7 @@ public class YoutubeMixPlaylistExtractorTest {
.value("playlistIndex", INDEX)
.value("params", "OAE%3D")
.done())
.getBytes(UTF_8);
.getBytes(StandardCharsets.UTF_8);
final InfoItemsPage<StreamInfoItem> streams = extractor.getPage(new Page(
YOUTUBEI_V1_URL + "next?key=" + getKey(), null, null, dummyCookie, body));
@ -180,7 +177,7 @@ public class YoutubeMixPlaylistExtractorTest {
}
@Test
public void getContinuations() throws Exception {
void getContinuations() throws Exception {
InfoItemsPage<StreamInfoItem> streams = extractor.getInitialPage();
final Set<String> urls = new HashSet<>();
@ -201,12 +198,11 @@ public class YoutubeMixPlaylistExtractorTest {
}
@Test
public void getStreamCount() {
void getStreamCount() {
assertEquals(ListExtractor.ITEM_COUNT_INFINITE, extractor.getStreamCount());
}
}
@Disabled("Test broken")
public static class MyMix {
@BeforeAll
@ -222,39 +218,39 @@ public class YoutubeMixPlaylistExtractorTest {
}
@Test
public void getServiceId() {
void getServiceId() {
assertEquals(YouTube.getServiceId(), extractor.getServiceId());
}
@Test
public void getName() throws Exception {
void getName() throws Exception {
final String name = extractor.getName();
assertEquals("My Mix", name);
}
@Test
public void getThumbnailUrl() throws Exception {
void getThumbnailUrl() throws Exception {
final String thumbnailUrl = extractor.getThumbnailUrl();
assertIsSecureUrl(thumbnailUrl);
assertTrue(thumbnailUrl.startsWith("https://i.ytimg.com/vi/_AzeUSL9lZc"));
}
@Test
public void getInitialPage() throws Exception {
void getInitialPage() throws Exception {
final InfoItemsPage<StreamInfoItem> streams = extractor.getInitialPage();
assertFalse(streams.getItems().isEmpty());
assertTrue(streams.hasNextPage());
}
@Test
public void getPage() throws Exception {
void getPage() throws Exception {
final byte[] body = JsonWriter.string(prepareDesktopJsonBuilder(
NewPipe.getPreferredLocalization(), NewPipe.getPreferredContentCountry())
.value("videoId", VIDEO_ID)
.value("playlistId", "RDMM" + VIDEO_ID)
.value("params", "OAE%3D")
.done())
.getBytes(UTF_8);
.getBytes(StandardCharsets.UTF_8);
final InfoItemsPage<StreamInfoItem> streams = extractor.getPage(new Page(
YOUTUBEI_V1_URL + "next?key=" + getKey(), null, null, dummyCookie, body));
@ -263,7 +259,7 @@ public class YoutubeMixPlaylistExtractorTest {
}
@Test
public void getContinuations() throws Exception {
void getContinuations() throws Exception {
InfoItemsPage<StreamInfoItem> streams = extractor.getInitialPage();
final Set<String> urls = new HashSet<>();
@ -285,7 +281,7 @@ public class YoutubeMixPlaylistExtractorTest {
}
@Test
public void getStreamCount() {
void getStreamCount() {
assertEquals(ListExtractor.ITEM_COUNT_INFINITE, extractor.getStreamCount());
}
}
@ -300,29 +296,13 @@ public class YoutubeMixPlaylistExtractorTest {
dummyCookie.put(YoutubeMixPlaylistExtractor.COOKIE_NAME, "whatever");
}
@Disabled
@Test
public void getPageEmptyUrl() throws Exception {
extractor = (YoutubeMixPlaylistExtractor) YouTube
.getPlaylistExtractor("https://www.youtube.com/watch?v=" + VIDEO_ID
+ "&list=RD" + VIDEO_ID);
assertThrows(IllegalArgumentException.class, () -> {
extractor.fetchPage();
extractor.getPage(new Page(""));
});
}
@Test
public void invalidVideoId() throws Exception {
void invalidVideoId() throws Exception {
extractor = (YoutubeMixPlaylistExtractor) YouTube
.getPlaylistExtractor("https://www.youtube.com/watch?v=" + "abcde"
+ "&list=RD" + "abcde");
assertThrows(ExtractionException.class, () -> {
extractor.fetchPage();
extractor.getName();
});
assertThrows(ExtractionException.class, extractor::fetchPage);
}
}
@ -346,35 +326,35 @@ public class YoutubeMixPlaylistExtractorTest {
}
@Test
public void getName() throws Exception {
void getName() throws Exception {
final String name = extractor.getName();
ExtractorAsserts.assertContains("Mix", name);
ExtractorAsserts.assertContains(CHANNEL_TITLE, name);
}
@Test
public void getThumbnailUrl() throws Exception {
void getThumbnailUrl() throws Exception {
final String thumbnailUrl = extractor.getThumbnailUrl();
assertIsSecureUrl(thumbnailUrl);
ExtractorAsserts.assertContains("yt", thumbnailUrl);
}
@Test
public void getInitialPage() throws Exception {
void getInitialPage() throws Exception {
final InfoItemsPage<StreamInfoItem> streams = extractor.getInitialPage();
assertFalse(streams.getItems().isEmpty());
assertTrue(streams.hasNextPage());
}
@Test
public void getPage() throws Exception {
void getPage() throws Exception {
final byte[] body = JsonWriter.string(prepareDesktopJsonBuilder(
NewPipe.getPreferredLocalization(), NewPipe.getPreferredContentCountry())
.value("videoId", VIDEO_ID_OF_CHANNEL)
.value("playlistId", "RDCM" + CHANNEL_ID)
.value("params", "OAE%3D")
.done())
.getBytes(UTF_8);
.getBytes(StandardCharsets.UTF_8);
final InfoItemsPage<StreamInfoItem> streams = extractor.getPage(new Page(
YOUTUBEI_V1_URL + "next?key=" + getKey(), null, null, dummyCookie, body));
@ -383,7 +363,7 @@ public class YoutubeMixPlaylistExtractorTest {
}
@Test
public void getStreamCount() {
void getStreamCount() {
assertEquals(ListExtractor.ITEM_COUNT_INFINITE, extractor.getStreamCount());
}
}

View File

@ -154,7 +154,7 @@ public class YoutubePlaylistExtractorTest {
@Test
public void testStreamCount() throws Exception {
assertTrue(extractor.getStreamCount() > 100, "Error in the streams count");
ExtractorAsserts.assertGreater(100, extractor.getStreamCount());
}
@Override
@ -273,7 +273,7 @@ public class YoutubePlaylistExtractorTest {
@Test
public void testStreamCount() throws Exception {
assertTrue(extractor.getStreamCount() > 100, "Error in the streams count");
ExtractorAsserts.assertGreater(100, extractor.getStreamCount());
}
@Override
@ -377,7 +377,7 @@ public class YoutubePlaylistExtractorTest {
@Test
public void testStreamCount() throws Exception {
assertTrue(extractor.getStreamCount() > 40, "Error in the streams count");
ExtractorAsserts.assertGreater(40, extractor.getStreamCount());
}
@Override