From 8dabda293b7776521e902d6db755dbded81b9bed Mon Sep 17 00:00:00 2001 From: Christian Schabesberger Date: Sat, 12 Aug 2017 23:03:34 +0200 Subject: [PATCH] add test for YoutubeTrendingUrlIdHandler --- .../youtube/YoutubeTrendingUrlIdHandler.java | 3 +- .../YoutubeSuggestionExtractorTest.java | 24 +++--- .../youtube/YoutubeTrendingExtractorTest.java | 4 + .../YoutubeTrendingUrlIdHandlerTest.java | 76 +++++++++++++++++++ 4 files changed, 94 insertions(+), 13 deletions(-) create mode 100644 src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeTrendingExtractorTest.java create mode 100644 src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeTrendingUrlIdHandlerTest.java diff --git a/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeTrendingUrlIdHandler.java b/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeTrendingUrlIdHandler.java index d6083459f..63a35181e 100644 --- a/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeTrendingUrlIdHandler.java +++ b/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeTrendingUrlIdHandler.java @@ -21,6 +21,7 @@ package org.schabi.newpipe.extractor.services.youtube; */ import org.schabi.newpipe.extractor.UrlIdHandler; +import org.schabi.newpipe.extractor.utils.Parser; public class YoutubeTrendingUrlIdHandler implements UrlIdHandler { @@ -40,6 +41,6 @@ public class YoutubeTrendingUrlIdHandler implements UrlIdHandler { @Override public boolean acceptUrl(String url) { - return url.contains("feed/treinding"); + return Parser.isMatch("^(https://|http://|)(www.|m.|)youtube.com/feed/trending(|\\?.*)$", url); } } diff --git a/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeSuggestionExtractorTest.java b/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeSuggestionExtractorTest.java index 58089081c..39caa42c7 100644 --- a/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeSuggestionExtractorTest.java +++ b/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeSuggestionExtractorTest.java @@ -1,17 +1,5 @@ package org.schabi.newpipe.extractor.services.youtube; -import org.junit.Before; -import org.junit.Test; -import org.schabi.newpipe.Downloader; -import org.schabi.newpipe.extractor.NewPipe; -import org.schabi.newpipe.extractor.SuggestionExtractor; -import org.schabi.newpipe.extractor.exceptions.ExtractionException; - -import java.io.IOException; - -import static org.junit.Assert.assertFalse; -import static org.schabi.newpipe.extractor.ServiceList.YouTube; - /* * Created by Christian Schabesberger on 18.11.16. * @@ -32,6 +20,18 @@ import static org.schabi.newpipe.extractor.ServiceList.YouTube; * along with NewPipe. If not, see . */ +import org.junit.Before; +import org.junit.Test; +import org.schabi.newpipe.Downloader; +import org.schabi.newpipe.extractor.NewPipe; +import org.schabi.newpipe.extractor.SuggestionExtractor; +import org.schabi.newpipe.extractor.exceptions.ExtractionException; + +import java.io.IOException; + +import static org.junit.Assert.assertFalse; +import static org.schabi.newpipe.extractor.ServiceList.YouTube; + /** * Test for {@link SuggestionExtractor} */ diff --git a/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeTrendingExtractorTest.java b/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeTrendingExtractorTest.java new file mode 100644 index 000000000..70e536cf2 --- /dev/null +++ b/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeTrendingExtractorTest.java @@ -0,0 +1,4 @@ +package org.schabi.newpipe.extractor.services.youtube; + +public class YoutubeTrendingExtractorTest { +} diff --git a/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeTrendingUrlIdHandlerTest.java b/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeTrendingUrlIdHandlerTest.java new file mode 100644 index 000000000..feca28c4b --- /dev/null +++ b/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeTrendingUrlIdHandlerTest.java @@ -0,0 +1,76 @@ +package org.schabi.newpipe.extractor.services.youtube; + +/* + * Created by Christian Schabesberger on 12.08.17. + * + * Copyright (C) Christian Schabesberger 2017 + * YoutubeTrendingUrlIdHandlerTest.java is part of NewPipe. + * + * NewPipe is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * NewPipe is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with NewPipe. If not, see . + */ + +import org.junit.Before; +import org.junit.Test; +import org.schabi.newpipe.Downloader; +import org.schabi.newpipe.extractor.NewPipe; + +import static junit.framework.TestCase.assertFalse; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +/** + * Test for {@link YoutubeTrendingUrlIdHandler} + */ +public class YoutubeTrendingUrlIdHandlerTest { + private YoutubeTrendingUrlIdHandler urlIdHandler; + + @Before + public void setUp() throws Exception { + urlIdHandler = new YoutubeTrendingUrlIdHandler(); + NewPipe.init(Downloader.getInstance()); + } + + @Test + public void getUrl() { + assertEquals(urlIdHandler.getUrl(""), "https://www.youtube.com/feed/trending"); + } + + @Test + public void getId() { + assertEquals(urlIdHandler.getId(""), "Trending"); + } + + @Test + public void acceptUrl() { + assertTrue(urlIdHandler.acceptUrl("https://www.youtube.com/feed/trending")); + assertTrue(urlIdHandler.acceptUrl("https://www.youtube.com/feed/trending?adsf=fjaj#fhe")); + assertTrue(urlIdHandler.acceptUrl("http://www.youtube.com/feed/trending")); + assertTrue(urlIdHandler.acceptUrl("www.youtube.com/feed/trending")); + assertTrue(urlIdHandler.acceptUrl("youtube.com/feed/trending")); + assertTrue(urlIdHandler.acceptUrl("youtube.com/feed/trending?akdsakjf=dfije&kfj=dkjak")); + assertTrue(urlIdHandler.acceptUrl("https://youtube.com/feed/trending")); + assertTrue(urlIdHandler.acceptUrl("m.youtube.com/feed/trending")); + + assertFalse(urlIdHandler.acceptUrl("https://youtu.be/feed/trending")); + assertFalse(urlIdHandler.acceptUrl("kdskjfiiejfia")); + assertFalse(urlIdHandler.acceptUrl("https://www.youtube.com/bullshit/feed/trending")); + assertFalse(urlIdHandler.acceptUrl("https://www.youtube.com/feed/trending/bullshit")); + assertFalse(urlIdHandler.acceptUrl("https://www.youtube.com/feed/bullshit/trending")); + assertFalse(urlIdHandler.acceptUrl("peter klaut aepferl youtube.com/feed/trending")); + assertFalse(urlIdHandler.acceptUrl("youtube.com/feed/trending askjkf")); + assertFalse(urlIdHandler.acceptUrl("askdjfi youtube.com/feed/trending askjkf")); + assertFalse(urlIdHandler.acceptUrl(" youtube.com/feed/trending")); + assertFalse(urlIdHandler.acceptUrl("")); + } +}