Skip to content

Commit 3f0b055

Browse files
committed
Use dedicated methods to fetch extractor related data
1 parent 4fa9d74 commit 3f0b055

2 files changed

Lines changed: 21 additions & 18 deletions

File tree

extractor/src/test/java/org/schabi/newpipe/extractor/services/media_ccc/MediaCCCConferenceExtractorTest.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
public class MediaCCCConferenceExtractorTest {
2020

2121
abstract static class Base extends DefaultSimpleExtractorTest<ChannelExtractor> {
22-
protected ChannelTabExtractor tabExtractor;
22+
private ChannelTabExtractor tabExtractor;
2323

2424
@Override
2525
protected void fetchExtractor(final ChannelExtractor extractor) throws Exception {
@@ -28,6 +28,13 @@ protected void fetchExtractor(final ChannelExtractor extractor) throws Exception
2828
tabExtractor = MediaCCC.getChannelTabExtractor(extractor.getTabs().get(0));
2929
tabExtractor.fetchPage();
3030
}
31+
32+
protected ChannelTabExtractor tabExtractor() {
33+
if (tabExtractor == null) {
34+
extractor(); // Initialize extractor to also init TabExtractor
35+
}
36+
return tabExtractor;
37+
}
3138
}
3239

3340
public static class FrOSCon2017 extends Base {
@@ -60,8 +67,7 @@ void testGetThumbnails() throws ParsingException {
6067

6168
@Test
6269
void testGetInitalPage() throws Exception {
63-
extractor(); // Init extractor
64-
assertEquals(97, tabExtractor.getInitialPage().getItems().size());
70+
assertEquals(97, tabExtractor().getInitialPage().getItems().size());
6571
}
6672
}
6773

@@ -95,8 +101,7 @@ void testGetThumbnailUrl() throws ParsingException {
95101

96102
@Test
97103
void testGetInitalPage() throws Exception {
98-
extractor(); // Init extractor
99-
assertTrue(tabExtractor.getInitialPage().getItems().size() >= 21);
104+
assertTrue(tabExtractor().getInitialPage().getItems().size() >= 21);
100105
}
101106
}
102107
}

extractor/src/test/java/org/schabi/newpipe/extractor/services/peertube/PeertubeCommentsExtractorTest.java

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import static org.schabi.newpipe.extractor.ServiceList.PeerTube;
77
import static org.schabi.newpipe.extractor.services.DefaultTests.defaultTestImageCollection;
88

9-
import org.junit.jupiter.api.BeforeAll;
109
import org.junit.jupiter.api.Test;
1110
import org.schabi.newpipe.extractor.ListExtractor.InfoItemsPage;
1211
import 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

Comments
 (0)