mirror of
https://github.com/RatzzFatzz/MKVAudioSubtitleChanger.git
synced 2026-02-11 02:05:56 +01:00
Update collection config parameter config
This commit is contained in:
@@ -58,13 +58,20 @@ public class Config {
|
|||||||
@CommandLine.Option(names = {"-d", "--filter-date"}, defaultValue = CommandLine.Option.NULL_VALUE, description = "only consider files created newer than entered date (format: \"dd.MM.yyyy-HH:mm:ss\")")
|
@CommandLine.Option(names = {"-d", "--filter-date"}, defaultValue = CommandLine.Option.NULL_VALUE, description = "only consider files created newer than entered date (format: \"dd.MM.yyyy-HH:mm:ss\")")
|
||||||
private Date filterDate;
|
private Date filterDate;
|
||||||
|
|
||||||
@CommandLine.Option(names = {"-fk", "--force-keywords"}, description = "Additional keywords to identify forced tracks")
|
@CommandLine.Option(names = {"-fk", "--force-keywords"}, arity = "1..*",
|
||||||
|
description = "Additional keywords to identify forced tracks (Defaults are will be overwritten; Default: ${DEFAULT-VALUE}")
|
||||||
private Set<String> forcedKeywords = new HashSet<>(Arrays.asList("forced", "signs", "songs"));
|
private Set<String> forcedKeywords = new HashSet<>(Arrays.asList("forced", "signs", "songs"));
|
||||||
@CommandLine.Option(names = {"-ck", "--commentary-keywords"}, description = "Additional keywords to identify commentary tracks")
|
|
||||||
|
@CommandLine.Option(names = {"-ck", "--commentary-keywords"}, arity = "1..*",
|
||||||
|
description = "Additional keywords to identify commentary tracks (Defaults are will be overwritten; Default: ${DEFAULT-VALUE}")
|
||||||
private Set<String> commentaryKeywords = new HashSet<>(Arrays.asList("commentary", "director"));
|
private Set<String> commentaryKeywords = new HashSet<>(Arrays.asList("commentary", "director"));
|
||||||
@CommandLine.Option(names = {"-e", "--excluded-directory"}, description = "Directories to be excluded, combines with config file")
|
|
||||||
|
@CommandLine.Option(names = {"-e", "--excluded-directory"}, arity = "1..*",
|
||||||
|
description = "Directories to be excluded, combines with config file")
|
||||||
private Set<String> excludedDirectories = new HashSet<>();
|
private Set<String> excludedDirectories = new HashSet<>();
|
||||||
@CommandLine.Option(names = {"-ps", "--preferred-subtiltes"}, description = "Additional keywords to prefer specific subtitle tracks")
|
|
||||||
|
@CommandLine.Option(names = {"-ps", "--preferred-subtiltes"}, arity = "1..*",
|
||||||
|
description = "Additional keywords to prefer specific subtitle tracks (Defaults are will be overwritten; Default: ${DEFAULT-VALUE}")
|
||||||
private Set<String> preferredSubtitles = new HashSet<>(Arrays.asList("unstyled"));
|
private Set<String> preferredSubtitles = new HashSet<>(Arrays.asList("unstyled"));
|
||||||
|
|
||||||
@CommandLine.Option(names = {"-a"}, required = true, arity = "1..*", converter = AttributeConfigConverter.class)
|
@CommandLine.Option(names = {"-a"}, required = true, arity = "1..*", converter = AttributeConfigConverter.class)
|
||||||
|
|||||||
@@ -24,20 +24,6 @@ import static at.pcgamingfreaks.mkvaudiosubtitlechanger.util.CommandLineOptionsU
|
|||||||
import static org.junit.jupiter.api.Assertions.*;
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
class AttributeConfigTest {
|
class AttributeConfigTest {
|
||||||
private static CommandLineParser parser;
|
|
||||||
private static Options options;
|
|
||||||
|
|
||||||
@BeforeAll
|
|
||||||
static void before() {
|
|
||||||
parser = new DefaultParser();
|
|
||||||
options = new Options();
|
|
||||||
options.addOption(optionOf(ATTRIBUTE_CONFIG, ATTRIBUTE_CONFIG.abrv(), ATTRIBUTE_CONFIG.args()));
|
|
||||||
}
|
|
||||||
|
|
||||||
@BeforeEach
|
|
||||||
void beforeEach() {
|
|
||||||
Config.getInstance(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static Stream<Arguments> provideTestCases() {
|
private static Stream<Arguments> provideTestCases() {
|
||||||
return Stream.of(
|
return Stream.of(
|
||||||
|
|||||||
@@ -20,15 +20,6 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
|
|||||||
import static org.junit.jupiter.api.Assertions.assertIterableEquals;
|
import static org.junit.jupiter.api.Assertions.assertIterableEquals;
|
||||||
|
|
||||||
class BooleanConfigParameterTest {
|
class BooleanConfigParameterTest {
|
||||||
private static CommandLineParser parser;
|
|
||||||
private static Options options;
|
|
||||||
|
|
||||||
@BeforeAll
|
|
||||||
static void before() {
|
|
||||||
parser = new DefaultParser();
|
|
||||||
options = new Options();
|
|
||||||
options.addOption(optionOf(SAFE_MODE, SAFE_MODE.abrv(), SAFE_MODE.args()));
|
|
||||||
}
|
|
||||||
|
|
||||||
private static Stream<Arguments> provideTestCases() {
|
private static Stream<Arguments> provideTestCases() {
|
||||||
return Stream.of(
|
return Stream.of(
|
||||||
|
|||||||
@@ -23,16 +23,6 @@ import static org.junit.jupiter.api.Assertions.*;
|
|||||||
|
|
||||||
class IntegerConfigParameterTest {
|
class IntegerConfigParameterTest {
|
||||||
|
|
||||||
private static CommandLineParser parser;
|
|
||||||
private static Options options;
|
|
||||||
|
|
||||||
@BeforeAll
|
|
||||||
static void before() {
|
|
||||||
parser = new DefaultParser();
|
|
||||||
options = new Options();
|
|
||||||
options.addOption(optionOf(THREADS, "t", THREADS.args()));
|
|
||||||
}
|
|
||||||
|
|
||||||
private static Stream<Arguments> provideTestCases() {
|
private static Stream<Arguments> provideTestCases() {
|
||||||
return Stream.of(
|
return Stream.of(
|
||||||
Arguments.of(args(), 2, (Function<Config, Integer>) Config::getThreads),
|
Arguments.of(args(), 2, (Function<Config, Integer>) Config::getThreads),
|
||||||
|
|||||||
@@ -0,0 +1,52 @@
|
|||||||
|
package at.pcgamingfreaks.mkvaudiosubtitlechanger.config;
|
||||||
|
|
||||||
|
import at.pcgamingfreaks.mkvaudiosubtitlechanger.Main;
|
||||||
|
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.CommandLineOptionsUtil.optionOf;
|
||||||
|
import static at.pcgamingfreaks.mkvaudiosubtitlechanger.util.TestUtil.args;
|
||||||
|
import static at.pcgamingfreaks.mkvaudiosubtitlechanger.util.TestUtil.argumentsOf;
|
||||||
|
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("-ck", "test"), 1, (Function<Config, Set<String>>) Config::getCommentaryKeywords),
|
||||||
|
Arguments.of(args("-ck", "test", "test1", "test2", "test3", "test4"), 5, (Function<Config, Set<String>>) Config::getCommentaryKeywords),
|
||||||
|
Arguments.of(args(), 2, (Function<Config, Set<String>>) Config::getCommentaryKeywords),
|
||||||
|
Arguments.of(args("-fk", "test"), 1, (Function<Config, Set<String>>) Config::getForcedKeywords),
|
||||||
|
Arguments.of(args("-fk", "test", "test1", "test2", "test3", "test4"), 5, (Function<Config, Set<String>>) Config::getForcedKeywords),
|
||||||
|
Arguments.of(args(), 3, (Function<Config, Set<String>>) Config::getForcedKeywords),
|
||||||
|
Arguments.of(args("-ps", "test"), 1, (Function<Config, Set<String>>) Config::getPreferredSubtitles),
|
||||||
|
Arguments.of(args("-ps", "test", "test1", "test2", "test3", "test4"), 5, (Function<Config, Set<String>>) Config::getPreferredSubtitles),
|
||||||
|
Arguments.of(args(), 1, (Function<Config, Set<String>>) Config::getPreferredSubtitles)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@ParameterizedTest
|
||||||
|
@MethodSource("provideTestCases")
|
||||||
|
void validate(String[] cmdArgs, int expectedSize, Function<Config, 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("-ck")));
|
||||||
|
assertThrows(CommandLine.MissingParameterException.class, () -> CommandLine.populateCommand(sut, args("-fk")));
|
||||||
|
assertThrows(CommandLine.MissingParameterException.class, () -> CommandLine.populateCommand(sut, args("-e")));
|
||||||
|
assertThrows(CommandLine.MissingParameterException.class, () -> CommandLine.populateCommand(sut, args("-ps")));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,68 +0,0 @@
|
|||||||
package at.pcgamingfreaks.mkvaudiosubtitlechanger.config.validator;
|
|
||||||
|
|
||||||
import at.pcgamingfreaks.mkvaudiosubtitlechanger.config.Config;
|
|
||||||
import at.pcgamingfreaks.mkvaudiosubtitlechanger.config.ValidationResult;
|
|
||||||
import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.ConfigProperty;
|
|
||||||
import at.pcgamingfreaks.yaml.YAML;
|
|
||||||
import at.pcgamingfreaks.yaml.YamlInvalidContentException;
|
|
||||||
import org.apache.commons.cli.CommandLineParser;
|
|
||||||
import org.apache.commons.cli.DefaultParser;
|
|
||||||
import org.apache.commons.cli.Options;
|
|
||||||
import org.apache.commons.cli.ParseException;
|
|
||||||
import org.junit.jupiter.api.BeforeAll;
|
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
|
||||||
import org.junit.jupiter.params.ParameterizedTest;
|
|
||||||
import org.junit.jupiter.params.provider.Arguments;
|
|
||||||
import org.junit.jupiter.params.provider.MethodSource;
|
|
||||||
|
|
||||||
import java.util.stream.Stream;
|
|
||||||
|
|
||||||
import static at.pcgamingfreaks.mkvaudiosubtitlechanger.config.ValidationResult.*;
|
|
||||||
import static at.pcgamingfreaks.mkvaudiosubtitlechanger.model.ConfigProperty.COMMENTARY_KEYWORDS;
|
|
||||||
import static at.pcgamingfreaks.mkvaudiosubtitlechanger.util.CommandLineOptionsUtil.optionOf;
|
|
||||||
import static at.pcgamingfreaks.mkvaudiosubtitlechanger.util.TestUtil.argumentsOf;
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
|
||||||
|
|
||||||
class SetValidatorTest {
|
|
||||||
|
|
||||||
private static CommandLineParser parser;
|
|
||||||
private static Options options;
|
|
||||||
|
|
||||||
@BeforeAll
|
|
||||||
static void before() {
|
|
||||||
parser = new DefaultParser();
|
|
||||||
options = new Options();
|
|
||||||
options.addOption(optionOf(COMMENTARY_KEYWORDS, COMMENTARY_KEYWORDS.abrv(), COMMENTARY_KEYWORDS.args()));
|
|
||||||
}
|
|
||||||
|
|
||||||
@BeforeEach
|
|
||||||
void beforeEach() {
|
|
||||||
Config.getInstance(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static Stream<Arguments> provideTestCases() {
|
|
||||||
return Stream.of(
|
|
||||||
argumentsOf(COMMENTARY_KEYWORDS, true, true, "", new String[]{"-ck", "test"}, VALID, 3),
|
|
||||||
argumentsOf(COMMENTARY_KEYWORDS, true, false, COMMENTARY_KEYWORDS.prop() + ": [test]", new String[]{}, VALID, 1),
|
|
||||||
argumentsOf(COMMENTARY_KEYWORDS, true, false, COMMENTARY_KEYWORDS.prop() + ":\n - test\n - test2", new String[]{}, VALID, 2),
|
|
||||||
argumentsOf(COMMENTARY_KEYWORDS, false, true, COMMENTARY_KEYWORDS.prop() + ": [test]", new String[]{}, VALID, 3),
|
|
||||||
argumentsOf(COMMENTARY_KEYWORDS, false, false, "", new String[]{"-ck", "test"}, VALID, 1),
|
|
||||||
argumentsOf(COMMENTARY_KEYWORDS, true, true, COMMENTARY_KEYWORDS.prop() + ": [commentary]", new String[]{}, VALID, 2),
|
|
||||||
|
|
||||||
argumentsOf(COMMENTARY_KEYWORDS, true, true, "", new String[]{}, MISSING, 2),
|
|
||||||
argumentsOf(COMMENTARY_KEYWORDS, false, true, "", new String[]{}, NOT_PRESENT, 2)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@ParameterizedTest
|
|
||||||
@MethodSource("provideTestCases")
|
|
||||||
void validate(ConfigProperty property, boolean required, boolean append, String yamlArgs, String[] cmdArgs,
|
|
||||||
ValidationResult expectedResult, int expectedSize) throws ParseException, YamlInvalidContentException {
|
|
||||||
SetValidator underTest = new SetValidator(property, required, append);
|
|
||||||
|
|
||||||
ValidationResult result = underTest.validate(new YAML(yamlArgs), parser.parse(options, cmdArgs));
|
|
||||||
|
|
||||||
assertEquals(expectedResult, result);
|
|
||||||
assertEquals(expectedSize, Config.getInstance().getCommentaryKeywords().size());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user