Skip to content

Commit

Permalink
fix: use assertTabs method, rename channelTab mock folder
Browse files Browse the repository at this point in the history
  • Loading branch information
Theta-Dev committed May 7, 2023
1 parent d868746 commit 2adc2ca
Show file tree
Hide file tree
Showing 23 changed files with 36 additions and 68 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
Expand All @@ -15,6 +18,7 @@
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

import org.schabi.newpipe.extractor.linkhandler.ListLinkHandler;
import org.schabi.newpipe.extractor.utils.Utils;

public class ExtractorAsserts {
Expand Down Expand Up @@ -144,6 +148,13 @@ public static void assertContains(
assertNotNull(shouldBeContained, "shouldBeContained is null");
assertNotNull(container, "container is null");
assertTrue(container.contains(shouldBeContained),
"'" + shouldBeContained + "' should be contained inside '" + container +"'");
"'" + shouldBeContained + "' should be contained inside '" + container + "'");
}

public static void assertTabs(final List<ListLinkHandler> tabs, final String... expect) {
final Set<String> tabSet = tabs.stream()
.map(linkHandler -> linkHandler.getContentFilters().get(0)).collect(Collectors.toUnmodifiableSet());
Arrays.stream(expect).forEach(expectedTab -> assertTrue(tabSet.contains(expectedTab),
String.format("missing tab: %s, got %s", expectedTab, tabSet)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,12 @@
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.schabi.newpipe.downloader.DownloaderTestImpl;
import org.schabi.newpipe.extractor.ExtractorAsserts;
import org.schabi.newpipe.extractor.NewPipe;
import org.schabi.newpipe.extractor.channel.ChannelExtractor;
import org.schabi.newpipe.extractor.linkhandler.ChannelTabs;
import org.schabi.newpipe.extractor.services.BaseChannelExtractorTest;

import java.util.Set;
import java.util.stream.Collectors;

import static org.junit.jupiter.api.Assertions.*;
import static org.schabi.newpipe.extractor.ServiceList.Bandcamp;

Expand Down Expand Up @@ -66,9 +64,7 @@ public void testVerified() throws Exception {
@Test
@Override
public void testTabs() throws Exception {
Set<String> tabs = extractor.getTabs().stream()
.map(linkHandler -> linkHandler.getContentFilters().get(0)).collect(Collectors.toSet());
assertTrue(tabs.contains(ChannelTabs.ALBUMS), "albums");
ExtractorAsserts.assertTabs(extractor.getTabs(), ChannelTabs.ALBUMS);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,10 +213,7 @@ public void testVerified() throws Exception {
@Test
@Override
public void testTabs() throws Exception {
Set<String> tabs = extractor.getTabs().stream()
.map(linkHandler -> linkHandler.getContentFilters().get(0)).collect(Collectors.toSet());
assertTrue(tabs.contains(ChannelTabs.VIDEOS));
assertTrue(tabs.contains(ChannelTabs.CHANNELS));
ExtractorAsserts.assertTabs(extractor.getTabs(), ChannelTabs.VIDEOS, ChannelTabs.CHANNELS);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -250,9 +250,7 @@ public void testVerified() throws Exception {
@Test
@Override
public void testTabs() throws Exception {
Set<String> tabs = extractor.getTabs().stream()
.map(linkHandler -> linkHandler.getContentFilters().get(0)).collect(Collectors.toSet());
assertTrue(tabs.contains(ChannelTabs.PLAYLISTS));
ExtractorAsserts.assertTabs(extractor.getTabs(), ChannelTabs.PLAYLISTS);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,17 @@
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.schabi.newpipe.downloader.DownloaderTestImpl;
import org.schabi.newpipe.extractor.ExtractorAsserts;
import org.schabi.newpipe.extractor.NewPipe;
import org.schabi.newpipe.extractor.channel.ChannelExtractor;
import org.schabi.newpipe.extractor.channel.ChannelTabExtractor;
import org.schabi.newpipe.extractor.exceptions.ParsingException;
import org.schabi.newpipe.extractor.linkhandler.ChannelTabs;
import org.schabi.newpipe.extractor.services.BaseChannelExtractorTest;
import org.schabi.newpipe.extractor.services.soundcloud.extractors.SoundcloudChannelExtractor;

import java.util.Set;
import java.util.stream.Collectors;

import static org.junit.jupiter.api.Assertions.*;
import static org.schabi.newpipe.extractor.ExtractorAsserts.assertEmpty;
import static org.schabi.newpipe.extractor.ExtractorAsserts.assertIsSecureUrl;
import static org.schabi.newpipe.extractor.ServiceList.SoundCloud;
import static org.schabi.newpipe.extractor.services.DefaultTests.*;

/**
* Test for {@link SoundcloudChannelExtractor}
Expand Down Expand Up @@ -112,11 +107,8 @@ public void testVerified() throws Exception {
@Test
@Override
public void testTabs() throws Exception {
Set<String> tabs = extractor.getTabs().stream()
.map(linkHandler -> linkHandler.getContentFilters().get(0)).collect(Collectors.toSet());
assertTrue(tabs.contains(ChannelTabs.TRACKS));
assertTrue(tabs.contains(ChannelTabs.PLAYLISTS));
assertTrue(tabs.contains(ChannelTabs.ALBUMS));
ExtractorAsserts.assertTabs(extractor.getTabs(),
ChannelTabs.TRACKS, ChannelTabs.PLAYLISTS, ChannelTabs.ALBUMS);
}
}

Expand Down Expand Up @@ -208,11 +200,8 @@ public void testVerified() throws Exception {
@Test
@Override
public void testTabs() throws Exception {
Set<String> tabs = extractor.getTabs().stream()
.map(linkHandler -> linkHandler.getContentFilters().get(0)).collect(Collectors.toSet());
assertTrue(tabs.contains(ChannelTabs.TRACKS));
assertTrue(tabs.contains(ChannelTabs.PLAYLISTS));
assertTrue(tabs.contains(ChannelTabs.ALBUMS));
ExtractorAsserts.assertTabs(extractor.getTabs(),
ChannelTabs.TRACKS, ChannelTabs.PLAYLISTS, ChannelTabs.ALBUMS);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import static org.schabi.newpipe.extractor.services.DefaultTests.defaultTestRelatedItems;

public class YouTubeChannelTabExtractorTest {
private static final String RESOURCE_PATH = DownloaderFactory.RESOURCE_PATH + "services/youtube/extractor/channelTab/";
private static final String RESOURCE_PATH = DownloaderFactory.RESOURCE_PATH + "services/youtube/extractor/channelTabs/";

public static class Playlists implements BaseListExtractorTest {
private static YoutubeChannelTabExtractor extractor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
import org.schabi.newpipe.extractor.services.youtube.extractors.YoutubeChannelExtractor;

import java.io.IOException;
import java.util.Set;
import java.util.stream.Collectors;

import static org.junit.jupiter.api.Assertions.*;
import static org.schabi.newpipe.extractor.ExtractorAsserts.assertContains;
Expand Down Expand Up @@ -258,12 +256,8 @@ public void testVerified() throws Exception {
@Test
@Override
public void testTabs() throws Exception {
Set<String> tabs = extractor.getTabs().stream()
.map(linkHandler -> linkHandler.getContentFilters().get(0)).collect(Collectors.toSet());
assertTrue(tabs.contains(ChannelTabs.VIDEOS));
assertTrue(tabs.contains(ChannelTabs.LIVESTREAMS));
assertTrue(tabs.contains(ChannelTabs.PLAYLISTS));
assertTrue(tabs.contains(ChannelTabs.CHANNELS));
ExtractorAsserts.assertTabs(extractor.getTabs(),
ChannelTabs.VIDEOS, ChannelTabs.LIVESTREAMS, ChannelTabs.PLAYLISTS, ChannelTabs.CHANNELS);
}
}

Expand Down Expand Up @@ -383,13 +377,9 @@ public void testVerified() throws Exception {
@Test
@Override
public void testTabs() throws Exception {
Set<String> tabs = extractor.getTabs().stream()
.map(linkHandler -> linkHandler.getContentFilters().get(0)).collect(Collectors.toSet());
assertTrue(tabs.contains(ChannelTabs.VIDEOS));
assertTrue(tabs.contains(ChannelTabs.SHORTS));
assertTrue(tabs.contains(ChannelTabs.LIVESTREAMS));
assertTrue(tabs.contains(ChannelTabs.PLAYLISTS));
assertTrue(tabs.contains(ChannelTabs.CHANNELS));
ExtractorAsserts.assertTabs(extractor.getTabs(),
ChannelTabs.VIDEOS, ChannelTabs.SHORTS, ChannelTabs.LIVESTREAMS,
ChannelTabs.PLAYLISTS, ChannelTabs.CHANNELS);
}
}

Expand Down Expand Up @@ -511,11 +501,8 @@ public void testVerified() throws Exception {
@Test
@Override
public void testTabs() throws Exception {
Set<String> tabs = extractor.getTabs().stream()
.map(linkHandler -> linkHandler.getContentFilters().get(0)).collect(Collectors.toSet());
assertTrue(tabs.contains(ChannelTabs.VIDEOS));
assertTrue(tabs.contains(ChannelTabs.PLAYLISTS));
assertTrue(tabs.contains(ChannelTabs.CHANNELS));
ExtractorAsserts.assertTabs(extractor.getTabs(),
ChannelTabs.VIDEOS, ChannelTabs.PLAYLISTS, ChannelTabs.CHANNELS);
}
}

Expand Down Expand Up @@ -660,11 +647,8 @@ public void testVerified() throws Exception {
@Test
@Override
public void testTabs() throws Exception {
Set<String> tabs = extractor.getTabs().stream()
.map(linkHandler -> linkHandler.getContentFilters().get(0)).collect(Collectors.toSet());
assertTrue(tabs.contains(ChannelTabs.VIDEOS));
assertTrue(tabs.contains(ChannelTabs.PLAYLISTS));
assertTrue(tabs.contains(ChannelTabs.CHANNELS));
ExtractorAsserts.assertTabs(extractor.getTabs(),
ChannelTabs.VIDEOS, ChannelTabs.PLAYLISTS, ChannelTabs.CHANNELS);
}
}

Expand Down Expand Up @@ -789,11 +773,8 @@ public void testVerified() throws Exception {
@Test
@Override
public void testTabs() throws Exception {
Set<String> tabs = extractor.getTabs().stream()
.map(linkHandler -> linkHandler.getContentFilters().get(0)).collect(Collectors.toSet());
assertTrue(tabs.contains(ChannelTabs.VIDEOS));
assertTrue(tabs.contains(ChannelTabs.PLAYLISTS));
assertTrue(tabs.contains(ChannelTabs.CHANNELS));
ExtractorAsserts.assertTabs(extractor.getTabs(),
ChannelTabs.VIDEOS, ChannelTabs.PLAYLISTS, ChannelTabs.CHANNELS);
}
}

Expand Down Expand Up @@ -907,13 +888,9 @@ public void testVerified() throws Exception {
@Test
@Override
public void testTabs() throws Exception {
Set<String> tabs = extractor.getTabs().stream()
.map(linkHandler -> linkHandler.getContentFilters().get(0)).collect(Collectors.toSet());
assertTrue(tabs.contains(ChannelTabs.VIDEOS));
assertTrue(tabs.contains(ChannelTabs.SHORTS));
assertTrue(tabs.contains(ChannelTabs.LIVESTREAMS));
assertTrue(tabs.contains(ChannelTabs.PLAYLISTS));
assertTrue(tabs.contains(ChannelTabs.CHANNELS));
ExtractorAsserts.assertTabs(extractor.getTabs(),
ChannelTabs.VIDEOS, ChannelTabs.SHORTS, ChannelTabs.LIVESTREAMS,
ChannelTabs.PLAYLISTS, ChannelTabs.CHANNELS);
}
}
}

0 comments on commit 2adc2ca

Please sign in to comment.