[PeerTube] Implement CommentsInfoItemExtractor.hasCreatorReply()
This commit is contained in:
parent
dd7b2d9798
commit
d49f8411d7
|
@ -148,4 +148,10 @@ public class PeertubeCommentsInfoItemExtractor implements CommentsInfoItemExtrac
|
||||||
}
|
}
|
||||||
return replyCount;
|
return replyCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean hasCreatorReply() {
|
||||||
|
return item.has("totalRepliesFromVideoAuthor")
|
||||||
|
&& item.getInt("totalRepliesFromVideoAuthor") > 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -127,26 +127,46 @@ public class PeertubeCommentsExtractorTest {
|
||||||
*/
|
*/
|
||||||
public static class NestedComments {
|
public static class NestedComments {
|
||||||
private static PeertubeCommentsExtractor extractor;
|
private static PeertubeCommentsExtractor extractor;
|
||||||
|
private static InfoItemsPage<CommentsInfoItem> comments = null;
|
||||||
|
|
||||||
@BeforeAll
|
@BeforeAll
|
||||||
public static void setUp() throws Exception {
|
public static void setUp() throws Exception {
|
||||||
NewPipe.init(DownloaderTestImpl.getInstance());
|
NewPipe.init(DownloaderTestImpl.getInstance());
|
||||||
extractor = (PeertubeCommentsExtractor) PeerTube
|
extractor = (PeertubeCommentsExtractor) PeerTube
|
||||||
.getCommentsExtractor("https://share.tube/w/vxu4uTstUBAUromWwXGHrq");
|
.getCommentsExtractor("https://share.tube/w/vxu4uTstUBAUromWwXGHrq");
|
||||||
|
comments = extractor.getInitialPage();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testGetComments() throws IOException, ExtractionException {
|
void testGetComments() throws IOException, ExtractionException {
|
||||||
final InfoItemsPage<CommentsInfoItem> comments = extractor.getInitialPage();
|
|
||||||
assertFalse(comments.getItems().isEmpty());
|
assertFalse(comments.getItems().isEmpty());
|
||||||
final Optional<CommentsInfoItem> nestedCommentHeadOpt =
|
final Optional<CommentsInfoItem> nestedCommentHeadOpt =
|
||||||
comments.getItems()
|
findCommentWithId("9770", comments.getItems());
|
||||||
.stream()
|
|
||||||
.filter(c -> c.getCommentId().equals("9770"))
|
|
||||||
.findFirst();
|
|
||||||
assertTrue(nestedCommentHeadOpt.isPresent());
|
assertTrue(nestedCommentHeadOpt.isPresent());
|
||||||
assertTrue(findNestedCommentWithId("9773", nestedCommentHeadOpt.get()), "The nested comment replies were not found");
|
assertTrue(findNestedCommentWithId("9773", nestedCommentHeadOpt.get()), "The nested comment replies were not found");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testHasCreatorReply() {
|
||||||
|
assertCreatorReply("9770", true);
|
||||||
|
assertCreatorReply("9852", false);
|
||||||
|
assertCreatorReply("11239", false);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void assertCreatorReply(final String id, final boolean expected) {
|
||||||
|
final Optional<CommentsInfoItem> comment =
|
||||||
|
findCommentWithId(id, comments.getItems());
|
||||||
|
assertTrue(comment.isPresent());
|
||||||
|
assertEquals(expected, comment.get().hasCreatorReply());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Optional<CommentsInfoItem> findCommentWithId(
|
||||||
|
final String id, final List<CommentsInfoItem> comments) {
|
||||||
|
return comments
|
||||||
|
.stream()
|
||||||
|
.filter(c -> c.getCommentId().equals(id))
|
||||||
|
.findFirst();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean findNestedCommentWithId(final String id, final CommentsInfoItem comment)
|
private static boolean findNestedCommentWithId(final String id, final CommentsInfoItem comment)
|
||||||
|
|
Loading…
Reference in New Issue