Skip to content

Commit f76cc49

Browse files
committed
Fix channel info item collector
1 parent 4f62d96 commit f76cc49

6 files changed

Lines changed: 47 additions & 8 deletions

File tree

src/main/java/org/schabi/newpipe/extractor/channel/ChannelInfoItemCollector.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public ChannelInfoItem extract(ChannelInfoItemExtractor extractor) throws Parsin
3535
String name = extractor.getName();
3636
String url = extractor.getUrl();
3737

38-
ChannelInfoItem resultItem = new ChannelInfoItem(serviceId, name, url);
38+
ChannelInfoItem resultItem = new ChannelInfoItem(serviceId, url, name);
3939

4040

4141
// optional information

src/test/java/org/schabi/newpipe/extractor/ExtractorAsserts.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package org.schabi.newpipe.extractor;
22

3+
import java.net.MalformedURLException;
4+
import java.net.URL;
35
import java.util.List;
46

57
public class ExtractorAsserts {
@@ -11,4 +13,12 @@ public static void assertEmptyErrors(String message, List<Throwable> errors) {
1113
throw new AssertionError(message, errors.get(0));
1214
}
1315
}
16+
17+
public static void assertIsValidUrl(String url) {
18+
try {
19+
new URL(url);
20+
} catch (MalformedURLException e) {
21+
throw new AssertionError("Invalid url: " + url, e);
22+
}
23+
}
1424
}

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

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,18 @@
44
import org.junit.Ignore;
55
import org.junit.Test;
66
import org.schabi.newpipe.Downloader;
7+
import org.schabi.newpipe.extractor.InfoItem;
78
import org.schabi.newpipe.extractor.NewPipe;
9+
import org.schabi.newpipe.extractor.channel.ChannelInfoItem;
810
import org.schabi.newpipe.extractor.search.SearchEngine;
911
import org.schabi.newpipe.extractor.search.SearchResult;
1012

11-
import static org.junit.Assert.assertFalse;
12-
import static org.junit.Assert.assertTrue;
13+
import java.net.MalformedURLException;
14+
import java.net.URL;
15+
import java.util.List;
16+
17+
import static org.junit.Assert.*;
18+
import static org.schabi.newpipe.extractor.ExtractorAsserts.assertIsValidUrl;
1319

1420
/*
1521
* Created by Christian Schabesberger on 29.12.15.
@@ -42,16 +48,27 @@ public static void setUpClass() throws Exception {
4248
NewPipe.init(Downloader.getInstance());
4349
YoutubeSearchEngine engine = new YoutubeSearchEngine(1);
4450

45-
// Youtube will suggest "asdf" instead of "asdgff"
46-
// keep in mind that the suggestions can change by country (the parameter "de")
47-
result = engine.search("asdgff", 0, "de", SearchEngine.Filter.ANY)
51+
result = engine.search("pewdiepie", 0, "de", SearchEngine.Filter.ANY)
4852
.getSearchResult();
4953
}
5054

5155
@Test
5256
public void testResultList() {
53-
System.out.println("Results: " + result.getResults());
54-
assertFalse("Results are empty: " + result.resultList, result.resultList.isEmpty());
57+
final List<InfoItem> results = result.getResults();
58+
System.out.println("Results: " + results);
59+
assertFalse("Results are empty: " + results, results.isEmpty());
60+
61+
InfoItem firstInfoItem = results.get(0);
62+
63+
// THe channel should be the first item
64+
assertTrue(firstInfoItem instanceof ChannelInfoItem);
65+
assertEquals("name", "PewDiePie", firstInfoItem.name);
66+
assertEquals("url","https://www.youtube.com/user/PewDiePie", firstInfoItem.url);
67+
68+
for(InfoItem item: results) {
69+
assertIsValidUrl(item.url);
70+
}
71+
5572
}
5673

5774
@Test

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import org.schabi.newpipe.extractor.search.SearchResult;
1111

1212
import static org.junit.Assert.*;
13+
import static org.schabi.newpipe.extractor.ExtractorAsserts.assertIsValidUrl;
1314
import static org.schabi.newpipe.extractor.ServiceList.YouTube;
1415

1516

@@ -53,6 +54,9 @@ public void setUp() throws Exception {
5354
@Test
5455
public void testResultList() {
5556
assertFalse(result.resultList.isEmpty());
57+
for(InfoItem item: result.getResults()) {
58+
assertIsValidUrl(item.url);
59+
}
5660
}
5761

5862
@Test

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import org.schabi.newpipe.extractor.search.SearchResult;
1111

1212
import static org.junit.Assert.*;
13+
import static org.schabi.newpipe.extractor.ExtractorAsserts.assertIsValidUrl;
1314
import static org.schabi.newpipe.extractor.ServiceList.YouTube;
1415

1516

@@ -53,6 +54,9 @@ public void setUp() throws Exception {
5354
@Test
5455
public void testResultList() {
5556
assertFalse(result.resultList.isEmpty());
57+
for(InfoItem item: result.getResults()) {
58+
assertIsValidUrl(item.url);
59+
}
5660
}
5761

5862
@Test

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import org.schabi.newpipe.extractor.search.SearchResult;
1111

1212
import static org.junit.Assert.*;
13+
import static org.schabi.newpipe.extractor.ExtractorAsserts.assertIsValidUrl;
1314
import static org.schabi.newpipe.extractor.ServiceList.YouTube;
1415

1516

@@ -53,6 +54,9 @@ public void setUp() throws Exception {
5354
@Test
5455
public void testResultList() {
5556
assertFalse(result.resultList.isEmpty());
57+
for(InfoItem item: result.getResults()) {
58+
assertIsValidUrl(item.url);
59+
}
5660
}
5761

5862
@Test

0 commit comments

Comments
 (0)