add test for YoutubeTrendingUrlIdHandler
This commit is contained in:
parent
b89f5a9b42
commit
8dabda293b
4 changed files with 94 additions and 13 deletions
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
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}
|
||||
*/
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
package org.schabi.newpipe.extractor.services.youtube;
|
||||
|
||||
public class YoutubeTrendingExtractorTest {
|
||||
}
|
|
@ -0,0 +1,76 @@
|
|||
package org.schabi.newpipe.extractor.services.youtube;
|
||||
|
||||
/*
|
||||
* Created by Christian Schabesberger on 12.08.17.
|
||||
*
|
||||
* Copyright (C) Christian Schabesberger 2017 <chris.schabesberger@mailbox.org>
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
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(""));
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue