|
18 | 18 | import static org.schabi.newpipe.extractor.ServiceList.PeerTube; |
19 | 19 |
|
20 | 20 | public class PeertubeCommentsExtractorTest { |
| 21 | + public static class Default { |
| 22 | + private static PeertubeCommentsExtractor extractor; |
21 | 23 |
|
22 | | - private static PeertubeCommentsExtractor extractor; |
| 24 | + @BeforeClass |
| 25 | + public static void setUp() throws Exception { |
| 26 | + NewPipe.init(DownloaderTestImpl.getInstance()); |
| 27 | + extractor = (PeertubeCommentsExtractor) PeerTube |
| 28 | + .getCommentsExtractor("https://framatube.org/videos/watch/04af977f-4201-4697-be67-a8d8cae6fa7a"); |
| 29 | + } |
23 | 30 |
|
24 | | - @BeforeClass |
25 | | - public static void setUp() throws Exception { |
26 | | - NewPipe.init(DownloaderTestImpl.getInstance()); |
27 | | - extractor = (PeertubeCommentsExtractor) PeerTube |
28 | | - .getCommentsExtractor("https://framatube.org/videos/watch/04af977f-4201-4697-be67-a8d8cae6fa7a"); |
29 | | - } |
| 31 | + @Test |
| 32 | + public void testGetComments() throws IOException, ExtractionException { |
| 33 | + InfoItemsPage<CommentsInfoItem> comments = extractor.getInitialPage(); |
| 34 | + assertTrue(comments.getErrors().isEmpty()); |
30 | 35 |
|
31 | | - @Test |
32 | | - public void testGetComments() throws IOException, ExtractionException { |
33 | | - boolean result = false; |
34 | | - InfoItemsPage<CommentsInfoItem> comments = extractor.getInitialPage(); |
35 | | - result = findInComments(comments, "@root A great documentary on a great guy."); |
| 36 | + boolean result = findInComments(comments, "@root A great documentary on a great guy."); |
| 37 | + while (comments.hasNextPage() && !result) { |
| 38 | + comments = extractor.getPage(comments.getNextPageUrl()); |
| 39 | + result = findInComments(comments, "@root A great documentary on a great guy."); |
| 40 | + } |
36 | 41 |
|
37 | | - while (comments.hasNextPage() && !result) { |
38 | | - comments = extractor.getPage(comments.getNextPageUrl()); |
39 | | - result = findInComments(comments, "@root A great documentary on a great guy."); |
| 42 | + assertTrue(result); |
40 | 43 | } |
41 | 44 |
|
42 | | - assertTrue(result); |
43 | | - } |
| 45 | + @Test |
| 46 | + public void testGetCommentsFromCommentsInfo() throws IOException, ExtractionException { |
| 47 | + final CommentsInfo commentsInfo = CommentsInfo.getInfo("https://framatube.org/videos/watch/a8ea95b8-0396-49a6-8f30-e25e25fb2828"); |
| 48 | + assertTrue(commentsInfo.getErrors().isEmpty()); |
| 49 | + assertEquals("Comments", commentsInfo.getName()); |
44 | 50 |
|
45 | | - @Test |
46 | | - public void testGetCommentsFromCommentsInfo() throws IOException, ExtractionException { |
47 | | - boolean result = false; |
48 | | - CommentsInfo commentsInfo = CommentsInfo.getInfo("https://framatube.org/videos/watch/a8ea95b8-0396-49a6-8f30-e25e25fb2828"); |
49 | | - assertEquals("Comments", commentsInfo.getName()); |
50 | | - result = findInComments(commentsInfo.getRelatedItems(), "Loved it!!!"); |
51 | | - |
52 | | - String nextPage = commentsInfo.getNextPageUrl(); |
53 | | - while (!Utils.isBlank(nextPage) && !result) { |
54 | | - InfoItemsPage<CommentsInfoItem> moreItems = CommentsInfo.getMoreItems(PeerTube, commentsInfo, nextPage); |
55 | | - result = findInComments(moreItems.getItems(), "Loved it!!!"); |
56 | | - nextPage = moreItems.getNextPageUrl(); |
| 51 | + boolean result = findInComments(commentsInfo.getRelatedItems(), "Loved it!!!"); |
| 52 | + String nextPage = commentsInfo.getNextPageUrl(); |
| 53 | + while (!Utils.isBlank(nextPage) && !result) { |
| 54 | + final InfoItemsPage<CommentsInfoItem> moreItems = CommentsInfo.getMoreItems(PeerTube, commentsInfo, nextPage); |
| 55 | + result = findInComments(moreItems.getItems(), "Loved it!!!"); |
| 56 | + nextPage = moreItems.getNextPageUrl(); |
| 57 | + } |
| 58 | + assertTrue(result); |
57 | 59 | } |
58 | 60 |
|
59 | | - assertTrue(result); |
60 | | - } |
| 61 | + @Test |
| 62 | + public void testGetCommentsAllData() throws IOException, ExtractionException { |
| 63 | + final InfoItemsPage<CommentsInfoItem> comments = extractor.getInitialPage(); |
| 64 | + for (final CommentsInfoItem c : comments.getItems()) { |
| 65 | + assertFalse(Utils.isBlank(c.getUploaderUrl())); |
| 66 | + assertFalse(Utils.isBlank(c.getUploaderName())); |
| 67 | + assertFalse(Utils.isBlank(c.getUploaderAvatarUrl())); |
| 68 | + assertFalse(Utils.isBlank(c.getCommentId())); |
| 69 | + assertFalse(Utils.isBlank(c.getCommentText())); |
| 70 | + assertFalse(Utils.isBlank(c.getName())); |
| 71 | + assertFalse(Utils.isBlank(c.getTextualUploadDate())); |
| 72 | + assertFalse(Utils.isBlank(c.getThumbnailUrl())); |
| 73 | + assertFalse(Utils.isBlank(c.getUrl())); |
| 74 | + assertEquals(-1, c.getLikeCount()); |
| 75 | + } |
| 76 | + } |
61 | 77 |
|
62 | | - @Test |
63 | | - public void testGetCommentsAllData() throws IOException, ExtractionException { |
64 | | - InfoItemsPage<CommentsInfoItem> comments = extractor.getInitialPage(); |
65 | | - for (CommentsInfoItem c : comments.getItems()) { |
66 | | - assertFalse(Utils.isBlank(c.getUploaderUrl())); |
67 | | - assertFalse(Utils.isBlank(c.getUploaderName())); |
68 | | - assertFalse(Utils.isBlank(c.getUploaderAvatarUrl())); |
69 | | - assertFalse(Utils.isBlank(c.getCommentId())); |
70 | | - assertFalse(Utils.isBlank(c.getCommentText())); |
71 | | - assertFalse(Utils.isBlank(c.getName())); |
72 | | - assertFalse(Utils.isBlank(c.getTextualUploadDate())); |
73 | | - assertFalse(Utils.isBlank(c.getThumbnailUrl())); |
74 | | - assertFalse(Utils.isBlank(c.getUrl())); |
75 | | - assertFalse(c.getLikeCount() != -1); |
| 78 | + private boolean findInComments(final InfoItemsPage<CommentsInfoItem> comments, final String comment) { |
| 79 | + return findInComments(comments.getItems(), comment); |
76 | 80 | } |
77 | | - } |
78 | 81 |
|
79 | | - private boolean findInComments(InfoItemsPage<CommentsInfoItem> comments, String comment) { |
80 | | - return findInComments(comments.getItems(), comment); |
| 82 | + private boolean findInComments(final List<CommentsInfoItem> comments, final String comment) { |
| 83 | + for (final CommentsInfoItem c : comments) { |
| 84 | + if (c.getCommentText().contains(comment)) { |
| 85 | + return true; |
| 86 | + } |
| 87 | + } |
| 88 | + return false; |
| 89 | + } |
81 | 90 | } |
82 | 91 |
|
83 | | - private boolean findInComments(List<CommentsInfoItem> comments, String comment) { |
84 | | - for (CommentsInfoItem c : comments) { |
85 | | - if (c.getCommentText().contains(comment)) { |
86 | | - return true; |
87 | | - } |
| 92 | + public static class DeletedComments { |
| 93 | + private static PeertubeCommentsExtractor extractor; |
| 94 | + |
| 95 | + @BeforeClass |
| 96 | + public static void setUp() throws Exception { |
| 97 | + NewPipe.init(DownloaderTestImpl.getInstance()); |
| 98 | + extractor = (PeertubeCommentsExtractor) PeerTube |
| 99 | + .getCommentsExtractor("https://framatube.org/videos/watch/217eefeb-883d-45be-b7fc-a788ad8507d3"); |
| 100 | + } |
| 101 | + |
| 102 | + @Test |
| 103 | + public void testGetComments() throws IOException, ExtractionException { |
| 104 | + final InfoItemsPage<CommentsInfoItem> comments = extractor.getInitialPage(); |
| 105 | + assertTrue(comments.getErrors().isEmpty()); |
| 106 | + } |
| 107 | + |
| 108 | + @Test |
| 109 | + public void testGetCommentsFromCommentsInfo() throws IOException, ExtractionException { |
| 110 | + final CommentsInfo commentsInfo = CommentsInfo.getInfo("https://framatube.org/videos/watch/217eefeb-883d-45be-b7fc-a788ad8507d3"); |
| 111 | + assertTrue(commentsInfo.getErrors().isEmpty()); |
88 | 112 | } |
89 | | - return false; |
90 | 113 | } |
91 | 114 | } |
0 commit comments