From 844de3e37831f280f49f2051303e612b0379c9f7 Mon Sep 17 00:00:00 2001 From: litetex <40789489+litetex@users.noreply.github.com> Date: Sun, 7 Aug 2022 13:58:21 +0200 Subject: [PATCH] Fix ``YoutubeStreamLinkHandlerFactoryTest `` and parameterized the tests used code from #833 --- .../YoutubeStreamLinkHandlerFactoryTest.java | 284 ++++++++++-------- 1 file changed, 159 insertions(+), 125 deletions(-) diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeStreamLinkHandlerFactoryTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeStreamLinkHandlerFactoryTest.java index 848c4ed508..62c9f6a5cd 100644 --- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeStreamLinkHandlerFactoryTest.java +++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeStreamLinkHandlerFactoryTest.java @@ -2,6 +2,9 @@ import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.CsvSource; +import org.junit.jupiter.params.provider.ValueSource; import org.schabi.newpipe.downloader.DownloaderTestImpl; import org.schabi.newpipe.extractor.NewPipe; import org.schabi.newpipe.extractor.exceptions.FoundAdException; @@ -17,7 +20,6 @@ * Test for {@link YoutubeStreamLinkHandlerFactory} */ public class YoutubeStreamLinkHandlerFactoryTest { - private static String AD_URL = "https://googleads.g.doubleclick.net/aclk?sa=l&ai=C-2IPgeVTWPf4GcOStgfOnIOADf78n61GvKmmobYDrgIQASDj-5MDKAJg9ZXOgeAEoAGgy_T-A8gBAakC2gkpmquIsT6oAwGqBJMBT9BgD5kVgbN0dX602bFFaDw9vsxq-We-S8VkrXVBi6W_e7brZ36GCz1WO3EPEeklYuJjXLUowwCOKsd-8xr1UlS_tusuFJv9iX35xoBHKTRvs8-0aDbfEIm6in37QDfFuZjqgEMB8-tg0Jn_Pf1RU5OzbuU40B4Gy25NUTnOxhDKthOhKBUSZEksCEerUV8GMu10iAXCxquwApIFBggDEAEYAaAGGsgGlIjthrUDgAfItIsBqAemvhvYBwHSCAUIgGEQAbgT6AE&num=1&sig=AOD64_1DybDd4qAm5O7o9UAbTNRdqXXHFQ&ctype=21&video_id=dMO_IXYPZew&client=ca-pub-6219811747049371&adurl=http://www.youtube.com/watch%3Fv%3DdMO_IXYPZew"; private static YoutubeStreamLinkHandlerFactory linkHandler; @BeforeAll @@ -27,146 +29,178 @@ public static void setUp() { } @Test - public void getIdWithNullAsUrl() { - assertThrows(IllegalArgumentException.class, () -> linkHandler.fromId(null)); + void getIdWithNullAsUrl() { + assertThrows(NullPointerException.class, () -> linkHandler.fromId(null)); } @Test - public void getIdForAd() throws ParsingException { - assertThrows(FoundAdException.class, () -> linkHandler.fromUrl(AD_URL)); + void getIdForAd() { + assertThrows(FoundAdException.class, () -> linkHandler.fromUrl( + "https://googleads.g.doubleclick.net/aclk?sa=l&ai=C-2IPgeVTWPf4GcOStgfOnIOADf78n61GvKmmobYDrgIQASDj-5MDKAJg9ZXOgeAEoAGgy_T-A8gBAakC2gkpmquIsT6oAwGqBJMBT9BgD5kVgbN0dX602bFFaDw9vsxq-We-S8VkrXVBi6W_e7brZ36GCz1WO3EPEeklYuJjXLUowwCOKsd-8xr1UlS_tusuFJv9iX35xoBHKTRvs8-0aDbfEIm6in37QDfFuZjqgEMB8-tg0Jn_Pf1RU5OzbuU40B4Gy25NUTnOxhDKthOhKBUSZEksCEerUV8GMu10iAXCxquwApIFBggDEAEYAaAGGsgGlIjthrUDgAfItIsBqAemvhvYBwHSCAUIgGEQAbgT6AE&num=1&sig=AOD64_1DybDd4qAm5O7o9UAbTNRdqXXHFQ&ctype=21&video_id=dMO_IXYPZew&client=ca-pub-6219811747049371&adurl=http://www.youtube.com/watch%3Fv%3DdMO_IXYPZew")); } - @Test - public void getIdForInvalidUrls() { - List invalidUrls = new ArrayList<>(50); - invalidUrls.add("https://www.youtube.com/watch?v=jZViOEv90d"); - invalidUrls.add("https://www.youtube.com/watchjZViOEv90d"); - invalidUrls.add("https://www.youtube.com/"); - invalidUrls.add("https://www.youtube.com/channel/UCBR8-60-B28hp2BmDPdntcQ"); - invalidUrls.add("https://invidio.us/channel/UCBR8-60-B28hp2BmDPdntcQ"); - for (String invalidUrl : invalidUrls) { - Throwable exception = null; - try { - linkHandler.fromUrl(invalidUrl).getId(); - } catch (ParsingException e) { - exception = e; - } - if (exception == null) { - fail("Expected ParsingException for url: " + invalidUrl); - } - } + @ParameterizedTest + @ValueSource(strings = { + "https://www.youtube.com/watch?v=jZViOEv90d", + "https://www.youtube.com/watchjZViOEv90d", + "https://www.youtube.com/", + "https://www.youtube.com/channel/UCBR8-60-B28hp2BmDPdntcQ", + "https://invidious.fdn.fr/channel/UCBR8-60-B28hp2BmDPdntcQ" + }) + void getIdForInvalidUrls(final String invalidUrl) { + assertThrows(ParsingException.class, () -> linkHandler.fromUrl(invalidUrl).getId()); } - @Test - public void getIdfromYt() throws Exception { - assertEquals("jZViOEv90dI", linkHandler.fromUrl("https://www.youtube.com/watch?v=jZViOEv90dI").getId()); - assertEquals("W-fFHeTX70Q", linkHandler.fromUrl("https://www.youtube.com/watch?v=W-fFHeTX70Q").getId()); - assertEquals("jZViOEv90dI", linkHandler.fromUrl("https://www.youtube.com/watch?v=jZViOEv90dI&t=100").getId()); - assertEquals("jZViOEv90dI", linkHandler.fromUrl("https://WWW.YouTube.com/watch?v=jZViOEv90dI&t=100").getId()); - assertEquals("jZViOEv90dI", linkHandler.fromUrl("HTTPS://www.youtube.com/watch?v=jZViOEv90dI&t=100").getId()); - assertEquals("jZViOEv90dI", linkHandler.fromUrl("https://youtu.be/jZViOEv90dI?t=9s").getId()); - assertEquals("jZViOEv90dI", linkHandler.fromUrl("HTTPS://Youtu.be/jZViOEv90dI?t=9s").getId()); - assertEquals("uEJuoEs1UxY", linkHandler.fromUrl("http://www.youtube.com/watch_popup?v=uEJuoEs1UxY").getId()); - assertEquals("uEJuoEs1UxY", linkHandler.fromUrl("http://www.Youtube.com/watch_popup?v=uEJuoEs1UxY").getId()); - assertEquals("jZViOEv90dI", linkHandler.fromUrl("https://www.youtube.com/embed/jZViOEv90dI").getId()); - assertEquals("jZViOEv90dI", linkHandler.fromUrl("https://www.youtube-nocookie.com/embed/jZViOEv90dI").getId()); - assertEquals("jZViOEv90dI", linkHandler.fromUrl("http://www.youtube.com/watch?v=jZViOEv90dI").getId()); - assertEquals("jZViOEv90dI", linkHandler.fromUrl("http://youtube.com/watch?v=jZViOEv90dI").getId()); - assertEquals("jZViOEv90dI", linkHandler.fromUrl("http://youtu.be/jZViOEv90dI?t=9s").getId()); - assertEquals("7_WWz2DSnT8", linkHandler.fromUrl("https://youtu.be/7_WWz2DSnT8").getId()); - assertEquals("oy6NvWeVruY", linkHandler.fromUrl("https://m.youtube.com/watch?v=oy6NvWeVruY").getId()); - assertEquals("jZViOEv90dI", linkHandler.fromUrl("http://www.youtube.com/embed/jZViOEv90dI").getId()); - assertEquals("jZViOEv90dI", linkHandler.fromUrl("http://www.Youtube.com/embed/jZViOEv90dI").getId()); - assertEquals("jZViOEv90dI", linkHandler.fromUrl("http://www.youtube-nocookie.com/embed/jZViOEv90dI").getId()); - assertEquals("EhxJLojIE_o", linkHandler.fromUrl("http://www.youtube.com/attribution_link?a=JdfC0C9V6ZI&u=%2Fwatch%3Fv%3DEhxJLojIE_o%26feature%3Dshare").getId()); - assertEquals("jZViOEv90dI", linkHandler.fromUrl("vnd.youtube://www.youtube.com/watch?v=jZViOEv90dI").getId()); - assertEquals("jZViOEv90dI", linkHandler.fromUrl("vnd.youtube:jZViOEv90dI").getId()); - assertEquals("n8X9_MgEdCg", linkHandler.fromUrl("vnd.youtube://n8X9_MgEdCg").getId()); - assertEquals("O0EDx9WAelc", linkHandler.fromUrl("https://music.youtube.com/watch?v=O0EDx9WAelc").getId()); - assertEquals("-cdveCh1kQk", linkHandler.fromUrl("https://m.youtube.com/watch?v=-cdveCh1kQk)").getId()); - assertEquals("-cdveCh1kQk", linkHandler.fromUrl("https://www.youtube.com/watch?v=-cdveCh1kQk-").getId()); - assertEquals("-cdveCh1kQk", linkHandler.fromUrl("https://WWW.YouTube.com/watch?v=-cdveCh1kQkwhatever").getId()); - assertEquals("O0EDx9WAelc", linkHandler.fromUrl("HTTPS://www.youtube.com/watch?v=O0EDx9WAelc]").getId()); - assertEquals("-cdveCh1kQk", linkHandler.fromUrl("https://youtu.be/-cdveCh1kQk)hello").getId()); - assertEquals("OGS7c0-CmRs", linkHandler.fromUrl("https://YouTu.be/OGS7c0-CmRswhatever)").getId()); - assertEquals("-cdveCh1kQk", linkHandler.fromUrl("HTTPS://youtu.be/-cdveCh1kQk)").getId()); - assertEquals("IOS2fqxwYbA", linkHandler.fromUrl("https://www.youtube.com/shorts/IOS2fqxwYbAhi").getId()); - assertEquals("IOS2fqxwYbA", linkHandler.fromUrl("http://www.youtube.com/shorts/IOS2fqxwYbA").getId()); - assertEquals("IOS2fqxwYbA", linkHandler.fromUrl("http://www.youtube.com/v/IOS2fqxwYbA").getId()); - assertEquals("IOS2fqxwYbA", linkHandler.fromUrl("http://www.youtube.com/w/IOS2fqxwYbA").getId()); - assertEquals("IOS2fqxwYbA", linkHandler.fromUrl("http://www.youtube.com/watch/IOS2fqxwYbA").getId()); + @ParameterizedTest + @ValueSource(strings = { + "https://www.youtube.com/watch?v=jZViOEv90dI", + "https://www.youtube.com/watch?v=jZViOEv90dI&t=100", + "https://WWW.YouTube.com/watch?v=jZViOEv90dI&t=100", + "HTTPS://www.youtube.com/watch?v=jZViOEv90dI&t=100", + "https://youtu.be/jZViOEv90dI?t=9s", + "HTTPS://Youtu.be/jZViOEv90dI?t=9s", + "https://www.youtube.com/embed/jZViOEv90dI", + "https://www.youtube-nocookie.com/embed/jZViOEv90dI", + "http://www.youtube.com/watch?v=jZViOEv90dI", + "http://youtube.com/watch?v=jZViOEv90dI", + "http://youtu.be/jZViOEv90dI?t=9s", + "http://www.youtube.com/embed/jZViOEv90dI", + "http://www.Youtube.com/embed/jZViOEv90dI", + "http://www.youtube-nocookie.com/embed/jZViOEv90dI", + "vnd.youtube://www.youtube.com/watch?v=jZViOEv90dI", + "vnd.youtube:jZViOEv90dI" + }) + void getId_jZViOEv90dI_fromYt(final String url) throws Exception { + assertEquals("jZViOEv90dI", linkHandler.fromUrl(url).getId()); } - @Test - public void testAcceptYtUrl() throws ParsingException { - assertTrue(linkHandler.acceptUrl("https://www.youtube.com/watch?v=jZViOEv90dI")); - assertTrue(linkHandler.acceptUrl("https://www.youtube.com/watch?v=jZViOEv90dI&t=100")); - assertTrue(linkHandler.acceptUrl("https://WWW.YouTube.com/watch?v=jZViOEv90dI&t=100")); - assertTrue(linkHandler.acceptUrl("HTTPS://www.youtube.com/watch?v=jZViOEv90dI&t=100")); - assertTrue(linkHandler.acceptUrl("https://youtu.be/jZViOEv90dI?t=9s")); - assertTrue(linkHandler.acceptUrl("https://www.youtube.com/embed/jZViOEv90dI")); - assertTrue(linkHandler.acceptUrl("https://www.youtube-nocookie.com/embed/jZViOEv90dI")); - assertTrue(linkHandler.acceptUrl("http://www.youtube.com/watch?v=jZViOEv90dI")); - assertTrue(linkHandler.acceptUrl("http://youtu.be/jZViOEv90dI?t=9s")); - assertTrue(linkHandler.acceptUrl("http://www.youtube.com/embed/jZViOEv90dI")); - assertTrue(linkHandler.acceptUrl("http://www.youtube-nocookie.com/embed/jZViOEv90dI")); - assertTrue(linkHandler.acceptUrl("http://www.youtube.com/attribution_link?a=JdfC0C9V6ZI&u=%2Fwatch%3Fv%3DEhxJLojIE_o%26feature%3Dshare")); - assertTrue(linkHandler.acceptUrl("vnd.youtube://www.youtube.com/watch?v=jZViOEv90dI")); - assertTrue(linkHandler.acceptUrl("vnd.youtube:jZViOEv90dI")); - assertTrue(linkHandler.acceptUrl("vnd.youtube.launch:jZViOEv90dI")); - assertTrue(linkHandler.acceptUrl("https://music.youtube.com/watch?v=O0EDx9WAelc")); - assertTrue(linkHandler.acceptUrl("https://www.youtube.com/shorts/IOS2fqxwYbA")); - assertTrue(linkHandler.acceptUrl("https://www.youtube.com/v/IOS2fqxwYbA")); - assertTrue(linkHandler.acceptUrl("https://www.youtube.com/w/IOS2fqxwYbA")); - assertTrue(linkHandler.acceptUrl("https://www.youtube.com/watch/IOS2fqxwYbA")); + @ParameterizedTest + @ValueSource(strings = { + "https://www.youtube.com/shorts/IOS2fqxwYbA", + "http://www.youtube.com/shorts/IOS2fqxwYbA", + "http://www.youtube.com/v/IOS2fqxwYbA", + "https://www.youtube.com/w/IOS2fqxwYbA", + "https://www.youtube.com/watch/IOS2fqxwYbA" + }) + void getId_IOS2fqxwYbA_fromYt(final String url) throws Exception { + assertEquals("IOS2fqxwYbA", linkHandler.fromUrl(url).getId()); } - @Test - public void testAcceptHookUrl() throws ParsingException { - assertTrue(linkHandler.acceptUrl("https://hooktube.com/watch?v=TglNG-yjabU")); - assertTrue(linkHandler.acceptUrl("http://hooktube.com/watch?v=TglNG-yjabU")); - assertTrue(linkHandler.acceptUrl("hooktube.com/watch?v=3msbfr6pBNE")); - assertTrue(linkHandler.acceptUrl("https://hooktube.com/watch?v=ocH3oSnZG3c&list=PLS2VU1j4vzuZwooPjV26XM9UEBY2CPNn2")); - assertTrue(linkHandler.acceptUrl("hooktube.com/watch/3msbfr6pBNE")); - assertTrue(linkHandler.acceptUrl("hooktube.com/v/3msbfr6pBNE")); - assertTrue(linkHandler.acceptUrl("hooktube.com/embed/3msbfr6pBNE")); + @ParameterizedTest + @ValueSource(strings = { + "https://m.youtube.com/watch?v=-cdveCh1kQk)", + "https://www.youtube.com/watch?v=-cdveCh1kQk-", + "https://WWW.YouTube.com/watch?v=-cdveCh1kQkwhatever", + "https://youtu.be/-cdveCh1kQk)hello", + "HTTPS://youtu.be/-cdveCh1kQk)" + }) + void getId_cdveCh1kQk_fromYt(final String url) throws Exception { + assertEquals("-cdveCh1kQk", linkHandler.fromUrl(url).getId()); } - @Test - public void testGetHookIdfromUrl() throws ParsingException { - assertEquals("TglNG-yjabU", linkHandler.fromUrl("https://hooktube.com/watch?v=TglNG-yjabU").getId()); - assertEquals("TglNG-yjabU", linkHandler.fromUrl("http://hooktube.com/watch?v=TglNG-yjabU").getId()); - assertEquals("3msbfr6pBNE", linkHandler.fromUrl("hooktube.com/watch?v=3msbfr6pBNE").getId()); - assertEquals("ocH3oSnZG3c", linkHandler.fromUrl("https://hooktube.com/watch?v=ocH3oSnZG3c&list=PLS2VU1j4vzuZwooPjV26XM9UEBY2CPNn2").getId()); - assertEquals("3msbfr6pBNE", linkHandler.fromUrl("hooktube.com/watch/3msbfr6pBNE").getId()); - assertEquals("3msbfr6pBNE", linkHandler.fromUrl("hooktube.com/v/3msbfr6pBNE").getId()); - assertEquals("3msbfr6pBNE", linkHandler.fromUrl("hooktube.com/w/3msbfr6pBNE").getId()); - assertEquals("3msbfr6pBNE", linkHandler.fromUrl("hooktube.com/embed/3msbfr6pBNE").getId()); + @ParameterizedTest + @CsvSource({ + "W-fFHeTX70Q,https://www.youtube.com/watch?v=W-fFHeTX70Q", + "uEJuoEs1UxY,http://www.youtube.com/watch_popup?v=uEJuoEs1UxY", + "uEJuoEs1UxY,http://www.Youtube.com/watch_popup?v=uEJuoEs1UxY", + "7_WWz2DSnT8,https://youtu.be/7_WWz2DSnT8", + "oy6NvWeVruY,https://m.youtube.com/watch?v=oy6NvWeVruY", + "EhxJLojIE_o,http://www.youtube.com/attribution_link?a=JdfC0C9V6ZI&u=%2Fwatch%3Fv%3DEhxJLojIE_o%26feature%3Dshare", + "n8X9_MgEdCg,vnd.youtube://n8X9_MgEdCg", + "O0EDx9WAelc,https://music.youtube.com/watch?v=O0EDx9WAelc", + "O0EDx9WAelc,HTTPS://www.youtube.com/watch?v=O0EDx9WAelc]", + "OGS7c0-CmRs,https://YouTu.be/OGS7c0-CmRswhatever)" + }) + void getId_diverse_fromYt(final String expectedId, final String url) throws Exception { + assertEquals(expectedId, linkHandler.fromUrl(url).getId()); } - @Test - public void testAcceptInvidiousUrl() throws ParsingException { - assertTrue(linkHandler.acceptUrl("https://invidio.us/watch?v=TglNG-yjabU")); - assertTrue(linkHandler.acceptUrl("http://www.invidio.us/watch?v=TglNG-yjabU")); - assertTrue(linkHandler.acceptUrl("http://invidio.us/watch?v=TglNG-yjabU")); - assertTrue(linkHandler.acceptUrl("invidio.us/watch?v=3msbfr6pBNE")); - assertTrue(linkHandler.acceptUrl("https://invidio.us/watch?v=ocH3oSnZG3c&test=PLS2VU1j4vzuZwooPjV26XM9UEBY2CPNn2")); - assertTrue(linkHandler.acceptUrl("invidio.us/embed/3msbfr6pBNE")); - assertTrue(linkHandler.acceptUrl("invidio.us/watch/3msbfr6pBNE")); - assertTrue(linkHandler.acceptUrl("invidio.us/v/3msbfr6pBNE")); - assertTrue(linkHandler.acceptUrl("invidio.us/w/3msbfr6pBNE")); + @ParameterizedTest + @ValueSource(strings = { + "https://www.youtube.com/watch?v=jZViOEv90dI", + "https://www.youtube.com/watch?v=jZViOEv90dI&t=100", + "https://WWW.YouTube.com/watch?v=jZViOEv90dI&t=100", + "HTTPS://www.youtube.com/watch?v=jZViOEv90dI&t=100", + "https://youtu.be/jZViOEv90dI?t=9s", + "https://www.youtube.com/embed/jZViOEv90dI", + "https://www.youtube-nocookie.com/embed/jZViOEv90dI", + "http://www.youtube.com/watch?v=jZViOEv90dI", + "http://youtu.be/jZViOEv90dI?t=9s", + "http://www.youtube.com/embed/jZViOEv90dI", + "http://www.youtube-nocookie.com/embed/jZViOEv90dI", + "http://www.youtube.com/attribution_link?a=JdfC0C9V6ZI&u=%2Fwatch%3Fv%3DEhxJLojIE_o%26feature%3Dshare", + "vnd.youtube://www.youtube.com/watch?v=jZViOEv90dI", + "vnd.youtube:jZViOEv90dI", + "vnd.youtube.launch:jZViOEv90dI", + "https://music.youtube.com/watch?v=O0EDx9WAelc", + "https://www.youtube.com/shorts/IOS2fqxwYbA", + "http://www.youtube.com/shorts/IOS2fqxwYbA", + "http://www.youtube.com/v/IOS2fqxwYbA", + "https://www.youtube.com/w/IOS2fqxwYbA", + "https://www.youtube.com/watch/IOS2fqxwYbA" + }) + void acceptYtUrl(final String url) throws ParsingException { + assertTrue(linkHandler.acceptUrl(url)); } - @Test - public void testGetInvidiousIdfromUrl() throws ParsingException { - assertEquals("TglNG-yjabU", linkHandler.fromUrl("https://invidio.us/watch?v=TglNG-yjabU").getId()); - assertEquals("TglNG-yjabU", linkHandler.fromUrl("http://www.invidio.us/watch?v=TglNG-yjabU").getId()); - assertEquals("TglNG-yjabU", linkHandler.fromUrl("http://invidio.us/watch?v=TglNG-yjabU").getId()); - assertEquals("3msbfr6pBNE", linkHandler.fromUrl("invidio.us/watch?v=3msbfr6pBNE").getId()); - assertEquals("ocH3oSnZG3c", linkHandler.fromUrl("https://invidio.us/watch?v=ocH3oSnZG3c&test=PLS2VU1j4vzuZwooPjV26XM9UEBY2CPNn2").getId()); - assertEquals("3msbfr6pBNE", linkHandler.fromUrl("invidio.us/embed/3msbfr6pBNE").getId()); - assertEquals("3msbfr6pBNE", linkHandler.fromUrl("invidio.us/v/3msbfr6pBNE").getId()); - assertEquals("3msbfr6pBNE", linkHandler.fromUrl("invidio.us/w/3msbfr6pBNE").getId()); - assertEquals("3msbfr6pBNE", linkHandler.fromUrl("invidio.us/watch/3msbfr6pBNE").getId()); + @ParameterizedTest + @ValueSource(strings = { + "https://hooktube.com/watch?v=TglNG-yjabU", + "http://hooktube.com/watch?v=TglNG-yjabU", + "https://hooktube.com/watch?v=ocH3oSnZG3c&test=PLS2VU1j4vzuZwooPjV26XM9UEBY2CPNn2", + "hooktube.com/watch?v=3msbfr6pBNE", + "hooktube.com/watch/3msbfr6pBNE", + "hooktube.com/v/3msbfr6pBNE", + "hooktube.com/embed/3msbfr6pBNE" + }) + void acceptHookUrl(final String url) throws ParsingException { + assertTrue(linkHandler.acceptUrl(url)); + } + + @ParameterizedTest + @CsvSource({ + "TglNG-yjabU,https://hooktube.com/watch?v=TglNG-yjabU", + "TglNG-yjabU,http://hooktube.com/watch?v=TglNG-yjabU", + "ocH3oSnZG3c,https://hooktube.com/watch?v=ocH3oSnZG3c&test=PLS2VU1j4vzuZwooPjV26XM9UEBY2CPNn2", + "3msbfr6pBNE,hooktube.com/watch?v=3msbfr6pBNE", + "3msbfr6pBNE,hooktube.com/watch/3msbfr6pBNE", + "3msbfr6pBNE,hooktube.com/v/3msbfr6pBNE", + "3msbfr6pBNE,hooktube.com/w/3msbfr6pBNE", + "3msbfr6pBNE,hooktube.com/embed/3msbfr6pBNE" + }) + void getHookIdfromUrl(final String expectedId, final String url) throws Exception { + assertEquals(expectedId, linkHandler.fromUrl(url).getId()); + } + + @ParameterizedTest + @ValueSource(strings = { + "https://invidious.fdn.fr/watch?v=TglNG-yjabU", + "http://www.invidio.us/watch?v=TglNG-yjabU", + "http://invidious.fdn.fr/watch?v=TglNG-yjabU", + "invidious.fdn.fr/watch?v=3msbfr6pBNE", + "https://invidious.fdn.fr/watch?v=ocH3oSnZG3c&test=PLS2VU1j4vzuZwooPjV26XM9UEBY2CPNn2", + "invidious.fdn.fr/embed/3msbfr6pBNE", + "invidious.fdn.fr/watch/3msbfr6pBNE", + "invidious.fdn.fr/v/3msbfr6pBNE", + "invidious.fdn.fr/w/3msbfr6pBNE" + }) + void acceptInvidiousUrl(final String url) throws ParsingException { + assertTrue(linkHandler.acceptUrl(url)); + } + + @ParameterizedTest + @CsvSource({ + "TglNG-yjabU,https://invidious.fdn.fr/watch?v=TglNG-yjabU", + "TglNG-yjabU,http://www.invidio.us/watch?v=TglNG-yjabU", + "TglNG-yjabU,http://invidious.fdn.fr/watch?v=TglNG-yjabU", + "ocH3oSnZG3c,https://invidious.fdn.fr/watch?v=ocH3oSnZG3c&test=PLS2VU1j4vzuZwooPjV26XM9UEBY2CPNn2", + "3msbfr6pBNE,invidious.fdn.fr/watch?v=3msbfr6pBNE", + "3msbfr6pBNE,invidious.fdn.fr/embed/3msbfr6pBNE", + "3msbfr6pBNE,invidious.fdn.fr/v/3msbfr6pBNE", + "3msbfr6pBNE,invidious.fdn.fr/w/3msbfr6pBNE", + "3msbfr6pBNE,invidious.fdn.fr/watch/3msbfr6pBNE" + }) + void getInvidiousIdfromUrl(final String expectedId, final String url) throws Exception { + assertEquals(expectedId, linkHandler.fromUrl(url).getId()); } } \ No newline at end of file