Skip to content

Commit 61d237d

Browse files
committed
[PeerTube] Test onAccept(String URL) in LinkHandlerFactories for non-URLs
1 parent 2b2c154 commit 61d237d

6 files changed

Lines changed: 56 additions & 2 deletions

extractor/src/test/java/org/schabi/newpipe/extractor/services/peertube/PeertubeChannelLinkHandlerFactoryTest.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
import org.schabi.newpipe.extractor.exceptions.ParsingException;
88
import org.schabi.newpipe.extractor.services.peertube.linkHandler.PeertubeChannelLinkHandlerFactory;
99

10-
import static org.junit.jupiter.api.Assertions.assertEquals;
11-
import static org.junit.jupiter.api.Assertions.assertTrue;
10+
import static org.junit.jupiter.api.Assertions.*;
1211
import static org.schabi.newpipe.extractor.ServiceList.PeerTube;
12+
import static org.schabi.newpipe.extractor.services.peertube.PeertubeLinkHandlerFactoryTestHelper.testDoNotAcceptNonURLs;
1313

1414
/**
1515
* Test for {@link PeertubeChannelLinkHandlerFactory}
@@ -33,6 +33,8 @@ public void acceptUrlTest() throws ParsingException {
3333
assertTrue(linkHandler.acceptUrl("https://peertube.stream/video-channels/kranti_channel@videos.squat.net/videos"));
3434
assertTrue(linkHandler.acceptUrl("https://peertube.stream/c/kranti_channel@videos.squat.net/videos"));
3535
assertTrue(linkHandler.acceptUrl("https://peertube.stream/api/v1/video-channels/7682d9f2-07be-4622-862e-93ec812e2ffa"));
36+
37+
testDoNotAcceptNonURLs(linkHandler);
3638
}
3739

3840
@Test

extractor/src/test/java/org/schabi/newpipe/extractor/services/peertube/PeertubeCommentsLinkHandlerFactoryTest.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
import static org.junit.jupiter.api.Assertions.assertEquals;
1111
import static org.junit.jupiter.api.Assertions.assertTrue;
12+
import static org.schabi.newpipe.extractor.services.peertube.PeertubeLinkHandlerFactoryTestHelper.testDoNotAcceptNonURLs;
1213

1314
/**
1415
* Test for {@link PeertubeCommentsLinkHandlerFactory}
@@ -31,6 +32,8 @@ public void acceptUrlTest() throws ParsingException {
3132
assertTrue(linkHandler.acceptUrl("https://framatube.org/videos/watch/9c9de5e8-0a1e-484a-b099-e80766180a6d"));
3233
assertTrue(linkHandler.acceptUrl("https://framatube.org/w/9c9de5e8-0a1e-484a-b099-e80766180a6d"));
3334
assertTrue(linkHandler.acceptUrl("https://framatube.org/api/v1/videos/9c9de5e8-0a1e-484a-b099-e80766180a6d/comment-threads?start=0&count=10&sort=-createdAt"));
35+
36+
testDoNotAcceptNonURLs(linkHandler);
3437
}
3538

3639
@Test
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package org.schabi.newpipe.extractor.services.peertube;
2+
3+
import org.schabi.newpipe.extractor.exceptions.ParsingException;
4+
import org.schabi.newpipe.extractor.linkhandler.LinkHandlerFactory;
5+
import org.schabi.newpipe.extractor.linkhandler.ListLinkHandlerFactory;
6+
7+
import static org.junit.jupiter.api.Assertions.assertFalse;
8+
9+
public class PeertubeLinkHandlerFactoryTestHelper {
10+
11+
public static void testDoNotAcceptNonURLs(LinkHandlerFactory linkHandler)
12+
throws ParsingException {
13+
assertFalse(linkHandler.acceptUrl("orchestr/a/"));
14+
assertFalse(linkHandler.acceptUrl("/a/"));
15+
assertFalse(linkHandler.acceptUrl("something/c/"));
16+
assertFalse(linkHandler.acceptUrl("/c/"));
17+
assertFalse(linkHandler.acceptUrl("videos/"));
18+
assertFalse(linkHandler.acceptUrl("I-hate-videos/"));
19+
assertFalse(linkHandler.acceptUrl("/w/"));
20+
assertFalse(linkHandler.acceptUrl("ksmg/w/"));
21+
assertFalse(linkHandler.acceptUrl("a reandom search query"));
22+
assertFalse(linkHandler.acceptUrl("test 230 "));
23+
assertFalse(linkHandler.acceptUrl("986513"));
24+
}
25+
26+
public static void testDoNotAcceptNonURLs(ListLinkHandlerFactory linkHandler)
27+
throws ParsingException {
28+
assertFalse(linkHandler.acceptUrl("orchestr/a/"));
29+
assertFalse(linkHandler.acceptUrl("/a/"));
30+
assertFalse(linkHandler.acceptUrl("something/c/"));
31+
assertFalse(linkHandler.acceptUrl("/c/"));
32+
assertFalse(linkHandler.acceptUrl("videos/"));
33+
assertFalse(linkHandler.acceptUrl("I-hate-videos/"));
34+
assertFalse(linkHandler.acceptUrl("/w/"));
35+
assertFalse(linkHandler.acceptUrl("ksmg/w/"));
36+
assertFalse(linkHandler.acceptUrl("a reandom search query"));
37+
assertFalse(linkHandler.acceptUrl("test 230 "));
38+
assertFalse(linkHandler.acceptUrl("986513"));
39+
}
40+
}

extractor/src/test/java/org/schabi/newpipe/extractor/services/peertube/PeertubePlaylistLinkHandlerFactoryTest.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
1111
import static org.junit.jupiter.api.Assertions.assertEquals;
1212
import static org.junit.jupiter.api.Assertions.assertTrue;
13+
import static org.schabi.newpipe.extractor.services.peertube.PeertubeLinkHandlerFactoryTestHelper.testDoNotAcceptNonURLs;
1314

1415
/**
1516
* Test for {@link PeertubePlaylistLinkHandlerFactory}
@@ -33,6 +34,8 @@ void acceptUrlTest() throws ParsingException {
3334
assertTrue(linkHandler.acceptUrl("https://framatube.org/w/p/dacdc4ef-5160-4846-9b70-a655880da667"));
3435
assertTrue(linkHandler.acceptUrl("https://framatube.org/videos/watch/playlist/96b0ee2b-a5a7-4794-8769-58d8ccb79ab7"));
3536
assertTrue(linkHandler.acceptUrl("https://framatube.org/w/p/96b0ee2b-a5a7-4794-8769-58d8ccb79ab7"));
37+
38+
testDoNotAcceptNonURLs(linkHandler);
3639
}
3740

3841
@Test

extractor/src/test/java/org/schabi/newpipe/extractor/services/peertube/PeertubeStreamLinkHandlerFactoryTest.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
import static org.junit.jupiter.api.Assertions.*;
1111
import static org.schabi.newpipe.extractor.ServiceList.PeerTube;
12+
import static org.schabi.newpipe.extractor.services.peertube.PeertubeLinkHandlerFactoryTestHelper.testDoNotAcceptNonURLs;
1213

1314
/**
1415
* Test for {@link PeertubeStreamLinkHandlerFactory}
@@ -71,5 +72,7 @@ public void testAcceptUrl() throws ParsingException {
7172
// make sure playlists aren't accepted
7273
assertFalse(linkHandler.acceptUrl("https://framatube.org/w/p/dacdc4ef-5160-4846-9b70-a655880da667"));
7374
assertFalse(linkHandler.acceptUrl("https://framatube.org/videos/watch/playlist/dacdc4ef-5160-4846-9b70-a655880da667"));
75+
76+
PeertubeLinkHandlerFactoryTestHelper.testDoNotAcceptNonURLs(linkHandler);
7477
}
7578
}

extractor/src/test/java/org/schabi/newpipe/extractor/services/peertube/PeertubeTrendingLinkHandlerFactoryTest.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import static org.junit.jupiter.api.Assertions.assertEquals;
1212
import static org.junit.jupiter.api.Assertions.assertTrue;
1313
import static org.schabi.newpipe.extractor.ServiceList.PeerTube;
14+
import static org.schabi.newpipe.extractor.services.peertube.PeertubeLinkHandlerFactoryTestHelper.testDoNotAcceptNonURLs;
1415

1516
/**
1617
* Test for {@link PeertubeTrendingLinkHandlerFactory}
@@ -57,5 +58,7 @@ public void acceptUrl() throws ParsingException {
5758

5859
assertTrue(LinkHandlerFactory.acceptUrl("https://peertube.mastodon.host/videos/local"));
5960
assertTrue(LinkHandlerFactory.acceptUrl("https://peertube.mastodon.host/videos/local?adsf=fjaj#fhe"));
61+
62+
PeertubeLinkHandlerFactoryTestHelper.testDoNotAcceptNonURLs(LinkHandlerFactory);
6063
}
6164
}

0 commit comments

Comments
 (0)