Skip to content

Commit 6c07b78

Browse files
committed
Fix Java 7 incompatibility
1 parent 29afd0c commit 6c07b78

6 files changed

Lines changed: 92 additions & 91 deletions

File tree

Lines changed: 1 addition & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,7 @@
11
package org.schabi.newpipe.extractor.services;
22

3-
import org.schabi.newpipe.extractor.InfoItem;
4-
import org.schabi.newpipe.extractor.InfoItemsCollector;
5-
import org.schabi.newpipe.extractor.ListExtractor;
6-
import org.schabi.newpipe.extractor.stream.StreamInfoItem;
7-
8-
import java.util.List;
9-
10-
import static org.junit.Assert.*;
11-
import static org.schabi.newpipe.extractor.ExtractorAsserts.*;
12-
3+
@SuppressWarnings("unused")
134
public interface BaseListExtractorTest extends BaseExtractorTest {
14-
@SuppressWarnings("unused")
155
void testRelatedItems() throws Exception;
16-
@SuppressWarnings("unused")
176
void testMoreRelatedItems() throws Exception;
18-
19-
20-
static void defaultTestListOfItems(int expectedServiceId, List<? extends InfoItem> itemsList, List<Throwable> errors) {
21-
assertTrue("List of items is empty", !itemsList.isEmpty());
22-
assertFalse("List of items contains a null element", itemsList.contains(null));
23-
assertEmptyErrors("Errors during stream list extraction", errors);
24-
25-
for (InfoItem item : itemsList) {
26-
assertIsSecureUrl(item.getUrl());
27-
if (item.getThumbnailUrl() != null && !item.getThumbnailUrl().isEmpty()) {
28-
assertIsSecureUrl(item.getThumbnailUrl());
29-
}
30-
assertNotNull("InfoItem type not set: " + item, item.getInfoType());
31-
assertEquals("Service id doesn't match: " + item, expectedServiceId, item.getServiceId());
32-
33-
if (item instanceof StreamInfoItem) {
34-
StreamInfoItem streamInfoItem = (StreamInfoItem) item;
35-
assertNotEmpty("Uploader name not set: " + item, streamInfoItem.getUploaderName());
36-
assertNotEmpty("Uploader url not set: " + item, streamInfoItem.getUploaderUrl());
37-
}
38-
}
39-
}
40-
41-
static void defaultTestRelatedItems(ListExtractor extractor, int expectedServiceId) throws Exception {
42-
final InfoItemsCollector<? extends InfoItem, ?> itemsCollector = extractor.getInfoItems();
43-
final List<? extends InfoItem> itemsList = itemsCollector.getItemList();
44-
List<Throwable> errors = itemsCollector.getErrors();
45-
46-
defaultTestListOfItems(expectedServiceId, itemsList, errors);
47-
}
48-
49-
static ListExtractor.InfoItemPage<? extends InfoItem> defaultTestMoreItems(ListExtractor extractor, int expectedServiceId) throws Exception {
50-
assertTrue("Doesn't have more items", extractor.hasNextPage());
51-
ListExtractor.InfoItemPage<? extends InfoItem> nextPage = extractor.getPage(extractor.getNextPageUrl());
52-
assertTrue("Next page is empty", !nextPage.getItemsList().isEmpty());
53-
assertEmptyErrors("Next page have errors", nextPage.getErrors());
54-
55-
defaultTestListOfItems(expectedServiceId, nextPage.getItemsList(), nextPage.getErrors());
56-
return nextPage;
57-
}
58-
59-
static void defaultTestGetPageInNewExtractor(ListExtractor extractor, ListExtractor newExtractor, int expectedServiceId) throws Exception {
60-
final String nextPageUrl = extractor.getNextPageUrl();
61-
62-
final ListExtractor.InfoItemPage<? extends InfoItem> page = newExtractor.getPage(nextPageUrl);
63-
BaseListExtractorTest.defaultTestListOfItems(expectedServiceId, page.getItemsList(), page.getErrors());
64-
}
657
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
package org.schabi.newpipe.extractor.services;
2+
3+
import org.schabi.newpipe.extractor.InfoItem;
4+
import org.schabi.newpipe.extractor.InfoItemsCollector;
5+
import org.schabi.newpipe.extractor.ListExtractor;
6+
import org.schabi.newpipe.extractor.stream.StreamInfoItem;
7+
8+
import java.util.List;
9+
10+
import static org.junit.Assert.*;
11+
import static org.schabi.newpipe.extractor.ExtractorAsserts.*;
12+
13+
public final class DefaultTests {
14+
public static void defaultTestListOfItems(int expectedServiceId, List<? extends InfoItem> itemsList, List<Throwable> errors) {
15+
assertTrue("List of items is empty", !itemsList.isEmpty());
16+
assertFalse("List of items contains a null element", itemsList.contains(null));
17+
assertEmptyErrors("Errors during stream list extraction", errors);
18+
19+
for (InfoItem item : itemsList) {
20+
assertIsSecureUrl(item.getUrl());
21+
if (item.getThumbnailUrl() != null && !item.getThumbnailUrl().isEmpty()) {
22+
assertIsSecureUrl(item.getThumbnailUrl());
23+
}
24+
assertNotNull("InfoItem type not set: " + item, item.getInfoType());
25+
assertEquals("Service id doesn't match: " + item, expectedServiceId, item.getServiceId());
26+
27+
if (item instanceof StreamInfoItem) {
28+
StreamInfoItem streamInfoItem = (StreamInfoItem) item;
29+
assertNotEmpty("Uploader name not set: " + item, streamInfoItem.getUploaderName());
30+
assertNotEmpty("Uploader url not set: " + item, streamInfoItem.getUploaderUrl());
31+
}
32+
}
33+
}
34+
35+
public static void defaultTestRelatedItems(ListExtractor extractor, int expectedServiceId) throws Exception {
36+
final InfoItemsCollector<? extends InfoItem, ?> itemsCollector = extractor.getInfoItems();
37+
final List<? extends InfoItem> itemsList = itemsCollector.getItemList();
38+
List<Throwable> errors = itemsCollector.getErrors();
39+
40+
defaultTestListOfItems(expectedServiceId, itemsList, errors);
41+
}
42+
43+
public static ListExtractor.InfoItemPage<? extends InfoItem> defaultTestMoreItems(ListExtractor extractor, int expectedServiceId) throws Exception {
44+
assertTrue("Doesn't have more items", extractor.hasNextPage());
45+
ListExtractor.InfoItemPage<? extends InfoItem> nextPage = extractor.getPage(extractor.getNextPageUrl());
46+
assertTrue("Next page is empty", !nextPage.getItemsList().isEmpty());
47+
assertEmptyErrors("Next page have errors", nextPage.getErrors());
48+
49+
defaultTestListOfItems(expectedServiceId, nextPage.getItemsList(), nextPage.getErrors());
50+
return nextPage;
51+
}
52+
53+
public static void defaultTestGetPageInNewExtractor(ListExtractor extractor, ListExtractor newExtractor, int expectedServiceId) throws Exception {
54+
final String nextPageUrl = extractor.getNextPageUrl();
55+
56+
final ListExtractor.InfoItemPage<? extends InfoItem> page = newExtractor.getPage(nextPageUrl);
57+
defaultTestListOfItems(expectedServiceId, page.getItemsList(), page.getErrors());
58+
}
59+
}

src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudChannelExtractorTest.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@
88
import org.schabi.newpipe.extractor.NewPipe;
99
import org.schabi.newpipe.extractor.channel.ChannelExtractor;
1010
import org.schabi.newpipe.extractor.services.BaseChannelExtractorTest;
11-
import org.schabi.newpipe.extractor.services.BaseListExtractorTest;
1211

1312
import static org.junit.Assert.*;
1413
import static org.schabi.newpipe.extractor.ExtractorAsserts.assertEmpty;
1514
import static org.schabi.newpipe.extractor.ExtractorAsserts.assertIsSecureUrl;
1615
import static org.schabi.newpipe.extractor.ServiceList.SoundCloud;
16+
import static org.schabi.newpipe.extractor.services.DefaultTests.*;
1717

1818
/**
1919
* Test for {@link SoundcloudChannelExtractor}
@@ -66,12 +66,12 @@ public void testOriginalUrl() {
6666

6767
@Test
6868
public void testRelatedItems() throws Exception {
69-
BaseListExtractorTest.defaultTestRelatedItems(extractor, SoundCloud.getServiceId());
69+
defaultTestRelatedItems(extractor, SoundCloud.getServiceId());
7070
}
7171

7272
@Test
7373
public void testMoreRelatedItems() throws Exception {
74-
BaseListExtractorTest.defaultTestMoreItems(extractor, SoundCloud.getServiceId());
74+
defaultTestMoreItems(extractor, SoundCloud.getServiceId());
7575
}
7676

7777
/*//////////////////////////////////////////////////////////////////////////
@@ -122,7 +122,7 @@ public static void setUp() throws Exception {
122122
@Test
123123
public void testGetPageInNewExtractor() throws Exception {
124124
final ChannelExtractor newExtractor = SoundCloud.getChannelExtractor(extractor.getCleanUrl());
125-
BaseListExtractorTest.defaultTestGetPageInNewExtractor(extractor, newExtractor, SoundCloud.getServiceId());
125+
defaultTestGetPageInNewExtractor(extractor, newExtractor, SoundCloud.getServiceId());
126126
}
127127

128128
/*//////////////////////////////////////////////////////////////////////////
@@ -160,12 +160,12 @@ public void testOriginalUrl() {
160160

161161
@Test
162162
public void testRelatedItems() throws Exception {
163-
BaseListExtractorTest.defaultTestRelatedItems(extractor, SoundCloud.getServiceId());
163+
defaultTestRelatedItems(extractor, SoundCloud.getServiceId());
164164
}
165165

166166
@Test
167167
public void testMoreRelatedItems() throws Exception {
168-
BaseListExtractorTest.defaultTestMoreItems(extractor, SoundCloud.getServiceId());
168+
defaultTestMoreItems(extractor, SoundCloud.getServiceId());
169169
}
170170

171171
/*//////////////////////////////////////////////////////////////////////////

src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudPlaylistExtractorTest.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@
1111
import org.schabi.newpipe.extractor.NewPipe;
1212
import org.schabi.newpipe.extractor.ServiceList;
1313
import org.schabi.newpipe.extractor.playlist.PlaylistExtractor;
14-
import org.schabi.newpipe.extractor.services.BaseListExtractorTest;
1514
import org.schabi.newpipe.extractor.services.BasePlaylistExtractorTest;
1615

1716
import static org.junit.Assert.*;
1817
import static org.schabi.newpipe.extractor.ExtractorAsserts.assertIsSecureUrl;
1918
import static org.schabi.newpipe.extractor.ServiceList.SoundCloud;
19+
import static org.schabi.newpipe.extractor.services.DefaultTests.*;
2020

2121
/**
2222
* Test for {@link PlaylistExtractor}
@@ -69,13 +69,13 @@ public void testOriginalUrl() {
6969

7070
@Test
7171
public void testRelatedItems() throws Exception {
72-
BaseListExtractorTest.defaultTestRelatedItems(extractor, SoundCloud.getServiceId());
72+
defaultTestRelatedItems(extractor, SoundCloud.getServiceId());
7373
}
7474

7575
@Test
7676
public void testMoreRelatedItems() {
7777
try {
78-
BaseListExtractorTest.defaultTestMoreItems(extractor, SoundCloud.getServiceId());
78+
defaultTestMoreItems(extractor, SoundCloud.getServiceId());
7979
} catch (Throwable ignored) {
8080
return;
8181
}
@@ -167,12 +167,12 @@ public void testOriginalUrl() {
167167

168168
@Test
169169
public void testRelatedItems() throws Exception {
170-
BaseListExtractorTest.defaultTestRelatedItems(extractor, SoundCloud.getServiceId());
170+
defaultTestRelatedItems(extractor, SoundCloud.getServiceId());
171171
}
172172

173173
@Test
174174
public void testMoreRelatedItems() throws Exception {
175-
BaseListExtractorTest.defaultTestMoreItems(extractor, SoundCloud.getServiceId());
175+
defaultTestMoreItems(extractor, SoundCloud.getServiceId());
176176
}
177177

178178
/*//////////////////////////////////////////////////////////////////////////
@@ -231,7 +231,7 @@ public static void setUp() throws Exception {
231231
@Test
232232
public void testGetPageInNewExtractor() throws Exception {
233233
final PlaylistExtractor newExtractor = SoundCloud.getPlaylistExtractor(extractor.getCleanUrl());
234-
BaseListExtractorTest.defaultTestGetPageInNewExtractor(extractor, newExtractor, SoundCloud.getServiceId());
234+
defaultTestGetPageInNewExtractor(extractor, newExtractor, SoundCloud.getServiceId());
235235
}
236236

237237
/*//////////////////////////////////////////////////////////////////////////
@@ -269,16 +269,16 @@ public void testOriginalUrl() {
269269

270270
@Test
271271
public void testRelatedItems() throws Exception {
272-
BaseListExtractorTest.defaultTestRelatedItems(extractor, SoundCloud.getServiceId());
272+
defaultTestRelatedItems(extractor, SoundCloud.getServiceId());
273273
}
274274

275275
@Test
276276
public void testMoreRelatedItems() throws Exception {
277-
ListExtractor.InfoItemPage<? extends InfoItem> currentPage = BaseListExtractorTest.defaultTestMoreItems(extractor, ServiceList.SoundCloud.getServiceId());
277+
ListExtractor.InfoItemPage<? extends InfoItem> currentPage = defaultTestMoreItems(extractor, ServiceList.SoundCloud.getServiceId());
278278
// Test for 2 more levels
279279
for (int i = 0; i < 2; i++) {
280280
currentPage = extractor.getPage(currentPage.getNextPageUrl());
281-
BaseListExtractorTest.defaultTestListOfItems(SoundCloud.getServiceId(), currentPage.getItemsList(), currentPage.getErrors());
281+
defaultTestListOfItems(SoundCloud.getServiceId(), currentPage.getItemsList(), currentPage.getErrors());
282282
}
283283
}
284284

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@
99
import org.schabi.newpipe.extractor.ServiceList;
1010
import org.schabi.newpipe.extractor.channel.ChannelExtractor;
1111
import org.schabi.newpipe.extractor.services.BaseChannelExtractorTest;
12-
import org.schabi.newpipe.extractor.services.BaseListExtractorTest;
1312

1413
import static org.junit.Assert.*;
1514
import static org.schabi.newpipe.extractor.ExtractorAsserts.assertIsSecureUrl;
1615
import static org.schabi.newpipe.extractor.ServiceList.YouTube;
16+
import static org.schabi.newpipe.extractor.services.DefaultTests.*;
1717

1818
/**
1919
* Test for {@link ChannelExtractor}
@@ -66,12 +66,12 @@ public void testOriginalUrl() {
6666

6767
@Test
6868
public void testRelatedItems() throws Exception {
69-
BaseListExtractorTest.defaultTestRelatedItems(extractor, YouTube.getServiceId());
69+
defaultTestRelatedItems(extractor, YouTube.getServiceId());
7070
}
7171

7272
@Test
7373
public void testMoreRelatedItems() throws Exception {
74-
BaseListExtractorTest.defaultTestMoreItems(extractor, ServiceList.YouTube.getServiceId());
74+
defaultTestMoreItems(extractor, ServiceList.YouTube.getServiceId());
7575
}
7676

7777
/*//////////////////////////////////////////////////////////////////////////
@@ -126,7 +126,7 @@ public static void setUp() throws Exception {
126126
@Test
127127
public void testGetPageInNewExtractor() throws Exception {
128128
final ChannelExtractor newExtractor = YouTube.getChannelExtractor(extractor.getCleanUrl());
129-
BaseListExtractorTest.defaultTestGetPageInNewExtractor(extractor, newExtractor, YouTube.getServiceId());
129+
defaultTestGetPageInNewExtractor(extractor, newExtractor, YouTube.getServiceId());
130130
}
131131

132132
/*//////////////////////////////////////////////////////////////////////////
@@ -165,12 +165,12 @@ public void testOriginalUrl() {
165165

166166
@Test
167167
public void testRelatedItems() throws Exception {
168-
BaseListExtractorTest.defaultTestRelatedItems(extractor, YouTube.getServiceId());
168+
defaultTestRelatedItems(extractor, YouTube.getServiceId());
169169
}
170170

171171
@Test
172172
public void testMoreRelatedItems() throws Exception {
173-
BaseListExtractorTest.defaultTestMoreItems(extractor, ServiceList.YouTube.getServiceId());
173+
defaultTestMoreItems(extractor, ServiceList.YouTube.getServiceId());
174174
}
175175

176176
/*//////////////////////////////////////////////////////////////////////////
@@ -256,12 +256,12 @@ public void testOriginalUrl() {
256256

257257
@Test
258258
public void testRelatedItems() throws Exception {
259-
BaseListExtractorTest.defaultTestRelatedItems(extractor, YouTube.getServiceId());
259+
defaultTestRelatedItems(extractor, YouTube.getServiceId());
260260
}
261261

262262
@Test
263263
public void testMoreRelatedItems() throws Exception {
264-
BaseListExtractorTest.defaultTestMoreItems(extractor, ServiceList.YouTube.getServiceId());
264+
defaultTestMoreItems(extractor, ServiceList.YouTube.getServiceId());
265265
}
266266

267267
/*//////////////////////////////////////////////////////////////////////////
@@ -345,13 +345,13 @@ public void testOriginalUrl() {
345345

346346
@Test
347347
public void testRelatedItems() throws Exception {
348-
BaseListExtractorTest.defaultTestRelatedItems(extractor, YouTube.getServiceId());
348+
defaultTestRelatedItems(extractor, YouTube.getServiceId());
349349
}
350350

351351
@Test
352352
public void testMoreRelatedItems() {
353353
try {
354-
BaseListExtractorTest.defaultTestMoreItems(extractor, YouTube.getServiceId());
354+
defaultTestMoreItems(extractor, YouTube.getServiceId());
355355
} catch (Throwable ignored) {
356356
return;
357357
}

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@
1010
import org.schabi.newpipe.extractor.NewPipe;
1111
import org.schabi.newpipe.extractor.ServiceList;
1212
import org.schabi.newpipe.extractor.playlist.PlaylistExtractor;
13-
import org.schabi.newpipe.extractor.services.BaseListExtractorTest;
1413
import org.schabi.newpipe.extractor.services.BasePlaylistExtractorTest;
1514

1615
import static org.junit.Assert.assertEquals;
1716
import static org.junit.Assert.assertTrue;
1817
import static org.schabi.newpipe.extractor.ExtractorAsserts.assertIsSecureUrl;
1918
import static org.schabi.newpipe.extractor.ServiceList.YouTube;
19+
import static org.schabi.newpipe.extractor.services.DefaultTests.*;
2020

2121
/**
2222
* Test for {@link YoutubePlaylistExtractor}
@@ -70,12 +70,12 @@ public void testOriginalUrl() {
7070

7171
@Test
7272
public void testRelatedItems() throws Exception {
73-
BaseListExtractorTest.defaultTestRelatedItems(extractor, YouTube.getServiceId());
73+
defaultTestRelatedItems(extractor, YouTube.getServiceId());
7474
}
7575

7676
@Test
7777
public void testMoreRelatedItems() throws Exception {
78-
BaseListExtractorTest.defaultTestMoreItems(extractor, ServiceList.YouTube.getServiceId());
78+
defaultTestMoreItems(extractor, ServiceList.YouTube.getServiceId());
7979
}
8080

8181
/*//////////////////////////////////////////////////////////////////////////
@@ -137,7 +137,7 @@ public static void setUp() throws Exception {
137137
@Test
138138
public void testGetPageInNewExtractor() throws Exception {
139139
final PlaylistExtractor newExtractor = YouTube.getPlaylistExtractor(extractor.getCleanUrl());
140-
BaseListExtractorTest.defaultTestGetPageInNewExtractor(extractor, newExtractor, YouTube.getServiceId());
140+
defaultTestGetPageInNewExtractor(extractor, newExtractor, YouTube.getServiceId());
141141
}
142142

143143
/*//////////////////////////////////////////////////////////////////////////
@@ -176,16 +176,16 @@ public void testOriginalUrl() {
176176

177177
@Test
178178
public void testRelatedItems() throws Exception {
179-
BaseListExtractorTest.defaultTestRelatedItems(extractor, YouTube.getServiceId());
179+
defaultTestRelatedItems(extractor, YouTube.getServiceId());
180180
}
181181

182182
@Test
183183
public void testMoreRelatedItems() throws Exception {
184-
ListExtractor.InfoItemPage<? extends InfoItem> currentPage = BaseListExtractorTest.defaultTestMoreItems(extractor, ServiceList.YouTube.getServiceId());
184+
ListExtractor.InfoItemPage<? extends InfoItem> currentPage = defaultTestMoreItems(extractor, ServiceList.YouTube.getServiceId());
185185
// Test for 2 more levels
186186
for (int i = 0; i < 2; i++) {
187187
currentPage = extractor.getPage(currentPage.getNextPageUrl());
188-
BaseListExtractorTest.defaultTestListOfItems(YouTube.getServiceId(), currentPage.getItemsList(), currentPage.getErrors());
188+
defaultTestListOfItems(YouTube.getServiceId(), currentPage.getItemsList(), currentPage.getErrors());
189189
}
190190
}
191191

0 commit comments

Comments
 (0)