[Bandcamp] Add support for mocks in unit tests

This commit is contained in:
TobiGr 2024-05-14 09:20:55 +02:00
parent fafd471606
commit 292f05f7ea
16 changed files with 83 additions and 60 deletions

View File

@ -4,7 +4,7 @@ package org.schabi.newpipe.extractor.services.bandcamp;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.schabi.newpipe.downloader.DownloaderTestImpl;
import org.schabi.newpipe.downloader.DownloaderFactory;
import org.schabi.newpipe.extractor.NewPipe;
import org.schabi.newpipe.extractor.channel.ChannelExtractor;
import org.schabi.newpipe.extractor.channel.tabs.ChannelTabs;
@ -18,12 +18,12 @@ import static org.schabi.newpipe.extractor.ExtractorAsserts.assertTabsContain;
import static org.schabi.newpipe.extractor.ServiceList.Bandcamp;
public class BandcampChannelExtractorTest implements BaseChannelExtractorTest {
private static final String RESOURCE_PATH = DownloaderFactory.RESOURCE_PATH + "services/bandcamp/extractor/channel";
private static ChannelExtractor extractor;
@BeforeAll
public static void setUp() throws Exception {
NewPipe.init(DownloaderTestImpl.getInstance());
NewPipe.init(DownloaderFactory.getDownloader(RESOURCE_PATH));
extractor = Bandcamp.getChannelExtractor("https://toupie.bandcamp.com/releases");
extractor.fetchPage();
}

View File

@ -4,23 +4,28 @@ package org.schabi.newpipe.extractor.services.bandcamp;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.schabi.newpipe.downloader.DownloaderTestImpl;
import org.schabi.newpipe.downloader.DownloaderFactory;
import org.schabi.newpipe.extractor.NewPipe;
import org.schabi.newpipe.extractor.exceptions.ParsingException;
import org.schabi.newpipe.extractor.services.bandcamp.linkHandler.BandcampChannelLinkHandlerFactory;
import java.io.IOException;
import static org.junit.jupiter.api.Assertions.*;
/**
* Test for {@link BandcampChannelLinkHandlerFactory}
*/
public class BandcampChannelLinkHandlerFactoryTest {
private static final String RESOURCE_PATH = DownloaderFactory.RESOURCE_PATH + "services/bandcamp/extractor/linkHandler/channel";
private static BandcampChannelLinkHandlerFactory linkHandler;
@BeforeAll
public static void setUp() {
public static void setUp() throws IOException {
// BandcampChannelLinkHandlerFactory needs a Downloader to check if domain is supported
NewPipe.init(DownloaderFactory.getDownloader(RESOURCE_PATH));
linkHandler = BandcampChannelLinkHandlerFactory.getInstance();
NewPipe.init(DownloaderTestImpl.getInstance());
}
@Test

View File

@ -1,34 +1,30 @@
package org.schabi.newpipe.extractor.services.bandcamp;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.schabi.newpipe.downloader.DownloaderTestImpl;
import org.schabi.newpipe.downloader.DownloaderFactory;
import org.schabi.newpipe.extractor.InfoItem;
import org.schabi.newpipe.extractor.NewPipe;
import org.schabi.newpipe.extractor.StreamingService;
import org.schabi.newpipe.extractor.channel.tabs.ChannelTabExtractor;
import org.schabi.newpipe.extractor.channel.tabs.ChannelTabs;
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
import org.schabi.newpipe.extractor.exceptions.ParsingException;
import org.schabi.newpipe.extractor.services.BaseListExtractorTest;
import org.schabi.newpipe.extractor.services.DefaultListExtractorTest;
import org.schabi.newpipe.extractor.services.bandcamp.extractors.BandcampChannelTabExtractor;
import java.io.IOException;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.schabi.newpipe.extractor.ServiceList.Bandcamp;
import static org.schabi.newpipe.extractor.ServiceList.PeerTube;
import static org.schabi.newpipe.extractor.services.DefaultTests.defaultTestRelatedItems;
class BandcampChannelTabExtractorTest {
private static final String RESOURCE_PATH = DownloaderFactory.RESOURCE_PATH + "services/bandcamp/extractor/channel/tab/";
static class Tracks extends DefaultListExtractorTest<ChannelTabExtractor> {
private static BandcampChannelTabExtractor extractor;
@BeforeAll
static void setUp() throws IOException, ExtractionException {
NewPipe.init(DownloaderTestImpl.getInstance());
NewPipe.init(DownloaderFactory.getDownloader(RESOURCE_PATH + "tracks"));
extractor = (BandcampChannelTabExtractor) Bandcamp
.getChannelTabExtractorFromId("2464198920", ChannelTabs.TRACKS);
extractor.fetchPage();
@ -49,7 +45,7 @@ class BandcampChannelTabExtractorTest {
@BeforeAll
static void setUp() throws IOException, ExtractionException {
NewPipe.init(DownloaderTestImpl.getInstance());
NewPipe.init(DownloaderFactory.getDownloader(RESOURCE_PATH + "albums"));
extractor = (BandcampChannelTabExtractor) Bandcamp
.getChannelTabExtractorFromId("2450875064", ChannelTabs.ALBUMS);
extractor.fetchPage();

View File

@ -2,7 +2,7 @@ package org.schabi.newpipe.extractor.services.bandcamp;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.schabi.newpipe.downloader.DownloaderTestImpl;
import org.schabi.newpipe.downloader.DownloaderFactory;
import org.schabi.newpipe.extractor.ListExtractor;
import org.schabi.newpipe.extractor.NewPipe;
import org.schabi.newpipe.extractor.comments.CommentsExtractor;
@ -20,11 +20,12 @@ import static org.schabi.newpipe.extractor.ServiceList.Bandcamp;
public class BandcampCommentsExtractorTest {
private static final String RESOURCE_PATH = DownloaderFactory.RESOURCE_PATH + "services/bandcamp/extractor/comments";
private static CommentsExtractor extractor;
@BeforeAll
public static void setUp() throws ExtractionException, IOException {
NewPipe.init(DownloaderTestImpl.getInstance());
NewPipe.init(DownloaderFactory.getDownloader(RESOURCE_PATH));
extractor = Bandcamp.getCommentsExtractor("https://floatingpoints.bandcamp.com/album/promises");
extractor.fetchPage();
}

View File

@ -4,11 +4,13 @@ package org.schabi.newpipe.extractor.services.bandcamp;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.schabi.newpipe.downloader.DownloaderTestImpl;
import org.schabi.newpipe.downloader.DownloaderFactory;
import org.schabi.newpipe.extractor.NewPipe;
import org.schabi.newpipe.extractor.exceptions.ParsingException;
import org.schabi.newpipe.extractor.services.bandcamp.linkHandler.BandcampCommentsLinkHandlerFactory;
import java.io.IOException;
import static org.junit.jupiter.api.Assertions.*;
/**
@ -16,12 +18,14 @@ import static org.junit.jupiter.api.Assertions.*;
*/
public class BandcampCommentsLinkHandlerFactoryTest {
private static final String RESOURCE_PATH = DownloaderFactory.RESOURCE_PATH + "services/bandcamp/extractor/linkHandler/comments";
private static BandcampCommentsLinkHandlerFactory linkHandler;
@BeforeAll
public static void setUp() {
public static void setUp() throws IOException {
// BandcampCommentsLinkHandlerFactory needs a Downloader to check if domain is supported
NewPipe.init(DownloaderFactory.getDownloader(RESOURCE_PATH));
linkHandler = BandcampCommentsLinkHandlerFactory.getInstance();
NewPipe.init(DownloaderTestImpl.getInstance());
}
@Test

View File

@ -4,7 +4,7 @@ package org.schabi.newpipe.extractor.services.bandcamp;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.schabi.newpipe.downloader.DownloaderTestImpl;
import org.schabi.newpipe.downloader.DownloaderFactory;
import org.schabi.newpipe.extractor.NewPipe;
import org.schabi.newpipe.extractor.Page;
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
@ -26,11 +26,12 @@ import static org.schabi.newpipe.extractor.ServiceList.Bandcamp;
*/
public class BandcampFeaturedExtractorTest implements BaseListExtractorTest {
private static final String RESOURCE_PATH = DownloaderFactory.RESOURCE_PATH + "services/bandcamp/extractor/featured";
private static BandcampFeaturedExtractor extractor;
@BeforeAll
public static void setUp() throws ExtractionException, IOException {
NewPipe.init(DownloaderTestImpl.getInstance());
NewPipe.init(DownloaderFactory.getDownloader(RESOURCE_PATH));
extractor = (BandcampFeaturedExtractor) Bandcamp
.getKioskList().getDefaultKioskExtractor();
extractor.fetchPage();

View File

@ -5,7 +5,7 @@ package org.schabi.newpipe.extractor.services.bandcamp;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Timeout;
import org.schabi.newpipe.downloader.DownloaderTestImpl;
import org.schabi.newpipe.downloader.DownloaderFactory;
import org.schabi.newpipe.extractor.NewPipe;
import org.schabi.newpipe.extractor.exceptions.ContentNotAvailableException;
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
@ -36,10 +36,11 @@ import static org.schabi.newpipe.extractor.ServiceList.Bandcamp;
* Tests for {@link BandcampPlaylistExtractor}
*/
public class BandcampPlaylistExtractorTest {
private static final String RESOURCE_PATH = DownloaderFactory.RESOURCE_PATH + "services/bandcamp/extractor/playlist/";
@BeforeAll
public static void setUp() {
NewPipe.init(DownloaderTestImpl.getInstance());
public static void setUp() throws IOException {
NewPipe.init(DownloaderFactory.getDownloader(RESOURCE_PATH));
}
/**
@ -110,7 +111,7 @@ public class BandcampPlaylistExtractorTest {
@BeforeAll
public static void setUp() throws ExtractionException, IOException {
NewPipe.init(DownloaderTestImpl.getInstance());
NewPipe.init(DownloaderFactory.getDownloader(RESOURCE_PATH + "coming-of-age"));
extractor = Bandcamp.getPlaylistExtractor("https://macbenson.bandcamp.com/album/coming-of-age");
extractor.fetchPage();
}

View File

@ -4,11 +4,13 @@ package org.schabi.newpipe.extractor.services.bandcamp;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.schabi.newpipe.downloader.DownloaderTestImpl;
import org.schabi.newpipe.downloader.DownloaderFactory;
import org.schabi.newpipe.extractor.NewPipe;
import org.schabi.newpipe.extractor.exceptions.ParsingException;
import org.schabi.newpipe.extractor.services.bandcamp.linkHandler.BandcampPlaylistLinkHandlerFactory;
import java.io.IOException;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
@ -17,12 +19,14 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
*/
public class BandcampPlaylistLinkHandlerFactoryTest {
private static final String RESOURCE_PATH = DownloaderFactory.RESOURCE_PATH + "services/bandcamp/extractor/linkHandler/playlist";
private static BandcampPlaylistLinkHandlerFactory linkHandler;
@BeforeAll
public static void setUp() {
public static void setUp() throws IOException {
// BandcampPlaylistLinkHandlerFactory needs a Downloader to check if the domain is supported
NewPipe.init(DownloaderFactory.getDownloader(RESOURCE_PATH));
linkHandler = BandcampPlaylistLinkHandlerFactory.getInstance();
NewPipe.init(DownloaderTestImpl.getInstance());
}
@Test

View File

@ -4,7 +4,7 @@ package org.schabi.newpipe.extractor.services.bandcamp;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.schabi.newpipe.downloader.DownloaderTestImpl;
import org.schabi.newpipe.downloader.DownloaderFactory;
import org.schabi.newpipe.extractor.NewPipe;
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
import org.schabi.newpipe.extractor.services.BaseListExtractorTest;
@ -23,11 +23,12 @@ import static org.schabi.newpipe.extractor.ServiceList.Bandcamp;
*/
public class BandcampRadioExtractorTest implements BaseListExtractorTest {
private static final String RESOURCE_PATH = DownloaderFactory.RESOURCE_PATH + "services/bandcamp/extractor/radio";
private static BandcampRadioExtractor extractor;
@BeforeAll
public static void setUp() throws ExtractionException, IOException {
NewPipe.init(DownloaderTestImpl.getInstance());
NewPipe.init(DownloaderFactory.getDownloader(RESOURCE_PATH));
extractor = (BandcampRadioExtractor) Bandcamp
.getKioskList()
.getExtractorById("Radio", null);

View File

@ -1,13 +1,13 @@
// Created by Fynn Godau 2019, licensed GNU GPL version 3 or later
package org.schabi.newpipe.extractor.services.bandcamp;
package org.schabi.newpipe.extractor.services.bandcamp.search;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.schabi.newpipe.extractor.ServiceList.Bandcamp;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.schabi.newpipe.downloader.DownloaderTestImpl;
import org.schabi.newpipe.downloader.DownloaderFactory;
import org.schabi.newpipe.extractor.InfoItem;
import org.schabi.newpipe.extractor.ListExtractor;
import org.schabi.newpipe.extractor.NewPipe;
@ -17,6 +17,7 @@ import org.schabi.newpipe.extractor.exceptions.ExtractionException;
import org.schabi.newpipe.extractor.playlist.PlaylistInfoItem;
import org.schabi.newpipe.extractor.search.SearchExtractor;
import org.schabi.newpipe.extractor.services.DefaultSearchExtractorTest;
import org.schabi.newpipe.extractor.services.bandcamp.BandcampTestUtils;
import org.schabi.newpipe.extractor.services.bandcamp.extractors.BandcampSearchExtractor;
import org.schabi.newpipe.extractor.stream.StreamInfoItem;
@ -29,10 +30,11 @@ import javax.annotation.Nullable;
*/
public class BandcampSearchExtractorTest {
@BeforeAll
public static void setUp() {
NewPipe.init(DownloaderTestImpl.getInstance());
private static final String RESOURCE_PATH = DownloaderFactory.RESOURCE_PATH + "services/bandcamp/extractor/search";
@BeforeAll
public static void setUp() throws IOException {
NewPipe.init(DownloaderFactory.getDownloader(RESOURCE_PATH));
}
/**
@ -108,7 +110,7 @@ public class BandcampSearchExtractorTest {
@BeforeAll
public static void setUp() throws Exception {
NewPipe.init(DownloaderTestImpl.getInstance());
NewPipe.init(DownloaderFactory.getDownloader(RESOURCE_PATH + "default"));
extractor = Bandcamp.getSearchExtractor(QUERY);
extractor.fetchPage();
}

View File

@ -1,11 +1,9 @@
// Created by Fynn Godau 2019, licensed GNU GPL version 3 or later
package org.schabi.newpipe.extractor.services.bandcamp;
package org.schabi.newpipe.extractor.services.bandcamp.search;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.schabi.newpipe.downloader.DownloaderTestImpl;
import org.schabi.newpipe.extractor.NewPipe;
import org.schabi.newpipe.extractor.exceptions.ParsingException;
import org.schabi.newpipe.extractor.services.bandcamp.linkHandler.BandcampSearchQueryHandlerFactory;
@ -18,8 +16,6 @@ public class BandcampSearchQueryHandlerFactoryTest {
@BeforeAll
public static void setUp() {
NewPipe.init(DownloaderTestImpl.getInstance());
searchQuery = (BandcampSearchQueryHandlerFactory) Bandcamp
.getSearchQHFactory();
}

View File

@ -1,10 +1,10 @@
// Created by Fynn Godau 2019, licensed GNU GPL version 3 or later
package org.schabi.newpipe.extractor.services.bandcamp;
package org.schabi.newpipe.extractor.services.bandcamp.search;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.schabi.newpipe.downloader.DownloaderTestImpl;
import org.schabi.newpipe.downloader.DownloaderFactory;
import org.schabi.newpipe.extractor.NewPipe;
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
import org.schabi.newpipe.extractor.services.bandcamp.extractors.BandcampSuggestionExtractor;
@ -20,11 +20,12 @@ import static org.schabi.newpipe.extractor.ServiceList.Bandcamp;
*/
public class BandcampSuggestionExtractorTest {
private static final String RESOURCE_PATH = DownloaderFactory.RESOURCE_PATH + "services/bandcamp/extractor/search/suggestion";
private static BandcampSuggestionExtractor extractor;
@BeforeAll
public static void setUp() {
NewPipe.init(DownloaderTestImpl.getInstance());
public static void setUp() throws IOException {
NewPipe.init(DownloaderFactory.getDownloader(RESOURCE_PATH));
extractor = (BandcampSuggestionExtractor) Bandcamp.getSuggestionExtractor();
}

View File

@ -1,20 +1,24 @@
package org.schabi.newpipe.extractor.services.bandcamp;
package org.schabi.newpipe.extractor.services.bandcamp.stream;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.schabi.newpipe.extractor.ServiceList.Bandcamp;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.schabi.newpipe.downloader.DownloaderTestImpl;
import org.schabi.newpipe.downloader.DownloaderFactory;
import org.schabi.newpipe.extractor.NewPipe;
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
import org.schabi.newpipe.extractor.exceptions.PaidContentException;
import java.io.IOException;
public class BandcampPaidStreamExtractorTest {
private static final String RESOURCE_PATH = DownloaderFactory.RESOURCE_PATH + "services/bandcamp/extractor/stream/paid";
@BeforeAll
public static void setUp() {
NewPipe.init(DownloaderTestImpl.getInstance());
public static void setUp() throws IOException {
NewPipe.init(DownloaderFactory.getDownloader(RESOURCE_PATH));
}
@Test

View File

@ -1,8 +1,8 @@
package org.schabi.newpipe.extractor.services.bandcamp;
package org.schabi.newpipe.extractor.services.bandcamp.stream;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.schabi.newpipe.downloader.DownloaderTestImpl;
import org.schabi.newpipe.downloader.DownloaderFactory;
import org.schabi.newpipe.extractor.ExtractorAsserts;
import org.schabi.newpipe.extractor.NewPipe;
import org.schabi.newpipe.extractor.StreamingService;
@ -11,6 +11,7 @@ import org.schabi.newpipe.extractor.exceptions.ExtractionException;
import org.schabi.newpipe.extractor.exceptions.ParsingException;
import org.schabi.newpipe.extractor.services.DefaultStreamExtractorTest;
import org.schabi.newpipe.extractor.services.DefaultTests;
import org.schabi.newpipe.extractor.services.bandcamp.BandcampTestUtils;
import org.schabi.newpipe.extractor.services.bandcamp.extractors.BandcampRadioStreamExtractor;
import org.schabi.newpipe.extractor.stream.StreamExtractor;
import org.schabi.newpipe.extractor.stream.StreamType;
@ -25,6 +26,7 @@ import static org.junit.jupiter.api.Assertions.*;
import static org.schabi.newpipe.extractor.ServiceList.Bandcamp;
public class BandcampRadioStreamExtractorTest extends DefaultStreamExtractorTest {
private static final String RESOURCE_PATH = DownloaderFactory.RESOURCE_PATH + "services/bandcamp/extractor/stream/radio";
private static StreamExtractor extractor;
@ -32,7 +34,7 @@ public class BandcampRadioStreamExtractorTest extends DefaultStreamExtractorTest
@BeforeAll
public static void setUp() throws IOException, ExtractionException {
NewPipe.init(DownloaderTestImpl.getInstance());
NewPipe.init(DownloaderFactory.getDownloader(RESOURCE_PATH));
extractor = Bandcamp.getStreamExtractor(URL);
extractor.fetchPage();
}

View File

@ -1,15 +1,16 @@
// Created by Fynn Godau 2019, licensed GNU GPL version 3 or later
package org.schabi.newpipe.extractor.services.bandcamp;
package org.schabi.newpipe.extractor.services.bandcamp.stream;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.schabi.newpipe.downloader.DownloaderTestImpl;
import org.schabi.newpipe.downloader.DownloaderFactory;
import org.schabi.newpipe.extractor.NewPipe;
import org.schabi.newpipe.extractor.StreamingService;
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
import org.schabi.newpipe.extractor.exceptions.ParsingException;
import org.schabi.newpipe.extractor.services.DefaultStreamExtractorTest;
import org.schabi.newpipe.extractor.services.bandcamp.BandcampTestUtils;
import org.schabi.newpipe.extractor.services.bandcamp.extractors.BandcampExtractorHelper;
import org.schabi.newpipe.extractor.services.bandcamp.extractors.BandcampStreamExtractor;
import org.schabi.newpipe.extractor.stream.StreamExtractor;
@ -27,11 +28,12 @@ import static org.schabi.newpipe.extractor.ServiceList.Bandcamp;
*/
public class BandcampStreamExtractorTest extends DefaultStreamExtractorTest {
private static final String RESOURCE_PATH = DownloaderFactory.RESOURCE_PATH + "services/bandcamp/extractor/stream/";
private static BandcampStreamExtractor extractor;
@BeforeAll
public static void setUp() throws ExtractionException, IOException {
NewPipe.init(DownloaderTestImpl.getInstance());
NewPipe.init(DownloaderFactory.getDownloader(RESOURCE_PATH));
extractor = (BandcampStreamExtractor) Bandcamp
.getStreamExtractor("https://teaganbear.bandcamp.com/track/just-for-the-halibut");

View File

@ -1,14 +1,16 @@
// Created by Fynn Godau 2019, licensed GNU GPL version 3 or later
package org.schabi.newpipe.extractor.services.bandcamp;
package org.schabi.newpipe.extractor.services.bandcamp.stream;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.schabi.newpipe.downloader.DownloaderTestImpl;
import org.schabi.newpipe.downloader.DownloaderFactory;
import org.schabi.newpipe.extractor.NewPipe;
import org.schabi.newpipe.extractor.exceptions.ParsingException;
import org.schabi.newpipe.extractor.services.bandcamp.linkHandler.BandcampStreamLinkHandlerFactory;
import java.io.IOException;
import static org.junit.jupiter.api.Assertions.*;
/**
@ -16,12 +18,13 @@ import static org.junit.jupiter.api.Assertions.*;
*/
public class BandcampStreamLinkHandlerFactoryTest {
private static final String RESOURCE_PATH = DownloaderFactory.RESOURCE_PATH + "services/bandcamp/extractor/linkHandler/stream";
private static BandcampStreamLinkHandlerFactory linkHandler;
@BeforeAll
public static void setUp() {
public static void setUp() throws IOException {
NewPipe.init(DownloaderFactory.getDownloader(RESOURCE_PATH));
linkHandler = BandcampStreamLinkHandlerFactory.getInstance();
NewPipe.init(DownloaderTestImpl.getInstance());
}
@Test