Fixed `SoundcloudStreamLinkHandlerFactoryTest`

* Removed the unnecessary ``public``
* Use parameterized tests
* One song got removed (which caused the test failure), replaced it with another song
This commit is contained in:
litetex 2022-07-30 15:05:13 +02:00
parent 504f81036e
commit bf3ae5e679

View file

@ -2,6 +2,9 @@ package org.schabi.newpipe.extractor.services.soundcloud;
import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;
import org.junit.jupiter.params.provider.ValueSource;
import org.schabi.newpipe.downloader.DownloaderTestImpl; import org.schabi.newpipe.downloader.DownloaderTestImpl;
import org.schabi.newpipe.extractor.NewPipe; import org.schabi.newpipe.extractor.NewPipe;
import org.schabi.newpipe.extractor.exceptions.ParsingException; import org.schabi.newpipe.extractor.exceptions.ParsingException;
@ -25,57 +28,54 @@ public class SoundcloudStreamLinkHandlerFactoryTest {
} }
@Test @Test
public void getIdWithNullAsUrl() { void getIdWithNullAsUrl() {
assertThrows(IllegalArgumentException.class, () -> linkHandler.fromUrl(null)); assertThrows(IllegalArgumentException.class, () -> linkHandler.fromUrl(null));
} }
@Test @ParameterizedTest
public void getIdForInvalidUrls() { @ValueSource(strings = {
List<String> invalidUrls = new ArrayList<>(50); "https://soundcloud.com/liluzivert/t.e.s.t",
invalidUrls.add("https://soundcloud.com/liluzivert/t.e.s.t"); "https://soundcloud.com/liluzivert/tracks",
invalidUrls.add("https://soundcloud.com/liluzivert/tracks"); "https://soundcloud.com/"
invalidUrls.add("https://soundcloud.com/"); })
for (String invalidUrl : invalidUrls) { void getIdForInvalidUrls(final String invalidUrl) {
Throwable exception = null; assertThrows(ParsingException.class, () -> linkHandler.fromUrl(invalidUrl).getId());
try {
linkHandler.fromUrl(invalidUrl).getId();
} catch (ParsingException e) {
exception = e;
}
if (exception == null) {
fail("Expected ParsingException for url: " + invalidUrl);
}
}
} }
@Test @ParameterizedTest
public void getId() throws Exception { @CsvSource(value = {
assertEquals("309689103", linkHandler.fromUrl("https://soundcloud.com/liluzivert/15-ysl").getId()); "309689103,https://soundcloud.com/liluzivert/15-ysl",
assertEquals("309689082", linkHandler.fromUrl("https://www.soundcloud.com/liluzivert/15-luv-scars-ko").getId()); "309689082,https://www.soundcloud.com/liluzivert/15-luv-scars-ko",
assertEquals("309689035", linkHandler.fromUrl("http://soundcloud.com/liluzivert/15-boring-shit").getId()); "309689035,http://soundcloud.com/liluzivert/15-boring-shit",
assertEquals("259273264", linkHandler.fromUrl("https://soundcloud.com/liluzivert/ps-qs-produced-by-don-cannon/").getId()); "259273264,https://soundcloud.com/liluzivert/ps-qs-produced-by-don-cannon/",
assertEquals("294488599", linkHandler.fromUrl("http://www.soundcloud.com/liluzivert/secure-the-bag-produced-by-glohan-beats").getId()); "294488599,http://www.soundcloud.com/liluzivert/secure-the-bag-produced-by-glohan-beats",
assertEquals("294488438", linkHandler.fromUrl("HtTpS://sOuNdClOuD.cOm/LiLuZiVeRt/In-O4-pRoDuCeD-bY-dP-bEaTz").getId()); "245710200,HtTpS://sOuNdClOuD.cOm/lIeuTeNaNt_rAe/bOtS-wAs-wOlLeN-wIr-tRinKeN",
assertEquals("294488147", linkHandler.fromUrl("https://soundcloud.com/liluzivert/fresh-produced-by-zaytoven#t=69").getId()); "294488147,https://soundcloud.com/liluzivert/fresh-produced-by-zaytoven#t=69",
assertEquals("294487876", linkHandler.fromUrl("https://soundcloud.com/liluzivert/threesome-produced-by-zaytoven#t=1:09").getId()); "294487876,https://soundcloud.com/liluzivert/threesome-produced-by-zaytoven#t=1:09",
assertEquals("294487684", linkHandler.fromUrl("https://soundcloud.com/liluzivert/blonde-brigitte-produced-manny-fresh#t=1:9").getId()); "294487684,https://soundcloud.com/liluzivert/blonde-brigitte-produced-manny-fresh#t=1:9",
assertEquals("294487428", linkHandler.fromUrl("https://soundcloud.com/liluzivert/today-produced-by-c-note#t=1m9s").getId()); "294487428,https://soundcloud.com/liluzivert/today-produced-by-c-note#t=1m9s",
assertEquals("294487157", linkHandler.fromUrl("https://soundcloud.com/liluzivert/changed-my-phone-produced-by-c-note#t=1m09s").getId()); "294487157,https://soundcloud.com/liluzivert/changed-my-phone-produced-by-c-note#t=1m09s",
assertEquals("44556776", linkHandler.fromUrl("https://soundcloud.com/kechuspider-sets-1/last-days").getId()); "44556776,https://soundcloud.com/kechuspider-sets-1/last-days"
})
void getId(final String expectedId, final String url) throws ParsingException {
assertEquals(expectedId, linkHandler.fromUrl(url).getId());
} }
@Test @ParameterizedTest
public void testAcceptUrl() throws ParsingException { @ValueSource(strings = {
assertTrue(linkHandler.acceptUrl("https://soundcloud.com/liluzivert/15-ysl")); "https://soundcloud.com/liluzivert/15-ysl",
assertTrue(linkHandler.acceptUrl("https://www.soundcloud.com/liluzivert/15-luv-scars-ko")); "https://www.soundcloud.com/liluzivert/15-luv-scars-ko",
assertTrue(linkHandler.acceptUrl("http://soundcloud.com/liluzivert/15-boring-shit")); "http://soundcloud.com/liluzivert/15-boring-shit",
assertTrue(linkHandler.acceptUrl("http://www.soundcloud.com/liluzivert/secure-the-bag-produced-by-glohan-beats")); "http://www.soundcloud.com/liluzivert/secure-the-bag-produced-by-glohan-beats",
assertTrue(linkHandler.acceptUrl("HtTpS://sOuNdClOuD.cOm/LiLuZiVeRt/In-O4-pRoDuCeD-bY-dP-bEaTz")); "HtTpS://sOuNdClOuD.cOm/LiLuZiVeRt/In-O4-pRoDuCeD-bY-dP-bEaTz",
assertTrue(linkHandler.acceptUrl("https://soundcloud.com/liluzivert/fresh-produced-by-zaytoven#t=69")); "https://soundcloud.com/liluzivert/fresh-produced-by-zaytoven#t=69",
assertTrue(linkHandler.acceptUrl("https://soundcloud.com/liluzivert/threesome-produced-by-zaytoven#t=1:09")); "https://soundcloud.com/liluzivert/threesome-produced-by-zaytoven#t=1:09",
assertTrue(linkHandler.acceptUrl("https://soundcloud.com/liluzivert/blonde-brigitte-produced-manny-fresh#t=1:9")); "https://soundcloud.com/liluzivert/blonde-brigitte-produced-manny-fresh#t=1:9",
assertTrue(linkHandler.acceptUrl("https://soundcloud.com/liluzivert/today-produced-by-c-note#t=1m9s")); "https://soundcloud.com/liluzivert/today-produced-by-c-note#t=1m9s",
assertTrue(linkHandler.acceptUrl("https://soundcloud.com/liluzivert/changed-my-phone-produced-by-c-note#t=1m09s")); "https://soundcloud.com/liluzivert/changed-my-phone-produced-by-c-note#t=1m09s"
})
void testAcceptUrl(final String url) throws ParsingException {
assertTrue(linkHandler.acceptUrl(url));
} }
} }