|
| 1 | +package org.schabi.newpipe.extractor.services.youtube; |
| 2 | + |
| 3 | +import org.junit.BeforeClass; |
| 4 | +import org.junit.Test; |
| 5 | +import org.schabi.newpipe.DownloaderTestImpl; |
| 6 | +import org.schabi.newpipe.extractor.NewPipe; |
| 7 | +import org.schabi.newpipe.extractor.exceptions.ParsingException; |
| 8 | +import org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubeCommentsLinkHandlerFactory; |
| 9 | + |
| 10 | +import static org.junit.Assert.assertEquals; |
| 11 | +import static org.junit.Assert.assertFalse; |
| 12 | +import static org.junit.Assert.assertTrue; |
| 13 | + |
| 14 | +public class YouTubeCommentsLinkHandlerFactoryTest { |
| 15 | + |
| 16 | + private static YoutubeCommentsLinkHandlerFactory linkHandler; |
| 17 | + |
| 18 | + @BeforeClass |
| 19 | + public static void setUp() { |
| 20 | + NewPipe.init(DownloaderTestImpl.getInstance()); |
| 21 | + linkHandler = YoutubeCommentsLinkHandlerFactory.getInstance(); |
| 22 | + } |
| 23 | + |
| 24 | + @Test(expected = IllegalArgumentException.class) |
| 25 | + public void getIdWithNullAsUrl() throws ParsingException { |
| 26 | + linkHandler.fromId(null); |
| 27 | + } |
| 28 | + |
| 29 | + @Test |
| 30 | + public void getIdFromYt() throws ParsingException { |
| 31 | + assertEquals("VM_6n762j6M", linkHandler.fromUrl("https://www.youtube.com/watch?v=VM_6n762j6M").getId()); |
| 32 | + assertEquals("VM_6n762j6M", linkHandler.fromUrl("https://m.youtube.com/watch?v=VM_6n762j6M").getId()); |
| 33 | + assertEquals("VM_6n762j6M", linkHandler.fromUrl("https://youtube.com/watch?v=VM_6n762j6M").getId()); |
| 34 | + assertEquals("VM_6n762j6M", linkHandler.fromUrl("https://WWW.youtube.com/watch?v=VM_6n762j6M").getId()); |
| 35 | + assertEquals("VM_6n762j6M", linkHandler.fromUrl("https://youtu.be/VM_6n762j6M").getId()); |
| 36 | + assertEquals("VM_6n762j6M", linkHandler.fromUrl("https://youtu.be/VM_6n762j6M&t=20").getId()); |
| 37 | + } |
| 38 | + |
| 39 | + @Test |
| 40 | + public void testAcceptUrl() throws ParsingException { |
| 41 | + assertTrue(linkHandler.acceptUrl("https://www.youtube.com/watch?v=VM_6n762j6M&t=20")); |
| 42 | + assertTrue(linkHandler.acceptUrl("https://WWW.youtube.com/watch?v=VM_6n762j6M&t=20")); |
| 43 | + assertTrue(linkHandler.acceptUrl("https://youtube.com/watch?v=VM_6n762j6M&t=20")); |
| 44 | + assertTrue(linkHandler.acceptUrl("https://youtu.be/VM_6n762j6M&t=20")); |
| 45 | + } |
| 46 | + |
| 47 | + @Test |
| 48 | + public void testDeniesUrl() throws ParsingException { |
| 49 | + assertFalse(linkHandler.acceptUrl("https://www.you com/watch?v=VM_6n762j6M")); |
| 50 | + assertFalse(linkHandler.acceptUrl("https://com/watch?v=VM_6n762j6M")); |
| 51 | + assertFalse(linkHandler.acceptUrl("htt ://com/watch?v=VM_6n762j6M")); |
| 52 | + assertFalse(linkHandler.acceptUrl("ftp://www.youtube.com/watch?v=VM_6n762j6M")); |
| 53 | + } |
| 54 | + |
| 55 | + @Test |
| 56 | + public void getIdFromInvidious() throws ParsingException { |
| 57 | + assertEquals("VM_6n762j6M", linkHandler.fromUrl("https://www.invidio.us/watch?v=VM_6n762j6M").getId()); |
| 58 | + assertEquals("VM_6n762j6M", linkHandler.fromUrl("https://invidio.us/watch?v=VM_6n762j6M").getId()); |
| 59 | + assertEquals("VM_6n762j6M", linkHandler.fromUrl("https://INVIDIO.US/watch?v=VM_6n762j6M").getId()); |
| 60 | + assertEquals("VM_6n762j6M", linkHandler.fromUrl("https://invidio.us/VM_6n762j6M").getId()); |
| 61 | + assertEquals("VM_6n762j6M", linkHandler.fromUrl("https://invidio.us/VM_6n762j6M&t=20").getId()); |
| 62 | + } |
| 63 | + |
| 64 | +} |
0 commit comments