Add utility method to assert that given channel tabs are in the ones returned by a channel extractor

Only the first content filter of the ListLinkHandler instances provided is
used when collecting all channel tabs of the ListLinkHandler list, as channel
tabs implementations only use one content filter per ListLinkHandler instance.

Co-authored-by: ThetaDev <t.testboy@gmail.com>
This commit is contained in:
AudricV 2023-07-15 00:24:27 +02:00 committed by Stypox
parent 18846baba7
commit e0ba29cd19
No known key found for this signature in database
GPG Key ID: 4BDF1B40A49FDD23

View File

@ -3,8 +3,11 @@ package org.schabi.newpipe.extractor;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.net.URL; import java.net.URL;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import javax.annotation.Nullable; import javax.annotation.Nullable;
@ -15,6 +18,7 @@ import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
import org.schabi.newpipe.extractor.linkhandler.ListLinkHandler;
import org.schabi.newpipe.extractor.utils.Utils; import org.schabi.newpipe.extractor.utils.Utils;
public class ExtractorAsserts { public class ExtractorAsserts {
@ -146,4 +150,14 @@ public class ExtractorAsserts {
assertTrue(container.contains(shouldBeContained), assertTrue(container.contains(shouldBeContained),
"'" + shouldBeContained + "' should be contained inside '" + container + "'"); "'" + shouldBeContained + "' should be contained inside '" + container + "'");
} }
public static void assertTabsContained(@Nonnull final List<ListLinkHandler> tabs,
@Nonnull final String... expectedTabs) {
final Set<String> tabSet = tabs.stream()
.map(linkHandler -> linkHandler.getContentFilters().get(0))
.collect(Collectors.toUnmodifiableSet());
Arrays.stream(expectedTabs)
.forEach(expectedTab -> assertTrue(tabSet.contains(expectedTab),
"Missing " + expectedTab + " tab (got " + tabSet + ")"));
}
} }