66import static org .schabi .newpipe .extractor .ServiceList .PeerTube ;
77import static org .schabi .newpipe .extractor .services .DefaultTests .defaultTestImageCollection ;
88
9- import org .junit .jupiter .api .BeforeAll ;
109import org .junit .jupiter .api .Test ;
1110import org .schabi .newpipe .extractor .ListExtractor .InfoItemsPage ;
1211import org .schabi .newpipe .extractor .Page ;
@@ -121,15 +120,7 @@ void testGetCommentsFromCommentsInfo() throws IOException, ExtractionException {
121120 * Test a video that has comments with nested replies.
122121 */
123122 public static class NestedComments extends DefaultSimpleExtractorTest <PeertubeCommentsExtractor > {
124- private InfoItemsPage <CommentsInfoItem > comments = null ;
125-
126- @ BeforeAll
127- @ Override
128- public void setUp () throws Exception {
129- super .setUp ();
130-
131- extractor (); // Initialize
132- }
123+ private InfoItemsPage <CommentsInfoItem > comments ;
133124
134125 @ Override
135126 protected PeertubeCommentsExtractor createExtractor () throws Exception {
@@ -142,11 +133,18 @@ protected void fetchExtractor(final PeertubeCommentsExtractor extractor) throws
142133 comments = extractor .getInitialPage ();
143134 }
144135
136+ protected InfoItemsPage <CommentsInfoItem > comments () {
137+ if (comments == null ) {
138+ extractor (); // Initialize extractor to also init Comments
139+ }
140+ return comments ;
141+ }
142+
145143 @ Test
146144 void testGetComments () throws IOException , ExtractionException {
147- assertFalse (comments .getItems ().isEmpty ());
145+ assertFalse (comments () .getItems ().isEmpty ());
148146 final Optional <CommentsInfoItem > nestedCommentHeadOpt =
149- findCommentWithId ("34293" , comments .getItems ());
147+ findCommentWithId ("34293" , comments () .getItems ());
150148 assertTrue (nestedCommentHeadOpt .isPresent ());
151149 assertTrue (findNestedCommentWithId ("34294" , nestedCommentHeadOpt .get ()), "The nested " +
152150 "comment replies were not found" );
@@ -160,7 +158,7 @@ void testHasCreatorReply() {
160158
161159 private void assertCreatorReply (final String id , final boolean expected ) {
162160 final Optional <CommentsInfoItem > comment =
163- findCommentWithId (id , comments .getItems ());
161+ findCommentWithId (id , comments () .getItems ());
164162 assertTrue (comment .isPresent ());
165163 assertEquals (expected , comment .get ().hasCreatorReply ());
166164 }
0 commit comments