Improve assertTabsContain() to also check size

This commit is contained in:
Stypox 2024-04-20 11:45:09 +02:00
parent 9d0dd36034
commit 4e9e7cb29c
No known key found for this signature in database
GPG Key ID: 4BDF1B40A49FDD23
2 changed files with 13 additions and 7 deletions

View File

@ -171,8 +171,17 @@ public class ExtractorAsserts {
public static void assertTabsContain(@Nonnull final List<ListLinkHandler> tabs, public static void assertTabsContain(@Nonnull final List<ListLinkHandler> tabs,
@Nonnull final String... expectedTabs) { @Nonnull final String... expectedTabs) {
final Set<String> tabSet = tabs.stream() final Set<String> tabSet = tabs.stream()
.map(linkHandler -> linkHandler.getContentFilters().get(0)) .map(linkHandler -> {
assertEquals(1, linkHandler.getContentFilters().size(),
"Unexpected content filters for channel tab: "
+ linkHandler.getContentFilters());
return linkHandler.getContentFilters().get(0);
})
.collect(Collectors.toUnmodifiableSet()); .collect(Collectors.toUnmodifiableSet());
assertEquals(expectedTabs.length, tabSet.size(),
"Different amount of tabs returned:\nExpected: "
+ Arrays.toString(expectedTabs) + "\nActual: " + tabSet);
Arrays.stream(expectedTabs) Arrays.stream(expectedTabs)
.forEach(expectedTab -> assertTrue(tabSet.contains(expectedTab), .forEach(expectedTab -> assertTrue(tabSet.contains(expectedTab),
"Missing " + expectedTab + " tab (got " + tabSet + ")")); "Missing " + expectedTab + " tab (got " + tabSet + ")"));

View File

@ -541,7 +541,8 @@ public class YoutubeChannelExtractorTest {
@Test @Test
@Override @Override
public void testTabs() throws Exception { public void testTabs() throws Exception {
assertTabsContain(extractor.getTabs(), ChannelTabs.VIDEOS, ChannelTabs.PLAYLISTS); assertTabsContain(extractor.getTabs(),
ChannelTabs.VIDEOS, ChannelTabs.PLAYLISTS, ChannelTabs.SHORTS);
assertTrue(extractor.getTabs().stream() assertTrue(extractor.getTabs().stream()
.filter(it -> ChannelTabs.VIDEOS.equals(it.getContentFilters().get(0))) .filter(it -> ChannelTabs.VIDEOS.equals(it.getContentFilters().get(0)))
.allMatch(ReadyChannelTabListLinkHandler.class::isInstance)); .allMatch(ReadyChannelTabListLinkHandler.class::isInstance));
@ -920,11 +921,7 @@ public class YoutubeChannelExtractorTest {
// Gaming topic channels tabs are not yet supported // Gaming topic channels tabs are not yet supported
// However, a Shorts tab like on other channel types is returned, so it is supported // However, a Shorts tab like on other channel types is returned, so it is supported
// Check that it is returned // Check that it is returned
final List<ListLinkHandler> channelTabs = extractor.getTabs(); assertTabsContain(extractor.getTabs(), ChannelTabs.SHORTS);
assertEquals(1, channelTabs.size());
final List<String> contentFilters = channelTabs.get(0).getContentFilters();
assertEquals(1, contentFilters.size());
assertEquals(ChannelTabs.SHORTS, contentFilters.get(0));
} }
@Test @Test