[PeerTube] Test onAccept(String URL) in LinkHandlerFactories for non-URLs

This commit is contained in:
TobiGr 2023-12-29 12:43:20 +01:00
parent 2b2c1546d1
commit 61d237de02
6 changed files with 56 additions and 2 deletions

View File

@ -7,9 +7,9 @@ import org.schabi.newpipe.extractor.NewPipe;
import org.schabi.newpipe.extractor.exceptions.ParsingException;
import org.schabi.newpipe.extractor.services.peertube.linkHandler.PeertubeChannelLinkHandlerFactory;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.*;
import static org.schabi.newpipe.extractor.ServiceList.PeerTube;
import static org.schabi.newpipe.extractor.services.peertube.PeertubeLinkHandlerFactoryTestHelper.testDoNotAcceptNonURLs;
/**
* Test for {@link PeertubeChannelLinkHandlerFactory}
@ -33,6 +33,8 @@ public class PeertubeChannelLinkHandlerFactoryTest {
assertTrue(linkHandler.acceptUrl("https://peertube.stream/video-channels/kranti_channel@videos.squat.net/videos"));
assertTrue(linkHandler.acceptUrl("https://peertube.stream/c/kranti_channel@videos.squat.net/videos"));
assertTrue(linkHandler.acceptUrl("https://peertube.stream/api/v1/video-channels/7682d9f2-07be-4622-862e-93ec812e2ffa"));
testDoNotAcceptNonURLs(linkHandler);
}
@Test

View File

@ -9,6 +9,7 @@ import org.schabi.newpipe.extractor.services.peertube.linkHandler.PeertubeCommen
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.schabi.newpipe.extractor.services.peertube.PeertubeLinkHandlerFactoryTestHelper.testDoNotAcceptNonURLs;
/**
* Test for {@link PeertubeCommentsLinkHandlerFactory}
@ -31,6 +32,8 @@ public class PeertubeCommentsLinkHandlerFactoryTest {
assertTrue(linkHandler.acceptUrl("https://framatube.org/videos/watch/9c9de5e8-0a1e-484a-b099-e80766180a6d"));
assertTrue(linkHandler.acceptUrl("https://framatube.org/w/9c9de5e8-0a1e-484a-b099-e80766180a6d"));
assertTrue(linkHandler.acceptUrl("https://framatube.org/api/v1/videos/9c9de5e8-0a1e-484a-b099-e80766180a6d/comment-threads?start=0&count=10&sort=-createdAt"));
testDoNotAcceptNonURLs(linkHandler);
}
@Test

View File

@ -0,0 +1,40 @@
package org.schabi.newpipe.extractor.services.peertube;
import org.schabi.newpipe.extractor.exceptions.ParsingException;
import org.schabi.newpipe.extractor.linkhandler.LinkHandlerFactory;
import org.schabi.newpipe.extractor.linkhandler.ListLinkHandlerFactory;
import static org.junit.jupiter.api.Assertions.assertFalse;
public class PeertubeLinkHandlerFactoryTestHelper {
public static void testDoNotAcceptNonURLs(LinkHandlerFactory linkHandler)
throws ParsingException {
assertFalse(linkHandler.acceptUrl("orchestr/a/"));
assertFalse(linkHandler.acceptUrl("/a/"));
assertFalse(linkHandler.acceptUrl("something/c/"));
assertFalse(linkHandler.acceptUrl("/c/"));
assertFalse(linkHandler.acceptUrl("videos/"));
assertFalse(linkHandler.acceptUrl("I-hate-videos/"));
assertFalse(linkHandler.acceptUrl("/w/"));
assertFalse(linkHandler.acceptUrl("ksmg/w/"));
assertFalse(linkHandler.acceptUrl("a reandom search query"));
assertFalse(linkHandler.acceptUrl("test 230 "));
assertFalse(linkHandler.acceptUrl("986513"));
}
public static void testDoNotAcceptNonURLs(ListLinkHandlerFactory linkHandler)
throws ParsingException {
assertFalse(linkHandler.acceptUrl("orchestr/a/"));
assertFalse(linkHandler.acceptUrl("/a/"));
assertFalse(linkHandler.acceptUrl("something/c/"));
assertFalse(linkHandler.acceptUrl("/c/"));
assertFalse(linkHandler.acceptUrl("videos/"));
assertFalse(linkHandler.acceptUrl("I-hate-videos/"));
assertFalse(linkHandler.acceptUrl("/w/"));
assertFalse(linkHandler.acceptUrl("ksmg/w/"));
assertFalse(linkHandler.acceptUrl("a reandom search query"));
assertFalse(linkHandler.acceptUrl("test 230 "));
assertFalse(linkHandler.acceptUrl("986513"));
}
}

View File

@ -10,6 +10,7 @@ import org.schabi.newpipe.extractor.services.peertube.linkHandler.PeertubePlayli
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.schabi.newpipe.extractor.services.peertube.PeertubeLinkHandlerFactoryTestHelper.testDoNotAcceptNonURLs;
/**
* Test for {@link PeertubePlaylistLinkHandlerFactory}
@ -33,6 +34,8 @@ public class PeertubePlaylistLinkHandlerFactoryTest {
assertTrue(linkHandler.acceptUrl("https://framatube.org/w/p/dacdc4ef-5160-4846-9b70-a655880da667"));
assertTrue(linkHandler.acceptUrl("https://framatube.org/videos/watch/playlist/96b0ee2b-a5a7-4794-8769-58d8ccb79ab7"));
assertTrue(linkHandler.acceptUrl("https://framatube.org/w/p/96b0ee2b-a5a7-4794-8769-58d8ccb79ab7"));
testDoNotAcceptNonURLs(linkHandler);
}
@Test

View File

@ -9,6 +9,7 @@ import org.schabi.newpipe.extractor.services.peertube.linkHandler.PeertubeStream
import static org.junit.jupiter.api.Assertions.*;
import static org.schabi.newpipe.extractor.ServiceList.PeerTube;
import static org.schabi.newpipe.extractor.services.peertube.PeertubeLinkHandlerFactoryTestHelper.testDoNotAcceptNonURLs;
/**
* Test for {@link PeertubeStreamLinkHandlerFactory}
@ -71,5 +72,7 @@ public class PeertubeStreamLinkHandlerFactoryTest {
// make sure playlists aren't accepted
assertFalse(linkHandler.acceptUrl("https://framatube.org/w/p/dacdc4ef-5160-4846-9b70-a655880da667"));
assertFalse(linkHandler.acceptUrl("https://framatube.org/videos/watch/playlist/dacdc4ef-5160-4846-9b70-a655880da667"));
PeertubeLinkHandlerFactoryTestHelper.testDoNotAcceptNonURLs(linkHandler);
}
}

View File

@ -11,6 +11,7 @@ import org.schabi.newpipe.extractor.services.peertube.linkHandler.PeertubeTrendi
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.schabi.newpipe.extractor.ServiceList.PeerTube;
import static org.schabi.newpipe.extractor.services.peertube.PeertubeLinkHandlerFactoryTestHelper.testDoNotAcceptNonURLs;
/**
* Test for {@link PeertubeTrendingLinkHandlerFactory}
@ -57,5 +58,7 @@ public class PeertubeTrendingLinkHandlerFactoryTest {
assertTrue(LinkHandlerFactory.acceptUrl("https://peertube.mastodon.host/videos/local"));
assertTrue(LinkHandlerFactory.acceptUrl("https://peertube.mastodon.host/videos/local?adsf=fjaj#fhe"));
PeertubeLinkHandlerFactoryTestHelper.testDoNotAcceptNonURLs(LinkHandlerFactory);
}
}