mirror of
https://github.com/RatzzFatzz/MKVAudioSubtitleChanger.git
synced 2026-02-11 10:05:58 +01:00
Add tests for validation and extract command from Main
This commit is contained in:
@@ -1,64 +1,18 @@
|
|||||||
package at.pcgamingfreaks.mkvaudiosubtitlechanger;
|
package at.pcgamingfreaks.mkvaudiosubtitlechanger;
|
||||||
|
|
||||||
import at.pcgamingfreaks.mkvaudiosubtitlechanger.impl.FileFilter;
|
import at.pcgamingfreaks.mkvaudiosubtitlechanger.impl.CommandRunner;
|
||||||
import at.pcgamingfreaks.mkvaudiosubtitlechanger.impl.processors.FileProcessor;
|
|
||||||
import at.pcgamingfreaks.mkvaudiosubtitlechanger.impl.processors.MkvFileProcessor;
|
|
||||||
import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.InputConfig;
|
|
||||||
import at.pcgamingfreaks.mkvaudiosubtitlechanger.impl.validation.ValidationExecutionStrategy;
|
import at.pcgamingfreaks.mkvaudiosubtitlechanger.impl.validation.ValidationExecutionStrategy;
|
||||||
import at.pcgamingfreaks.mkvaudiosubtitlechanger.impl.processors.CachedFileProcessor;
|
|
||||||
import at.pcgamingfreaks.mkvaudiosubtitlechanger.impl.kernel.AttributeUpdaterKernel;
|
|
||||||
import at.pcgamingfreaks.mkvaudiosubtitlechanger.impl.kernel.CoherentAttributeUpdaterKernel;
|
|
||||||
import at.pcgamingfreaks.mkvaudiosubtitlechanger.impl.kernel.DefaultAttributeUpdaterKernel;
|
|
||||||
import at.pcgamingfreaks.mkvaudiosubtitlechanger.util.ProjectUtil;
|
|
||||||
import lombok.Getter;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.apache.logging.log4j.Level;
|
|
||||||
import org.apache.logging.log4j.core.config.Configurator;
|
|
||||||
import picocli.CommandLine;
|
import picocli.CommandLine;
|
||||||
|
|
||||||
@Slf4j
|
public class Main {
|
||||||
@CommandLine.Command(
|
|
||||||
name = "mkvaudiosubtitlechanger",
|
|
||||||
usageHelpAutoWidth = true,
|
|
||||||
customSynopsis = {
|
|
||||||
"mkvaudiosubtitlechanger -a <attributeConfig> [...<attributeConfig>] -l <libraryPath> [-s]",
|
|
||||||
"Example: mkvaudiosubtitlechanger -a eng:eng eng:ger -l /mnt/media/ -s",
|
|
||||||
""
|
|
||||||
},
|
|
||||||
requiredOptionMarker = '*',
|
|
||||||
sortOptions = false,
|
|
||||||
mixinStandardHelpOptions = true,
|
|
||||||
versionProvider = ProjectUtil.class
|
|
||||||
)
|
|
||||||
public class Main implements Runnable {
|
|
||||||
|
|
||||||
@Getter
|
|
||||||
@CommandLine.ArgGroup(exclusive = false)
|
|
||||||
private InputConfig config;
|
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
if (args.length == 0) {
|
if (args.length == 0) {
|
||||||
CommandLine.usage(Main.class, System.out);
|
CommandLine.usage(CommandRunner.class, System.out);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
new CommandLine(Main.class)
|
new CommandLine(CommandRunner.class)
|
||||||
.setExecutionStrategy(new ValidationExecutionStrategy())
|
.setExecutionStrategy(new ValidationExecutionStrategy())
|
||||||
.execute(args);
|
.execute(args);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
if (config.isDebug()) {
|
|
||||||
Configurator.setRootLevel(Level.DEBUG);
|
|
||||||
}
|
|
||||||
|
|
||||||
FileFilter fileFilter = new FileFilter(config.getExcluded(), config.getIncludePattern(), config.getFilterDate());
|
|
||||||
FileProcessor fileProcessor = new CachedFileProcessor(new MkvFileProcessor(config.getMkvToolNix(), fileFilter));
|
|
||||||
|
|
||||||
AttributeUpdaterKernel kernel = config.getCoherent() != null
|
|
||||||
? new CoherentAttributeUpdaterKernel(config, fileProcessor)
|
|
||||||
: new DefaultAttributeUpdaterKernel(config, fileProcessor);
|
|
||||||
kernel.execute();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,50 @@
|
|||||||
|
package at.pcgamingfreaks.mkvaudiosubtitlechanger.impl;
|
||||||
|
|
||||||
|
import at.pcgamingfreaks.mkvaudiosubtitlechanger.impl.kernel.AttributeUpdaterKernel;
|
||||||
|
import at.pcgamingfreaks.mkvaudiosubtitlechanger.impl.kernel.CoherentAttributeUpdaterKernel;
|
||||||
|
import at.pcgamingfreaks.mkvaudiosubtitlechanger.impl.kernel.DefaultAttributeUpdaterKernel;
|
||||||
|
import at.pcgamingfreaks.mkvaudiosubtitlechanger.impl.processors.CachedFileProcessor;
|
||||||
|
import at.pcgamingfreaks.mkvaudiosubtitlechanger.impl.processors.FileProcessor;
|
||||||
|
import at.pcgamingfreaks.mkvaudiosubtitlechanger.impl.processors.MkvFileProcessor;
|
||||||
|
import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.InputConfig;
|
||||||
|
import at.pcgamingfreaks.mkvaudiosubtitlechanger.util.ProjectUtil;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.apache.logging.log4j.Level;
|
||||||
|
import org.apache.logging.log4j.core.config.Configurator;
|
||||||
|
import picocli.CommandLine;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
@CommandLine.Command(
|
||||||
|
name = "mkvaudiosubtitlechanger",
|
||||||
|
usageHelpAutoWidth = true,
|
||||||
|
customSynopsis = {
|
||||||
|
"mkvaudiosubtitlechanger -a <attributeConfig> [...<attributeConfig>] -l <libraryPath> [-s]",
|
||||||
|
"Example: mkvaudiosubtitlechanger -a eng:eng eng:ger -l /mnt/media/ -s",
|
||||||
|
""
|
||||||
|
},
|
||||||
|
requiredOptionMarker = '*',
|
||||||
|
sortOptions = false,
|
||||||
|
mixinStandardHelpOptions = true,
|
||||||
|
versionProvider = ProjectUtil.class
|
||||||
|
)
|
||||||
|
public class CommandRunner implements Runnable {
|
||||||
|
@Getter
|
||||||
|
@CommandLine.ArgGroup(exclusive = false)
|
||||||
|
private InputConfig config;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
if (config.isDebug()) {
|
||||||
|
Configurator.setRootLevel(Level.DEBUG);
|
||||||
|
}
|
||||||
|
|
||||||
|
FileFilter fileFilter = new FileFilter(config.getExcluded(), config.getIncludePattern(), config.getFilterDate());
|
||||||
|
FileProcessor fileProcessor = new CachedFileProcessor(new MkvFileProcessor(config.getMkvToolNix(), fileFilter));
|
||||||
|
|
||||||
|
AttributeUpdaterKernel kernel = config.getCoherent() != null
|
||||||
|
? new CoherentAttributeUpdaterKernel(config, fileProcessor)
|
||||||
|
: new DefaultAttributeUpdaterKernel(config, fileProcessor);
|
||||||
|
kernel.execute();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,22 +3,17 @@ package at.pcgamingfreaks.mkvaudiosubtitlechanger.impl.kernel;
|
|||||||
import at.pcgamingfreaks.mkvaudiosubtitlechanger.exceptions.MkvToolNixException;
|
import at.pcgamingfreaks.mkvaudiosubtitlechanger.exceptions.MkvToolNixException;
|
||||||
import at.pcgamingfreaks.mkvaudiosubtitlechanger.impl.processors.AttributeProcessor;
|
import at.pcgamingfreaks.mkvaudiosubtitlechanger.impl.processors.AttributeProcessor;
|
||||||
import at.pcgamingfreaks.mkvaudiosubtitlechanger.impl.processors.FileProcessor;
|
import at.pcgamingfreaks.mkvaudiosubtitlechanger.impl.processors.FileProcessor;
|
||||||
import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.*;
|
import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.FileInfo;
|
||||||
import at.pcgamingfreaks.mkvaudiosubtitlechanger.util.DateUtils;
|
import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.InputConfig;
|
||||||
import at.pcgamingfreaks.mkvaudiosubtitlechanger.util.ProjectUtil;
|
import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.ResultStatistic;
|
||||||
import at.pcgamingfreaks.yaml.YAML;
|
|
||||||
import at.pcgamingfreaks.yaml.YamlInvalidContentException;
|
|
||||||
import lombok.SneakyThrows;
|
import lombok.SneakyThrows;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import me.tongfei.progressbar.ProgressBar;
|
import me.tongfei.progressbar.ProgressBar;
|
||||||
import me.tongfei.progressbar.ProgressBarBuilder;
|
import me.tongfei.progressbar.ProgressBarBuilder;
|
||||||
import me.tongfei.progressbar.ProgressBarStyle;
|
import me.tongfei.progressbar.ProgressBarStyle;
|
||||||
import net.harawata.appdirs.AppDirsFactory;
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.file.Path;
|
|
||||||
import java.util.Date;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
package at.pcgamingfreaks.mkvaudiosubtitlechanger.impl.validation;
|
package at.pcgamingfreaks.mkvaudiosubtitlechanger.impl.validation;
|
||||||
|
|
||||||
import at.pcgamingfreaks.mkvaudiosubtitlechanger.Main;
|
import at.pcgamingfreaks.mkvaudiosubtitlechanger.impl.CommandRunner;
|
||||||
import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.InputConfig;
|
import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.InputConfig;
|
||||||
import at.pcgamingfreaks.mkvaudiosubtitlechanger.util.ValidationUtil;
|
import at.pcgamingfreaks.mkvaudiosubtitlechanger.util.ValidationUtil;
|
||||||
import jakarta.validation.ConstraintViolation;
|
import jakarta.validation.ConstraintViolation;
|
||||||
@@ -18,7 +18,7 @@ public class ValidationExecutionStrategy implements CommandLine.IExecutionStrate
|
|||||||
|
|
||||||
private static void validate(CommandLine.Model.CommandSpec spec) {
|
private static void validate(CommandLine.Model.CommandSpec spec) {
|
||||||
Validator validator = ValidationUtil.getValidator();
|
Validator validator = ValidationUtil.getValidator();
|
||||||
Set<ConstraintViolation<InputConfig>> violations = validator.validate(((Main)spec.userObject()).getConfig());
|
Set<ConstraintViolation<InputConfig>> violations = validator.validate(((CommandRunner)spec.userObject()).getConfig());
|
||||||
|
|
||||||
if (!violations.isEmpty()) {
|
if (!violations.isEmpty()) {
|
||||||
StringBuilder errors = new StringBuilder();
|
StringBuilder errors = new StringBuilder();
|
||||||
|
|||||||
@@ -1,61 +0,0 @@
|
|||||||
package at.pcgamingfreaks.mkvaudiosubtitlechanger.config.fields;
|
|
||||||
|
|
||||||
import at.pcgamingfreaks.mkvaudiosubtitlechanger.Main;
|
|
||||||
import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.AttributeConfig;
|
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
import org.junit.jupiter.params.ParameterizedTest;
|
|
||||||
import org.junit.jupiter.params.provider.Arguments;
|
|
||||||
import org.junit.jupiter.params.provider.MethodSource;
|
|
||||||
import picocli.CommandLine;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.stream.Stream;
|
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.*;
|
|
||||||
|
|
||||||
class AttributeConfigTest {
|
|
||||||
|
|
||||||
private static Stream<Arguments> provideTestCases() {
|
|
||||||
return Stream.of(
|
|
||||||
Arguments.of(args("-a", "jpn:ger"), attrConf("jpn", "ger")),
|
|
||||||
Arguments.of(args("-a", "jpn:ger", "jpn:eng"), attrConf("jpn", "ger", "jpn", "eng")),
|
|
||||||
Arguments.of(args("-a", "jpn:ger", "jpn:OFF"), attrConf("jpn", "ger", "jpn", "OFF"))
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@ParameterizedTest
|
|
||||||
@MethodSource("provideTestCases")
|
|
||||||
void validate(String[] cmdArgs, AttributeConfig[] expectedConfig) {
|
|
||||||
Main underTest = new Main();
|
|
||||||
CommandLine.populateCommand(underTest, cmdArgs);
|
|
||||||
assertArrayEquals(expectedConfig, underTest.getConfig().getAttributeConfig());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void validate() {
|
|
||||||
Main sut = new Main();
|
|
||||||
assertThrows(CommandLine.MissingParameterException.class, () -> CommandLine.populateCommand(sut, new String[]{"-l", "/"}));
|
|
||||||
assertThrows(CommandLine.MissingParameterException.class, () -> CommandLine.populateCommand(sut, new String[]{"-l", "/", "-a"}));
|
|
||||||
assertThrows(CommandLine.ParameterException.class, () -> CommandLine.populateCommand(sut, new String[]{"-l", "/", "-a", "ger:"}));
|
|
||||||
assertThrows(CommandLine.ParameterException.class,
|
|
||||||
() -> CommandLine.populateCommand(sut, new String[]{"-l", "/", "-a", "ger:qwf"})); // Invalid language code
|
|
||||||
}
|
|
||||||
|
|
||||||
private static String[] args(String... args) {
|
|
||||||
String[] staticArray = new String[]{"-l", "/"};
|
|
||||||
String[] result = new String[staticArray.length + args.length];
|
|
||||||
System.arraycopy(staticArray, 0, result, 0, staticArray.length);
|
|
||||||
System.arraycopy(args, 0, result, staticArray.length, args.length);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static AttributeConfig[] attrConf(String... languages) {
|
|
||||||
AttributeConfig[] conf = new AttributeConfig[languages.length/2];
|
|
||||||
for (int i = 0; i < languages.length; i += 2) {
|
|
||||||
conf[i / 2] = new AttributeConfig(languages[i], languages[i+1]);
|
|
||||||
}
|
|
||||||
return conf;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,38 +0,0 @@
|
|||||||
package at.pcgamingfreaks.mkvaudiosubtitlechanger.config.fields;
|
|
||||||
|
|
||||||
import at.pcgamingfreaks.mkvaudiosubtitlechanger.Main;
|
|
||||||
import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.InputConfig;
|
|
||||||
import org.junit.jupiter.params.ParameterizedTest;
|
|
||||||
import org.junit.jupiter.params.provider.Arguments;
|
|
||||||
import org.junit.jupiter.params.provider.MethodSource;
|
|
||||||
import picocli.CommandLine;
|
|
||||||
|
|
||||||
import java.util.function.Function;
|
|
||||||
import java.util.stream.Stream;
|
|
||||||
|
|
||||||
import static at.pcgamingfreaks.mkvaudiosubtitlechanger.util.TestUtil.args;
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
|
||||||
|
|
||||||
class BooleanConfigParameterTest {
|
|
||||||
|
|
||||||
private static Stream<Arguments> provideTestCases() {
|
|
||||||
return Stream.of(
|
|
||||||
Arguments.of(args("-s"), true, (Function<InputConfig, Boolean>) InputConfig::isSafeMode),
|
|
||||||
Arguments.of(args("--safemode"), true, (Function<InputConfig, Boolean>) InputConfig::isSafeMode),
|
|
||||||
Arguments.of(args(), false, (Function<InputConfig, Boolean>) InputConfig::isSafeMode),
|
|
||||||
Arguments.of(args("-cf"), true, (Function<InputConfig, Boolean>) InputConfig::isForceCoherent),
|
|
||||||
Arguments.of(args("--force-coherent"), true, (Function<InputConfig, Boolean>) InputConfig::isForceCoherent),
|
|
||||||
Arguments.of(args(), false, (Function<InputConfig, Boolean>) InputConfig::isForceCoherent),
|
|
||||||
Arguments.of(args("-n"), true, (Function<InputConfig, Boolean>) InputConfig::isOnlyNewFiles),
|
|
||||||
Arguments.of(args(), false, (Function<InputConfig, Boolean>) InputConfig::isOnlyNewFiles)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@ParameterizedTest
|
|
||||||
@MethodSource("provideTestCases")
|
|
||||||
void validate(String[] cmdArgs, boolean expected, Function<InputConfig, Boolean> fieldUnderTest) {
|
|
||||||
Main sut = new Main();
|
|
||||||
CommandLine.populateCommand(sut, cmdArgs);
|
|
||||||
assertEquals(expected, fieldUnderTest.apply(sut.getConfig()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,41 +0,0 @@
|
|||||||
package at.pcgamingfreaks.mkvaudiosubtitlechanger.config.fields;
|
|
||||||
|
|
||||||
import at.pcgamingfreaks.mkvaudiosubtitlechanger.Main;
|
|
||||||
import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.InputConfig;
|
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
import org.junit.jupiter.params.ParameterizedTest;
|
|
||||||
import org.junit.jupiter.params.provider.Arguments;
|
|
||||||
import org.junit.jupiter.params.provider.MethodSource;
|
|
||||||
import picocli.CommandLine;
|
|
||||||
|
|
||||||
import java.util.function.Function;
|
|
||||||
import java.util.stream.Stream;
|
|
||||||
|
|
||||||
import static at.pcgamingfreaks.mkvaudiosubtitlechanger.util.TestUtil.args;
|
|
||||||
import static org.junit.jupiter.api.Assertions.*;
|
|
||||||
|
|
||||||
class IntegerConfigParameterTest {
|
|
||||||
|
|
||||||
private static Stream<Arguments> provideTestCases() {
|
|
||||||
return Stream.of(
|
|
||||||
Arguments.of(args(), 2, (Function<InputConfig, Integer>) InputConfig::getThreads),
|
|
||||||
Arguments.of(args("-t", "5"), 5, (Function<InputConfig, Integer>) InputConfig::getThreads),
|
|
||||||
Arguments.of(args("--threads", "5"), 5, (Function<InputConfig, Integer>) InputConfig::getThreads)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@ParameterizedTest
|
|
||||||
@MethodSource("provideTestCases")
|
|
||||||
void validate(String[] cmdArgs, int expected, Function<InputConfig, Integer> fieldUnderTest) {
|
|
||||||
Main sut = new Main();
|
|
||||||
CommandLine.populateCommand(sut, cmdArgs);
|
|
||||||
assertEquals(expected, fieldUnderTest.apply(sut.getConfig()));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void validate() {
|
|
||||||
Main sut = new Main();
|
|
||||||
assertThrows(CommandLine.MissingParameterException.class, () -> CommandLine.populateCommand(sut, args("-t")));
|
|
||||||
assertThrows(CommandLine.MissingParameterException.class, () -> CommandLine.populateCommand(sut, args("--threads")));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,45 +0,0 @@
|
|||||||
package at.pcgamingfreaks.mkvaudiosubtitlechanger.config.fields;
|
|
||||||
|
|
||||||
import at.pcgamingfreaks.mkvaudiosubtitlechanger.Main;
|
|
||||||
import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.InputConfig;
|
|
||||||
import org.apache.commons.lang3.SystemUtils;
|
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
import org.junit.jupiter.params.ParameterizedTest;
|
|
||||||
import org.junit.jupiter.params.provider.Arguments;
|
|
||||||
import org.junit.jupiter.params.provider.MethodSource;
|
|
||||||
import picocli.CommandLine;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.nio.file.Path;
|
|
||||||
import java.util.function.Function;
|
|
||||||
import java.util.stream.Stream;
|
|
||||||
|
|
||||||
import static at.pcgamingfreaks.mkvaudiosubtitlechanger.util.TestUtil.args;
|
|
||||||
import static org.junit.jupiter.api.Assertions.*;
|
|
||||||
|
|
||||||
class MkvToolNixPathConfigParameterTest {
|
|
||||||
|
|
||||||
private static final String TEST_MKVTOOLNIX_DIR = SystemUtils.IS_OS_WINDOWS ? "src/test/resources/mkvtoolnix_exe" : "src/test/resources/mkvtoolnix";
|
|
||||||
|
|
||||||
private static Stream<Arguments> provideTestCases() {
|
|
||||||
return Stream.of(
|
|
||||||
Arguments.of(args("-m", TEST_MKVTOOLNIX_DIR), TEST_MKVTOOLNIX_DIR, (Function<InputConfig, File>) InputConfig::getMkvToolNix),
|
|
||||||
Arguments.of(args("--mkvtoolnix", TEST_MKVTOOLNIX_DIR), TEST_MKVTOOLNIX_DIR, (Function<InputConfig, File>) InputConfig::getMkvToolNix)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@ParameterizedTest
|
|
||||||
@MethodSource("provideTestCases")
|
|
||||||
void validate(String[] cmdArgs, String expected, Function<InputConfig, File> fieldUnderTest) {
|
|
||||||
Main sut = new Main();
|
|
||||||
CommandLine.populateCommand(sut, cmdArgs);
|
|
||||||
assertEquals(Path.of(expected).toFile().getAbsolutePath(), fieldUnderTest.apply(sut.getConfig()).getAbsolutePath());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void validate() {
|
|
||||||
Main sut = new Main();
|
|
||||||
assertThrows(CommandLine.ParameterException.class, () -> CommandLine.populateCommand(sut, args("-m")));
|
|
||||||
assertThrows(CommandLine.ParameterException.class, () -> CommandLine.populateCommand(sut, args("")));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,54 +0,0 @@
|
|||||||
package at.pcgamingfreaks.mkvaudiosubtitlechanger.config.fields;
|
|
||||||
|
|
||||||
import at.pcgamingfreaks.mkvaudiosubtitlechanger.Main;
|
|
||||||
import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.InputConfig;
|
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
import org.junit.jupiter.params.ParameterizedTest;
|
|
||||||
import org.junit.jupiter.params.provider.Arguments;
|
|
||||||
import org.junit.jupiter.params.provider.MethodSource;
|
|
||||||
import picocli.CommandLine;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.nio.file.Path;
|
|
||||||
import java.util.function.Function;
|
|
||||||
import java.util.stream.Stream;
|
|
||||||
|
|
||||||
import static at.pcgamingfreaks.mkvaudiosubtitlechanger.util.PathUtils.TEST_DIR;
|
|
||||||
import static at.pcgamingfreaks.mkvaudiosubtitlechanger.util.PathUtils.TEST_FILE;
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
|
||||||
|
|
||||||
class PathConfigParameterTest {
|
|
||||||
|
|
||||||
private static Stream<Arguments> provideTestCases() {
|
|
||||||
return Stream.of(
|
|
||||||
Arguments.of(args("-l", TEST_DIR), Path.of(TEST_DIR).toFile(), true, (Function<InputConfig, File>) InputConfig::getLibraryPath),
|
|
||||||
Arguments.of(args("-l", TEST_FILE), Path.of(TEST_FILE).toFile(), true, (Function<InputConfig, File>) InputConfig::getLibraryPath)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@ParameterizedTest
|
|
||||||
@MethodSource("provideTestCases")
|
|
||||||
void validate(String[] cmdArgs, File expected, boolean exists, Function<InputConfig, File> fieldUnderTest) {
|
|
||||||
Main sut = new Main();
|
|
||||||
CommandLine.populateCommand(sut, cmdArgs);
|
|
||||||
assertEquals(expected.getAbsolutePath(), fieldUnderTest.apply(sut.getConfig()).getAbsolutePath());
|
|
||||||
assertEquals(exists, fieldUnderTest.apply(sut.getConfig()).exists());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void validate() {
|
|
||||||
Main sut = new Main();
|
|
||||||
// assertThrows(CommandLine.ParameterException.class, () -> new CommandLine(sut).execute(args("-l", "arst")));
|
|
||||||
assertThrows(CommandLine.MissingParameterException.class, () -> CommandLine.populateCommand(sut, args("-l")));
|
|
||||||
assertThrows(CommandLine.UnmatchedArgumentException.class, () -> CommandLine.populateCommand(sut, args("")));
|
|
||||||
}
|
|
||||||
|
|
||||||
private static String[] args(String... args) {
|
|
||||||
String[] staticArray = new String[]{"-a", "ger:ger"};
|
|
||||||
String[] result = new String[staticArray.length + args.length];
|
|
||||||
System.arraycopy(staticArray, 0, result, 0, staticArray.length);
|
|
||||||
System.arraycopy(args, 0, result, staticArray.length, args.length);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,43 +0,0 @@
|
|||||||
package at.pcgamingfreaks.mkvaudiosubtitlechanger.config.fields;
|
|
||||||
|
|
||||||
import at.pcgamingfreaks.mkvaudiosubtitlechanger.Main;
|
|
||||||
import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.InputConfig;
|
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
import org.junit.jupiter.params.ParameterizedTest;
|
|
||||||
import org.junit.jupiter.params.provider.Arguments;
|
|
||||||
import org.junit.jupiter.params.provider.MethodSource;
|
|
||||||
import picocli.CommandLine;
|
|
||||||
|
|
||||||
import java.util.function.Function;
|
|
||||||
import java.util.regex.Pattern;
|
|
||||||
import java.util.stream.Stream;
|
|
||||||
|
|
||||||
import static at.pcgamingfreaks.mkvaudiosubtitlechanger.util.TestUtil.args;
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
|
||||||
|
|
||||||
class PatternConfigParameterTest {
|
|
||||||
|
|
||||||
private static Stream<Arguments> provideTestCases() {
|
|
||||||
return Stream.of(
|
|
||||||
Arguments.of(args("-i", "[abd]?.*"), Pattern.compile("[abd]?.*"), (Function<InputConfig, Pattern>) InputConfig::getIncludePattern),
|
|
||||||
Arguments.of(args("-i", ".*"), Pattern.compile(".*"), (Function<InputConfig, Pattern>) InputConfig::getIncludePattern),
|
|
||||||
Arguments.of(args(), Pattern.compile(".*"), (Function<InputConfig, Pattern>) InputConfig::getIncludePattern)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@ParameterizedTest
|
|
||||||
@MethodSource("provideTestCases")
|
|
||||||
void validate(String[] cmdArgs, Pattern expected, Function<InputConfig, Pattern> fieldUnderTest) {
|
|
||||||
Main sut = new Main();
|
|
||||||
CommandLine.populateCommand(sut, cmdArgs);
|
|
||||||
assertEquals(expected.pattern(), fieldUnderTest.apply(sut.getConfig()).pattern());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void validate() {
|
|
||||||
Main sut = new Main();
|
|
||||||
assertThrows(CommandLine.MissingParameterException.class, () -> CommandLine.populateCommand(sut, args("-i")));
|
|
||||||
assertThrows(CommandLine.ParameterException.class, () -> CommandLine.populateCommand(sut, args("-i", "[")));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,51 +0,0 @@
|
|||||||
package at.pcgamingfreaks.mkvaudiosubtitlechanger.config.fields;
|
|
||||||
|
|
||||||
import at.pcgamingfreaks.mkvaudiosubtitlechanger.Main;
|
|
||||||
import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.InputConfig;
|
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
import org.junit.jupiter.params.ParameterizedTest;
|
|
||||||
import org.junit.jupiter.params.provider.Arguments;
|
|
||||||
import org.junit.jupiter.params.provider.MethodSource;
|
|
||||||
import picocli.CommandLine;
|
|
||||||
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.function.Function;
|
|
||||||
import java.util.stream.Stream;
|
|
||||||
|
|
||||||
import static at.pcgamingfreaks.mkvaudiosubtitlechanger.util.TestUtil.args;
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
|
||||||
|
|
||||||
class SetConfigParameterTest {
|
|
||||||
|
|
||||||
private static Stream<Arguments> provideTestCases() {
|
|
||||||
return Stream.of(
|
|
||||||
Arguments.of(args("--commentary-keywords", "test"), 1, (Function<InputConfig, Set<String>>) InputConfig::getCommentaryKeywords),
|
|
||||||
Arguments.of(args("--commentary-keywords", "test", "test1", "test2", "test3", "test4"), 5, (Function<InputConfig, Set<String>>) InputConfig::getCommentaryKeywords),
|
|
||||||
Arguments.of(args(), 3, (Function<InputConfig, Set<String>>) InputConfig::getCommentaryKeywords),
|
|
||||||
Arguments.of(args("--forced-keywords", "test"), 1, (Function<InputConfig, Set<String>>) InputConfig::getForcedKeywords),
|
|
||||||
Arguments.of(args("--forced-keywords", "test", "test1", "test2", "test3", "test4"), 5, (Function<InputConfig, Set<String>>) InputConfig::getForcedKeywords),
|
|
||||||
Arguments.of(args(), 3, (Function<InputConfig, Set<String>>) InputConfig::getForcedKeywords),
|
|
||||||
Arguments.of(args("--preferred-subtitles", "test"), 1, (Function<InputConfig, Set<String>>) InputConfig::getPreferredSubtitles),
|
|
||||||
Arguments.of(args("--preferred-subtitles", "test", "test1", "test2", "test3", "test4"), 5, (Function<InputConfig, Set<String>>) InputConfig::getPreferredSubtitles),
|
|
||||||
Arguments.of(args(), 1, (Function<InputConfig, Set<String>>) InputConfig::getPreferredSubtitles)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@ParameterizedTest
|
|
||||||
@MethodSource("provideTestCases")
|
|
||||||
void validate(String[] cmdArgs, int expectedSize, Function<InputConfig, Set<String>> fieldUnderTest) {
|
|
||||||
Main sut = new Main();
|
|
||||||
CommandLine.populateCommand(sut, cmdArgs);
|
|
||||||
assertEquals(expectedSize, fieldUnderTest.apply(sut.getConfig()).size());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void validate() {
|
|
||||||
Main sut = new Main();
|
|
||||||
assertThrows(CommandLine.MissingParameterException.class, () -> CommandLine.populateCommand(sut, args("--commentary-keywords")));
|
|
||||||
assertThrows(CommandLine.MissingParameterException.class, () -> CommandLine.populateCommand(sut, args("--forced-keywords")));
|
|
||||||
assertThrows(CommandLine.MissingParameterException.class, () -> CommandLine.populateCommand(sut, args("-e")));
|
|
||||||
assertThrows(CommandLine.MissingParameterException.class, () -> CommandLine.populateCommand(sut, args("--preferred-subtitles")));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,50 +0,0 @@
|
|||||||
package at.pcgamingfreaks.mkvaudiosubtitlechanger.impl;
|
|
||||||
|
|
||||||
import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.FileInfo;
|
|
||||||
import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.AttributeConfig;
|
|
||||||
import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.TrackAttributes;
|
|
||||||
import org.junit.jupiter.api.Disabled;
|
|
||||||
import org.junit.jupiter.params.ParameterizedTest;
|
|
||||||
import org.junit.jupiter.params.provider.Arguments;
|
|
||||||
import org.junit.jupiter.params.provider.MethodSource;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.stream.Stream;
|
|
||||||
|
|
||||||
import static at.pcgamingfreaks.mkvaudiosubtitlechanger.util.FileInfoTestUtil.*;
|
|
||||||
import static org.junit.jupiter.api.Assertions.*;
|
|
||||||
|
|
||||||
class MkvFileProcessorTest {
|
|
||||||
|
|
||||||
private static Stream<Arguments> detectDesiredTracks() {
|
|
||||||
return Stream.of(
|
|
||||||
Arguments.of(new AttributeConfig("ger", "OFF"), List.of(AUDIO_GER, AUDIO_ENG), new AttributeConfig[] {new AttributeConfig("ger", "OFF"), new AttributeConfig("eng", "OFF")}),
|
|
||||||
Arguments.of(new AttributeConfig("eng", "OFF"), List.of(AUDIO_ENG), new AttributeConfig[] {new AttributeConfig("ger", "OFF"), new AttributeConfig("eng", "OFF")}),
|
|
||||||
Arguments.of(new AttributeConfig("eng", "ger"), List.of(AUDIO_GER, AUDIO_ENG, SUB_GER, SUB_ENG), new AttributeConfig[] {new AttributeConfig("eng", "ger"), new AttributeConfig("ger", "eng")}),
|
|
||||||
Arguments.of(new AttributeConfig("ger", "eng"), List.of(AUDIO_GER, SUB_GER, SUB_ENG), new AttributeConfig[] {new AttributeConfig("eng", "ger"), new AttributeConfig("ger", "eng")}),
|
|
||||||
Arguments.of(new AttributeConfig("OFF", "ger"), List.of(AUDIO_GER, SUB_GER, SUB_ENG), new AttributeConfig[] {new AttributeConfig("OFF", "ger"), new AttributeConfig("ger", "eng")})
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@ParameterizedTest
|
|
||||||
@MethodSource
|
|
||||||
@Disabled
|
|
||||||
void detectDesiredTracks(AttributeConfig expectedMatch, List<TrackAttributes> tracks, AttributeConfig... configs) {
|
|
||||||
FileInfo info = new FileInfo(null);
|
|
||||||
// MkvFileProcessor processor = new MkvFileProcessor(null, new FileFilter());
|
|
||||||
// processor.detectDesiredTracks(info, tracks, tracks, configs);
|
|
||||||
assertEquals(expectedMatch.getAudioLanguage(), info.getMatchedConfig().getAudioLanguage());
|
|
||||||
assertEquals(expectedMatch.getSubtitleLanguage(), info.getMatchedConfig().getSubtitleLanguage());
|
|
||||||
}
|
|
||||||
|
|
||||||
private static Stream<Arguments> retrieveNonForcedTracks() {
|
|
||||||
return Stream.of(
|
|
||||||
Arguments.of(List.of(SUB_GER, SUB_ENG, SUB_GER_FORCED), List.of(SUB_GER, SUB_ENG)),
|
|
||||||
Arguments.of(List.of(SUB_GER, SUB_ENG), List.of(SUB_GER, SUB_ENG)),
|
|
||||||
Arguments.of(List.of(AUDIO_GER, SUB_GER, SUB_ENG), List.of(AUDIO_GER, SUB_GER, SUB_ENG)),
|
|
||||||
Arguments.of(List.of(AUDIO_GER), List.of(AUDIO_GER)),
|
|
||||||
Arguments.of(List.of(AUDIO_GER_FORCED), List.of()),
|
|
||||||
Arguments.of(List.of(), List.of())
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -7,7 +7,6 @@ import org.junit.jupiter.params.provider.Arguments;
|
|||||||
import org.junit.jupiter.params.provider.MethodSource;
|
import org.junit.jupiter.params.provider.MethodSource;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.*;
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
@@ -35,9 +34,7 @@ class SubtitleTrackComparatorTest {
|
|||||||
@ParameterizedTest
|
@ParameterizedTest
|
||||||
@MethodSource("compareArguments")
|
@MethodSource("compareArguments")
|
||||||
void compare(List<TrackAttributes> input, List<TrackAttributes> expected) {
|
void compare(List<TrackAttributes> input, List<TrackAttributes> expected) {
|
||||||
List<TrackAttributes> result = input.stream().sorted(comparator.reversed()).collect(Collectors.toList());
|
assertIterableEquals(expected, input.stream().sorted(comparator.reversed()).toList());
|
||||||
|
|
||||||
assertArrayEquals(expected.toArray(new TrackAttributes[0]), result.toArray(new TrackAttributes[0]));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static TrackAttributes attr(String trackName, boolean defaultTrack) {
|
private static TrackAttributes attr(String trackName, boolean defaultTrack) {
|
||||||
|
|||||||
@@ -0,0 +1,61 @@
|
|||||||
|
package at.pcgamingfreaks.mkvaudiosubtitlechanger.impl.validation;
|
||||||
|
|
||||||
|
import at.pcgamingfreaks.mkvaudiosubtitlechanger.impl.CommandRunner;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.junit.jupiter.params.ParameterizedTest;
|
||||||
|
import org.junit.jupiter.params.provider.Arguments;
|
||||||
|
import org.junit.jupiter.params.provider.MethodSource;
|
||||||
|
import picocli.CommandLine;
|
||||||
|
|
||||||
|
import java.io.PrintWriter;
|
||||||
|
import java.io.StringWriter;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
|
import static at.pcgamingfreaks.mkvaudiosubtitlechanger.util.PathUtils.*;
|
||||||
|
import static at.pcgamingfreaks.mkvaudiosubtitlechanger.util.TestUtil.args;
|
||||||
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
|
class ValidationExecutionStrategyTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void validate() {
|
||||||
|
CommandRunner underTest = new CommandRunner();
|
||||||
|
new CommandLine(underTest)
|
||||||
|
.setExecutionStrategy(new ValidationExecutionStrategy())
|
||||||
|
.parseArgs("-a", "ger:ger", "-l", TEST_FILE, "-m", TEST_MKVTOOLNIX_DIR);
|
||||||
|
|
||||||
|
assertEquals(TEST_FILE, underTest.getConfig().getLibraryPath().getPath());
|
||||||
|
assertEquals(TEST_MKVTOOLNIX_DIR, underTest.getConfig().getMkvToolNix().getPath());
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Stream<Arguments> validateFailure() {
|
||||||
|
return Stream.of(
|
||||||
|
Arguments.of(new String[]{"-a", "jpn:ger"}, "Error: Missing required argument(s): --library=<libraryPath>"),
|
||||||
|
Arguments.of(new String[]{"-a", "jpn:ger", "-l"}, "Missing required parameter for option '--library' (<libraryPath>)"),
|
||||||
|
Arguments.of(new String[]{"-l", "/arstarstarst"}, "Error: Missing required argument(s): --attribute-config=<attributeConfig>"),
|
||||||
|
Arguments.of(new String[]{"-l", "/arstarstarst", "-a",}, "Missing required parameter for option '--attribute-config' at index 0 (<attributeConfig>)"),
|
||||||
|
Arguments.of(new String[]{"-l", "/arstarstarst", "-a", "jpn:ger"}, "libraryPath does not exist"),
|
||||||
|
Arguments.of(args("-m"), "Missing required parameter for option '--mkvtoolnix' (<mkvToolNix>)"),
|
||||||
|
Arguments.of(args("-m", TEST_INVALID_DIR), "mkvToolNix does not exist"),
|
||||||
|
Arguments.of(args("-t"), "Missing required parameter for option '--threads' (<threads>)"),
|
||||||
|
Arguments.of(args("-t", "0"), "threads must be greater than or equal to 1"),
|
||||||
|
Arguments.of(args("-t", "-1"), "threads must be greater than or equal to 1"),
|
||||||
|
Arguments.of(args("-c", "-1"), "coherent must be greater than or equal to 0")
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@ParameterizedTest
|
||||||
|
@MethodSource("validateFailure")
|
||||||
|
void validateFailure(String[] args, String expectedMessage) {
|
||||||
|
StringWriter writer = new StringWriter();
|
||||||
|
PrintWriter printWriter = new PrintWriter(writer);
|
||||||
|
|
||||||
|
new CommandLine(CommandRunner.class)
|
||||||
|
.setExecutionStrategy(new ValidationExecutionStrategy())
|
||||||
|
.setErr(printWriter)
|
||||||
|
.execute(args);
|
||||||
|
|
||||||
|
printWriter.flush();
|
||||||
|
assertEquals(expectedMessage, writer.toString().split("\n")[0]);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,80 +0,0 @@
|
|||||||
package at.pcgamingfreaks.mkvaudiosubtitlechanger.model;
|
|
||||||
|
|
||||||
import at.pcgamingfreaks.mkvaudiosubtitlechanger.Main;
|
|
||||||
import at.pcgamingfreaks.mkvaudiosubtitlechanger.impl.validation.ValidationExecutionStrategy;
|
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
import org.junit.jupiter.params.ParameterizedTest;
|
|
||||||
import org.junit.jupiter.params.provider.Arguments;
|
|
||||||
import org.junit.jupiter.params.provider.MethodSource;
|
|
||||||
import picocli.CommandLine;
|
|
||||||
|
|
||||||
import java.io.PrintWriter;
|
|
||||||
import java.io.StringWriter;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.stream.Stream;
|
|
||||||
|
|
||||||
import static at.pcgamingfreaks.mkvaudiosubtitlechanger.util.PathUtils.TEST_FILE;
|
|
||||||
import static at.pcgamingfreaks.mkvaudiosubtitlechanger.util.TestUtil.args;
|
|
||||||
import static org.junit.jupiter.api.Assertions.*;
|
|
||||||
|
|
||||||
class InputConfigTest {
|
|
||||||
private static final String TEST_INVALID_DIR = "src/test/resources/test-dir";
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void initConfig() {
|
|
||||||
String[] sut = new String[]{"-a", "ger:ger", "eng:eng", "-l", TEST_FILE,
|
|
||||||
"-s", "-cf", "-n",
|
|
||||||
"-c", "2",
|
|
||||||
"-t", "4",
|
|
||||||
"-i", ".*[abc].*",
|
|
||||||
"--forced-keywords", "testForced",
|
|
||||||
"--commentary-keywords", "testCommentary",
|
|
||||||
"--preferred-subtitles", "testPreferred"
|
|
||||||
};
|
|
||||||
InputConfig config = CommandLine.populateCommand(new InputConfig(), sut);
|
|
||||||
|
|
||||||
assertTrue(config.getLibraryPath().exists());
|
|
||||||
assertArrayEquals(new AttributeConfig[]{new AttributeConfig("ger", "ger"), new AttributeConfig("eng", "eng")},
|
|
||||||
config.getAttributeConfig());
|
|
||||||
|
|
||||||
assertTrue(config.isSafeMode());
|
|
||||||
assertTrue(config.isForceCoherent());
|
|
||||||
assertTrue(config.isOnlyNewFiles());
|
|
||||||
assertNull(config.getFilterDate());
|
|
||||||
|
|
||||||
assertEquals(2, config.getCoherent());
|
|
||||||
assertEquals(4, config.getThreads());
|
|
||||||
assertEquals(".*[abc].*", config.getIncludePattern().pattern());
|
|
||||||
assertTrue(config.getForcedKeywords().contains("testForced"));
|
|
||||||
assertTrue(config.getCommentaryKeywords().contains("testCommentary"));
|
|
||||||
assertTrue(config.getPreferredSubtitles().contains("testPreferred"));
|
|
||||||
|
|
||||||
assertNull(config.getConfigPath());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private static Stream<Arguments> jakartaValidationData() {
|
|
||||||
return Stream.of(
|
|
||||||
Arguments.of(new String[]{"-l", "/arstarstarst", "-a", "jpn:ger"}, "libraryPath does not exist"),
|
|
||||||
Arguments.of(args("-m", TEST_INVALID_DIR), "mkvToolNix does not exist"),
|
|
||||||
Arguments.of(args("-t", "0"), "threads must be greater than or equal to 1"),
|
|
||||||
Arguments.of(args("-t", "-1"), "threads must be greater than or equal to 1"),
|
|
||||||
Arguments.of(args("-c", "-1"), "coherent must be greater than or equal to 0")
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@ParameterizedTest
|
|
||||||
@MethodSource("jakartaValidationData")
|
|
||||||
void testJakartaValidation(String[] args, String expectedMessage) {
|
|
||||||
StringWriter writer = new StringWriter();
|
|
||||||
PrintWriter printWriter = new PrintWriter(writer);
|
|
||||||
|
|
||||||
new CommandLine(Main.class)
|
|
||||||
.setExecutionStrategy(new ValidationExecutionStrategy())
|
|
||||||
.setErr(printWriter)
|
|
||||||
.execute(args);
|
|
||||||
|
|
||||||
printWriter.flush();
|
|
||||||
assertTrue(writer.toString().contains(expectedMessage));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,6 +1,10 @@
|
|||||||
package at.pcgamingfreaks.mkvaudiosubtitlechanger.util;
|
package at.pcgamingfreaks.mkvaudiosubtitlechanger.util;
|
||||||
|
|
||||||
|
import org.apache.commons.lang3.SystemUtils;
|
||||||
|
|
||||||
public class PathUtils {
|
public class PathUtils {
|
||||||
public static final String TEST_DIR = "src/test/resources/test-dir";
|
public static final String TEST_DIR = "src/test/resources/test-dir";
|
||||||
public static final String TEST_FILE = "src/test/resources/test-dir/test-file.mkv";
|
public static final String TEST_FILE = "src/test/resources/test-dir/test-file.mkv";
|
||||||
|
public static final String TEST_INVALID_DIR = "src/test/resources/test-dir";
|
||||||
|
public static final String TEST_MKVTOOLNIX_DIR = SystemUtils.IS_OS_WINDOWS ? "src/test/resources/mkvtoolnix_exe" : "src/test/resources/mkvtoolnix";
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user