From 2a31db8816f36f07734b1f5e734ab78edeb687ee Mon Sep 17 00:00:00 2001 From: scavchik Date: Tue, 12 Sep 2023 19:14:58 -0400 Subject: [PATCH] Fixed tests. Due to removed youtube-dl all commands use yt-dlp's parameters '--compat-options' and 'all'. They need to be taken into account in the tests --- .../YoutubeDlCommandBuilderTests.java | 20 +++++++----- .../YoutubeDlCommandHelperTests.java | 31 ++++++++++--------- 2 files changed, 29 insertions(+), 22 deletions(-) diff --git a/src/test/java/com/github/engatec/vdl/core/youtubedl/YoutubeDlCommandBuilderTests.java b/src/test/java/com/github/engatec/vdl/core/youtubedl/YoutubeDlCommandBuilderTests.java index 25df544..f48b0ac 100644 --- a/src/test/java/com/github/engatec/vdl/core/youtubedl/YoutubeDlCommandBuilderTests.java +++ b/src/test/java/com/github/engatec/vdl/core/youtubedl/YoutubeDlCommandBuilderTests.java @@ -21,14 +21,20 @@ static void setUp() { } private void doAssertions(List command, String key) { - assertThat(command).hasSize(2); - assertThat(command).contains(key, atIndex(1)); + assertThat(command).hasSize(4); + assertThat(command) + .contains("--compat-options", atIndex(1)) + .contains("all", atIndex(2)) + .contains(key, atIndex(3)); } private void doAssertions(List command, String key, String value) { - assertThat(command).hasSize(3); - assertThat(command).contains(key, atIndex(1)); - assertThat(command).contains(value, atIndex(2)); + assertThat(command).hasSize(5); + assertThat(command) + .contains("--compat-options", atIndex(1)) + .contains("all", atIndex(2)) + .contains(key, atIndex(3)) + .contains(value, atIndex(4)); } @Nested @@ -129,7 +135,7 @@ class SubtutlesOptionsTests { void shouldCreateWriteSubWithSubLang() { List command = YoutubeDlCommandBuilder.newInstance().writeSub(Set.of("en", "ru")).buildAsList(); assertThat(command) - .hasSize(4) + .hasSize(6) .containsAll(List.of("--write-sub", "--sub-lang")) .containsAnyOf("en,ru", "ru,en"); // Since set is passed, can't be sure what order is going to be when joining the elements } @@ -138,7 +144,7 @@ void shouldCreateWriteSubWithSubLang() { void shouldCreateWriteSubAndAllSubsWithoutSubLang() { List command = YoutubeDlCommandBuilder.newInstance().writeSub(Set.of()).buildAsList(); assertThat(command) - .hasSize(3) + .hasSize(5) .contains("--write-sub", "--all-subs"); } diff --git a/src/test/java/com/github/engatec/vdl/core/youtubedl/YoutubeDlCommandHelperTests.java b/src/test/java/com/github/engatec/vdl/core/youtubedl/YoutubeDlCommandHelperTests.java index d184f77..8a72ef8 100644 --- a/src/test/java/com/github/engatec/vdl/core/youtubedl/YoutubeDlCommandHelperTests.java +++ b/src/test/java/com/github/engatec/vdl/core/youtubedl/YoutubeDlCommandHelperTests.java @@ -3,6 +3,7 @@ import java.nio.file.Files; import java.nio.file.Path; import java.util.List; +import java.util.function.Consumer; import com.github.engatec.vdl.TestHelper; import com.github.engatec.vdl.core.ApplicationContext; @@ -66,6 +67,16 @@ private void doAssertions(List command, String key, String value) { assertThat(command).contains(value, atIndex(2)); } + private List buildCommandGeneric(Consumer propertiesSetter) { + YoutubeDlCommandBuilder commandBuilder = YoutubeDlCommandBuilder.newInstance(); + propertiesSetter.accept(commandBuilder); + List commandList = commandBuilder.buildAsList(); + return commandList.stream() + .filter(it -> !it.equals("--compat-options")) + .filter(it -> !it.equals("all")) + .toList(); + } + @Nested @DisplayName("General options") class GeneralOptionsTests { @@ -81,9 +92,7 @@ void setUp() { } private List buildCommand() { - YoutubeDlCommandBuilder commandBuilder = YoutubeDlCommandBuilder.newInstance(); - YoutubeDlCommandHelper.setGeneralOptions(commandBuilder); - return commandBuilder.buildAsList(); + return buildCommandGeneric(YoutubeDlCommandHelper::setGeneralOptions); } @Test @@ -157,9 +166,7 @@ void setUp() { } private List buildCommand() { - YoutubeDlCommandBuilder commandBuilder = YoutubeDlCommandBuilder.newInstance(); - YoutubeDlCommandHelper.setSubtitlesOptions(commandBuilder); - return commandBuilder.buildAsList(); + return buildCommandGeneric(YoutubeDlCommandHelper::setSubtitlesOptions); } @Test @@ -211,9 +218,7 @@ void setUp() { } private List buildCommand() { - YoutubeDlCommandBuilder commandBuilder = YoutubeDlCommandBuilder.newInstance(); - YoutubeDlCommandHelper.setDownloadOptions(commandBuilder); - return commandBuilder.buildAsList(); + return buildCommandGeneric(YoutubeDlCommandHelper::setDownloadOptions); } @ParameterizedTest @@ -247,9 +252,7 @@ void setUp() { } private List buildCommand() { - YoutubeDlCommandBuilder commandBuilder = YoutubeDlCommandBuilder.newInstance(); - YoutubeDlCommandHelper.setNetworkOptions(commandBuilder); - return commandBuilder.buildAsList(); + return buildCommandGeneric(YoutubeDlCommandHelper::setNetworkOptions); } @Test @@ -336,9 +339,7 @@ void setUp() { } private List buildCommand() { - YoutubeDlCommandBuilder commandBuilder = YoutubeDlCommandBuilder.newInstance(); - YoutubeDlCommandHelper.setAuthenticationOptions(commandBuilder); - return commandBuilder.buildAsList(); + return buildCommandGeneric(YoutubeDlCommandHelper::setAuthenticationOptions); } @Test