Skip to content

Commit 5158472

Browse files
committed
Apply changes in DefaultTests and add utility method to test image lists
This new method, defaultTestImageList(List<Image), will check that the image list is not null. For each image, it will test that its URL is secure and its height and width are more than or equal to their relevant unknown constants in the Image class (HEIGHT_UNKNOWN and WIDTH_UNKNOWN).
1 parent 70fb3aa commit 5158472

1 file changed

Lines changed: 31 additions & 8 deletions

File tree

extractor/src/test/java/org/schabi/newpipe/extractor/services/DefaultTests.java

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.schabi.newpipe.extractor.services;
22

3+
import org.schabi.newpipe.extractor.Image;
34
import org.schabi.newpipe.extractor.InfoItem;
45
import org.schabi.newpipe.extractor.ListExtractor;
56
import org.schabi.newpipe.extractor.Page;
@@ -10,12 +11,22 @@
1011
import org.schabi.newpipe.extractor.playlist.PlaylistInfoItem;
1112
import org.schabi.newpipe.extractor.stream.StreamInfoItem;
1213

14+
import javax.annotation.Nullable;
15+
import java.util.Collection;
1316
import java.util.HashSet;
1417
import java.util.List;
1518
import java.util.Set;
1619

17-
import static org.junit.jupiter.api.Assertions.*;
18-
import static org.schabi.newpipe.extractor.ExtractorAsserts.*;
20+
import static org.junit.jupiter.api.Assertions.assertEquals;
21+
import static org.junit.jupiter.api.Assertions.assertFalse;
22+
import static org.junit.jupiter.api.Assertions.assertNotEquals;
23+
import static org.junit.jupiter.api.Assertions.assertNotNull;
24+
import static org.junit.jupiter.api.Assertions.assertTrue;
25+
import static org.junit.jupiter.api.Assertions.fail;
26+
import static org.schabi.newpipe.extractor.ExtractorAsserts.assertEmptyErrors;
27+
import static org.schabi.newpipe.extractor.ExtractorAsserts.assertGreaterOrEqual;
28+
import static org.schabi.newpipe.extractor.ExtractorAsserts.assertIsSecureUrl;
29+
import static org.schabi.newpipe.extractor.ExtractorAsserts.assertNotEmpty;
1930
import static org.schabi.newpipe.extractor.StreamingService.LinkType;
2031
import static org.schabi.newpipe.extractor.utils.Utils.isNullOrEmpty;
2132

@@ -28,9 +39,9 @@ public static void defaultTestListOfItems(StreamingService expectedService, List
2839
for (InfoItem item : itemsList) {
2940
assertIsSecureUrl(item.getUrl());
3041

31-
final String thumbnailUrl = item.getThumbnailUrl();
32-
if (!isNullOrEmpty(thumbnailUrl)) {
33-
assertIsSecureUrl(thumbnailUrl);
42+
final List<Image> thumbnails = item.getThumbnails();
43+
if (!isNullOrEmpty(thumbnails)) {
44+
defaultTestImageCollection(thumbnails);
3445
}
3546
assertNotNull(item.getInfoType(), "InfoItem type not set: " + item);
3647
assertEquals(expectedService.getServiceId(), item.getServiceId(), "Unexpected item service id");
@@ -44,9 +55,9 @@ public static void defaultTestListOfItems(StreamingService expectedService, List
4455
assertExpectedLinkType(expectedService, uploaderUrl, LinkType.CHANNEL);
4556
}
4657

47-
final String uploaderAvatarUrl = streamInfoItem.getUploaderAvatarUrl();
48-
if (!isNullOrEmpty(uploaderAvatarUrl)) {
49-
assertIsSecureUrl(uploaderAvatarUrl);
58+
final List<Image> uploaderAvatars = streamInfoItem.getUploaderAvatars();
59+
if (!isNullOrEmpty(uploaderAvatars)) {
60+
defaultTestImageCollection(uploaderAvatars);
5061
}
5162

5263
assertExpectedLinkType(expectedService, streamInfoItem.getUrl(), LinkType.STREAM);
@@ -134,4 +145,16 @@ public static void defaultTestGetPageInNewExtractor(ListExtractor<? extends Info
134145
final ListExtractor.InfoItemsPage<? extends InfoItem> page = newExtractor.getPage(nextPage);
135146
defaultTestListOfItems(extractor.getService(), page.getItems(), page.getErrors());
136147
}
148+
149+
public static void defaultTestImageCollection(
150+
@Nullable final Collection<Image> imageCollection) {
151+
assertNotNull(imageCollection);
152+
imageCollection.forEach(image -> {
153+
assertIsSecureUrl(image.getUrl());
154+
assertGreaterOrEqual(Image.HEIGHT_UNKNOWN, image.getHeight(),
155+
"Unexpected image height: " + image.getHeight());
156+
assertGreaterOrEqual(Image.WIDTH_UNKNOWN, image.getWidth(),
157+
"Unexpected image width: " + image.getWidth());
158+
});
159+
}
137160
}

0 commit comments

Comments
 (0)