Skip to content

Commit 82eff77

Browse files
authored
Merge pull request #234 from TeamNewPipe/fix/YT_search_test
Fix and improve tests
2 parents 51fd9ba + 2308b07 commit 82eff77

6 files changed

Lines changed: 20 additions & 48 deletions

File tree

extractor/src/main/java/org/schabi/newpipe/extractor/linkhandler/LinkHandlerFactory.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public abstract class LinkHandlerFactory {
3434
public abstract String getUrl(String id) throws ParsingException;
3535
public abstract boolean onAcceptUrl(final String url) throws ParsingException;
3636

37-
public String getUrl(String id, String baseUrl) throws ParsingException{
37+
public String getUrl(String id, String baseUrl) throws ParsingException {
3838
return getUrl(id);
3939
}
4040

@@ -43,13 +43,14 @@ public String getUrl(String id, String baseUrl) throws ParsingException{
4343
///////////////////////////////////
4444

4545
public LinkHandler fromUrl(String url) throws ParsingException {
46+
if (url == null) throw new IllegalArgumentException("url can not be null");
4647
final String baseUrl = Utils.getBaseUrl(url);
4748
return fromUrl(url, baseUrl);
4849
}
4950

5051
public LinkHandler fromUrl(String url, String baseUrl) throws ParsingException {
51-
if(url == null) throw new IllegalArgumentException("url can not be null");
52-
if(!acceptUrl(url)) {
52+
if (url == null) throw new IllegalArgumentException("url can not be null");
53+
if (!acceptUrl(url)) {
5354
throw new ParsingException("Malformed unacceptable url: " + url);
5455
}
5556

@@ -58,13 +59,13 @@ public LinkHandler fromUrl(String url, String baseUrl) throws ParsingException {
5859
}
5960

6061
public LinkHandler fromId(String id) throws ParsingException {
61-
if(id == null) throw new IllegalArgumentException("id can not be null");
62+
if (id == null) throw new IllegalArgumentException("id can not be null");
6263
final String url = getUrl(id);
6364
return new LinkHandler(url, url, id);
6465
}
6566

6667
public LinkHandler fromId(String id, String baseUrl) throws ParsingException {
67-
if(id == null) throw new IllegalArgumentException("id can not be null");
68+
if (id == null) throw new IllegalArgumentException("id can not be null");
6869
final String url = getUrl(id, baseUrl);
6970
return new LinkHandler(url, url, id);
7071
}

extractor/src/test/java/org/schabi/newpipe/extractor/services/media_ccc/MediaCCCStreamExtractorTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ public void testAudioStreams() throws Exception {
8989

9090
@Test
9191
public void testGetTextualUploadDate() throws ParsingException {
92-
Assert.assertEquals("2018-05-11", extractor.getTextualUploadDate());
92+
Assert.assertEquals("2018-05-11T02:00:00.000+02:00", extractor.getTextualUploadDate());
9393
}
9494

9595
@Test

extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeStreamLinkHandlerFactoryTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ public void getIdfromYt() throws Exception {
7777
assertEquals("jZViOEv90dI", linkHandler.fromUrl("http://www.Youtube.com/embed/jZViOEv90dI").getId());
7878
assertEquals("jZViOEv90dI", linkHandler.fromUrl("http://www.youtube-nocookie.com/embed/jZViOEv90dI").getId());
7979
assertEquals("EhxJLojIE_o", linkHandler.fromUrl("http://www.youtube.com/attribution_link?a=JdfC0C9V6ZI&u=%2Fwatch%3Fv%3DEhxJLojIE_o%26feature%3Dshare").getId());
80-
assertEquals("jZViOEv90dI", linkHandler.fromUrl("vnd.youtube://www.youtube.com/watch?v=jZViOEv90dI").getId());
81-
assertEquals("jZViOEv90dI", linkHandler.fromUrl("vnd.youtube:jZViOEv90dI").getId());
80+
assertEquals("jZViOEv90dI", linkHandler.fromUrl("vnd.youtube://www.youtube.com/watch?v=jZViOEv90dI", "youtube.com").getId());
81+
assertEquals("jZViOEv90dI", linkHandler.fromUrl("vnd.youtube:jZViOEv90dI", "youtube.com").getId());
8282
assertEquals("O0EDx9WAelc", linkHandler.fromUrl("https://music.youtube.com/watch?v=O0EDx9WAelc").getId());
8383
}
8484

extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/search/YoutubeSearchCountTest.java

Lines changed: 0 additions & 36 deletions
This file was deleted.

extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/search/YoutubeSearchExtractorChannelOnlyTest.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public void testGetSecondPage() throws Exception {
3939
boolean equals = true;
4040
for (int i = 0; i < secondPage.getItems().size()
4141
&& i < itemsPage.getItems().size(); i++) {
42-
if(!secondPage.getItems().get(i).getUrl().equals(
42+
if (!secondPage.getItems().get(i).getUrl().equals(
4343
itemsPage.getItems().get(i).getUrl())) {
4444
equals = false;
4545
}
@@ -58,7 +58,7 @@ public void testGetSecondPageUrl() throws Exception {
5858
@Test
5959
public void testOnlyContainChannels() {
6060
for(InfoItem item : itemsPage.getItems()) {
61-
if(!(item instanceof ChannelInfoItem)) {
61+
if (!(item instanceof ChannelInfoItem)) {
6262
fail("The following item is no channel item: " + item.toString());
6363
}
6464
}
@@ -78,4 +78,11 @@ public void testChannelUrl() {
7878
}
7979
}
8080
}
81+
82+
@Test
83+
public void testStreamCount() {
84+
ChannelInfoItem ci = (ChannelInfoItem) itemsPage.getItems().get(0);
85+
assertTrue("Stream count does not fit: " + ci.getStreamCount(),
86+
4000 < ci.getStreamCount() && ci.getStreamCount() < 5500);
87+
}
8188
}

extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/stream/YoutubeStreamExtractorControversialTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,13 +122,13 @@ public void testGetVideoStreams() throws IOException, ExtractionException {
122122

123123
@Test
124124
public void testGetSubtitlesListDefault() throws IOException, ExtractionException {
125-
// Video (/view?v=YQHsXMglC9A) set in the setUp() method has no captions => null
125+
// Video (/view?v=T4XJQO3qol8) set in the setUp() method has at least auto-generated (English) captions
126126
assertFalse(extractor.getSubtitlesDefault().isEmpty());
127127
}
128128

129129
@Test
130130
public void testGetSubtitlesList() throws IOException, ExtractionException {
131-
// Video (/view?v=YQHsXMglC9A) set in the setUp() method has no captions => null
131+
// Video (/view?v=T4XJQO3qol8) set in the setUp() method has at least auto-generated (English) captions
132132
assertFalse(extractor.getSubtitles(MediaFormat.TTML).isEmpty());
133133
}
134134
}

0 commit comments

Comments
 (0)