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).
This commit is contained in:
AudricV 2022-08-01 21:17:09 +02:00
parent 70fb3aa38e
commit 5158472852
No known key found for this signature in database
GPG Key ID: DA92EC7905614198
1 changed files with 31 additions and 8 deletions

View File

@ -1,5 +1,6 @@
package org.schabi.newpipe.extractor.services;
import org.schabi.newpipe.extractor.Image;
import org.schabi.newpipe.extractor.InfoItem;
import org.schabi.newpipe.extractor.ListExtractor;
import org.schabi.newpipe.extractor.Page;
@ -10,12 +11,22 @@ import org.schabi.newpipe.extractor.localization.DateWrapper;
import org.schabi.newpipe.extractor.playlist.PlaylistInfoItem;
import org.schabi.newpipe.extractor.stream.StreamInfoItem;
import javax.annotation.Nullable;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import static org.junit.jupiter.api.Assertions.*;
import static org.schabi.newpipe.extractor.ExtractorAsserts.*;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
import static org.schabi.newpipe.extractor.ExtractorAsserts.assertEmptyErrors;
import static org.schabi.newpipe.extractor.ExtractorAsserts.assertGreaterOrEqual;
import static org.schabi.newpipe.extractor.ExtractorAsserts.assertIsSecureUrl;
import static org.schabi.newpipe.extractor.ExtractorAsserts.assertNotEmpty;
import static org.schabi.newpipe.extractor.StreamingService.LinkType;
import static org.schabi.newpipe.extractor.utils.Utils.isNullOrEmpty;
@ -28,9 +39,9 @@ public final class DefaultTests {
for (InfoItem item : itemsList) {
assertIsSecureUrl(item.getUrl());
final String thumbnailUrl = item.getThumbnailUrl();
if (!isNullOrEmpty(thumbnailUrl)) {
assertIsSecureUrl(thumbnailUrl);
final List<Image> thumbnails = item.getThumbnails();
if (!isNullOrEmpty(thumbnails)) {
defaultTestImageCollection(thumbnails);
}
assertNotNull(item.getInfoType(), "InfoItem type not set: " + item);
assertEquals(expectedService.getServiceId(), item.getServiceId(), "Unexpected item service id");
@ -44,9 +55,9 @@ public final class DefaultTests {
assertExpectedLinkType(expectedService, uploaderUrl, LinkType.CHANNEL);
}
final String uploaderAvatarUrl = streamInfoItem.getUploaderAvatarUrl();
if (!isNullOrEmpty(uploaderAvatarUrl)) {
assertIsSecureUrl(uploaderAvatarUrl);
final List<Image> uploaderAvatars = streamInfoItem.getUploaderAvatars();
if (!isNullOrEmpty(uploaderAvatars)) {
defaultTestImageCollection(uploaderAvatars);
}
assertExpectedLinkType(expectedService, streamInfoItem.getUrl(), LinkType.STREAM);
@ -134,4 +145,16 @@ public final class DefaultTests {
final ListExtractor.InfoItemsPage<? extends InfoItem> page = newExtractor.getPage(nextPage);
defaultTestListOfItems(extractor.getService(), page.getItems(), page.getErrors());
}
public static void defaultTestImageCollection(
@Nullable final Collection<Image> imageCollection) {
assertNotNull(imageCollection);
imageCollection.forEach(image -> {
assertIsSecureUrl(image.getUrl());
assertGreaterOrEqual(Image.HEIGHT_UNKNOWN, image.getHeight(),
"Unexpected image height: " + image.getHeight());
assertGreaterOrEqual(Image.WIDTH_UNKNOWN, image.getWidth(),
"Unexpected image width: " + image.getWidth());
});
}
}