Skip to content

Commit 0eaca52

Browse files
committed
Add test for subscription with invalid url.
Also modified the test for empty title, since now subscriptions with empty title are not ignored anymore.
1 parent 171f2c4 commit 0eaca52

1 file changed

Lines changed: 20 additions & 14 deletions

File tree

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

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -61,19 +61,28 @@ public void testEmptySourceException() throws Exception {
6161

6262
@Test
6363
public void testSubscriptionWithEmptyTitleInSource() throws Exception {
64-
String channelName = "NAME OF CHANNEL";
65-
String emptySource = "<opml version=\"1.1\"><body><outline text=\"YouTube Subscriptions\" title=\"YouTube Subscriptions\">" +
66-
67-
"<outline text=\"\" title=\"\" type=\"rss\" xmlUrl=\"https://www.youtube.com/feeds/videos.xml?channel_id=AA0AaAa0AaaaAAAAAA0aa0AA\" />" +
64+
String channelId = "AA0AaAa0AaaaAAAAAA0aa0AA";
65+
String source = "<opml version=\"1.1\"><body><outline text=\"YouTube Subscriptions\" title=\"YouTube Subscriptions\">" +
66+
"<outline text=\"\" title=\"\" type=\"rss\" xmlUrl=\"https://www.youtube.com/feeds/videos.xml?channel_id=" + channelId + "\" />" +
67+
"</outline></body></opml>";
6868

69-
"<outline text=\"" + channelName + "\" title=\"" + channelName +
70-
"\" type=\"rss\" xmlUrl=\"https://www.youtube.com/feeds/videos.xml?channel_id=AA0AaAa0AaaaAAAAAA0aa0AA\" />" +
69+
List<SubscriptionItem> items = subscriptionExtractor.fromInputStream(new ByteArrayInputStream(source.getBytes("UTF-8")));
70+
assertTrue("List doesn't have exactly 1 item (had " + items.size() + ")", items.size() == 1);
71+
assertTrue("Item does not have an empty title (had \"" + items.get(0).getName() + "\")", items.get(0).getName().isEmpty());
72+
assertTrue("Item does not have the right channel id \"" + channelId + "\" (the whole url is \"" + items.get(0).getUrl() + "\")", items.get(0).getUrl().endsWith(channelId));
73+
}
7174

75+
@Test
76+
public void testSubscriptionWithInvalidUrlInSource() throws Exception {
77+
String source = "<opml version=\"1.1\"><body><outline text=\"YouTube Subscriptions\" title=\"YouTube Subscriptions\">" +
78+
"<outline text=\"invalid\" title=\"url\" type=\"rss\" xmlUrl=\"https://www.youtube.com/feeds/videos.xml?channel_not_id=|||||||\"/>" +
79+
"<outline text=\"fail\" title=\"fail\" type=\"rss\" xmlUgrl=\"invalidTag\"/>" +
80+
"<outline text=\"invalid\" title=\"url\" type=\"rss\" xmlUrl=\"\"/>" +
81+
"<outline text=\"\" title=\"\" type=\"rss\" xmlUrl=\"\"/>" +
7282
"</outline></body></opml>";
7383

74-
List<SubscriptionItem> items = subscriptionExtractor.fromInputStream(new ByteArrayInputStream(emptySource.getBytes("UTF-8")));
75-
assertTrue("List doesn't have exactly 1 item (had " + items.size() + ")", items.size() == 1);
76-
assertTrue("Item does not have the right title \"" + channelName + "\" (had \"" + items.get(0).getName() + "\")", items.get(0).getName().equals(channelName));
84+
List<SubscriptionItem> items = subscriptionExtractor.fromInputStream(new ByteArrayInputStream(source.getBytes("UTF-8")));
85+
assertTrue(items.isEmpty());
7786
}
7887

7988
@Test
@@ -82,9 +91,6 @@ public void testInvalidSourceException() {
8291
"<xml><notvalid></notvalid></xml>",
8392
"<opml><notvalid></notvalid></opml>",
8493
"<opml><body></body></opml>",
85-
"<opml><body><outline text=\"fail\" title=\"fail\" type=\"rss\" xmlUgrl=\"invalidTag\"/></outline></body></opml>",
86-
"<opml><body><outline><outline text=\"invalid\" title=\"url\" type=\"rss\"" +
87-
" xmlUrl=\"https://www.youtube.com/feeds/videos.xml?channel_not_id=|||||||\"/></outline></body></opml>",
8894
"",
8995
null,
9096
"\uD83D\uDC28\uD83D\uDC28\uD83D\uDC28",
@@ -95,11 +101,11 @@ public void testInvalidSourceException() {
95101
if (invalidContent != null) {
96102
byte[] bytes = invalidContent.getBytes("UTF-8");
97103
subscriptionExtractor.fromInputStream(new ByteArrayInputStream(bytes));
104+
fail("Extracting from \"" + invalidContent + "\" didn't throw an exception");
98105
} else {
99106
subscriptionExtractor.fromInputStream(null);
107+
fail("Extracting from null String didn't throw an exception");
100108
}
101-
102-
fail("didn't throw exception");
103109
} catch (Exception e) {
104110
// System.out.println(" -> " + e);
105111
boolean isExpectedException = e instanceof SubscriptionExtractor.InvalidSourceException;

0 commit comments

Comments
 (0)