mirror of
https://github.com/RatzzFatzz/MKVAudioSubtitleChanger.git
synced 2026-02-11 10:05:58 +01:00
Add ConfigProperty Validation
This commit is contained in:
@@ -3,7 +3,6 @@ package at.pcgamingfreaks.mkvaudiosubtitlechanger.config.validator;
|
||||
import at.pcgamingfreaks.mkvaudiosubtitlechanger.config.Config;
|
||||
import at.pcgamingfreaks.mkvaudiosubtitlechanger.config.ValidationResult;
|
||||
import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.AttributeConfig;
|
||||
import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.ConfigProperty;
|
||||
import at.pcgamingfreaks.yaml.YAML;
|
||||
import at.pcgamingfreaks.yaml.YamlInvalidContentException;
|
||||
import org.apache.commons.cli.CommandLineParser;
|
||||
@@ -16,8 +15,6 @@ import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.Arguments;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Stream;
|
||||
@@ -25,14 +22,9 @@ import java.util.stream.Stream;
|
||||
import static at.pcgamingfreaks.mkvaudiosubtitlechanger.config.ValidationResult.*;
|
||||
import static at.pcgamingfreaks.mkvaudiosubtitlechanger.model.ConfigProperty.*;
|
||||
import static at.pcgamingfreaks.mkvaudiosubtitlechanger.util.CommandLineOptionsUtil.optionOf;
|
||||
import static at.pcgamingfreaks.mkvaudiosubtitlechanger.util.TestUtil.argumentsOf;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
class AttributeConfigValidatorTest {
|
||||
private static final String TEST_DIR = "src/test/resources/test-dir";
|
||||
private static final String TEST_FILE = "src/test/resources/test-dir/test-file.mkv";
|
||||
private static final String TEST_CONFIG = "src/test/resources/test-dir/test-config.yml";
|
||||
|
||||
private static CommandLineParser parser;
|
||||
private static Options options;
|
||||
|
||||
@@ -71,13 +63,13 @@ class AttributeConfigValidatorTest {
|
||||
}
|
||||
|
||||
private static String attrConfYaml(String... languages) {
|
||||
String yaml = "attribute-config: ";
|
||||
StringBuilder yaml = new StringBuilder("attribute-config: ");
|
||||
int counter = 0;
|
||||
for (int i = 0; i < languages.length; i += 2) {
|
||||
counter++;
|
||||
yaml += String.format("\n %s:\n audio: %s\n subtitle: %s", counter, languages[0], languages[1]);
|
||||
yaml.append(String.format("\n %s:\n audio: %s\n subtitle: %s", counter, languages[0], languages[1]));
|
||||
}
|
||||
return yaml;
|
||||
return yaml.toString();
|
||||
}
|
||||
|
||||
private static List<AttributeConfig> attrConf(String... languages) {
|
||||
|
||||
@@ -20,13 +20,11 @@ import java.util.stream.Stream;
|
||||
import static at.pcgamingfreaks.mkvaudiosubtitlechanger.config.ValidationResult.*;
|
||||
import static at.pcgamingfreaks.mkvaudiosubtitlechanger.config.ValidationResult.INVALID;
|
||||
import static at.pcgamingfreaks.mkvaudiosubtitlechanger.model.ConfigProperty.CONFIG_PATH;
|
||||
import static at.pcgamingfreaks.mkvaudiosubtitlechanger.model.ConfigProperty.LIBRARY;
|
||||
import static at.pcgamingfreaks.mkvaudiosubtitlechanger.util.CommandLineOptionsUtil.optionOf;
|
||||
import static at.pcgamingfreaks.mkvaudiosubtitlechanger.util.TestUtil.argumentsOf;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
class ConfigPathValidatorTest {
|
||||
private static final String TEST_DIR = "src/test/resources/test-dir";
|
||||
private static final String TEST_FILE = "src/test/resources/test-dir/test-file.mkv";
|
||||
private static final String TEST_CONFIG = "src/test/resources/test-dir/test-config.yml";
|
||||
|
||||
@@ -42,11 +40,11 @@ class ConfigPathValidatorTest {
|
||||
|
||||
private static Stream<Arguments> provideTestCases() {
|
||||
return Stream.of(
|
||||
argumentsOf(CONFIG_PATH, true, null, "", new String[]{"-c", TEST_CONFIG}, VALID),
|
||||
argumentsOf(CONFIG_PATH, true, null, "", new String[]{"-p", TEST_CONFIG}, VALID),
|
||||
argumentsOf(CONFIG_PATH, true, null, "config-path: " + TEST_CONFIG, new String[]{}, MISSING),
|
||||
argumentsOf(CONFIG_PATH, false, null, "config-path: " + TEST_CONFIG, new String[]{}, NOT_PRESENT),
|
||||
argumentsOf(CONFIG_PATH, false, Path.of(TEST_CONFIG).toFile(), "", new String[]{}, DEFAULT),
|
||||
argumentsOf(CONFIG_PATH, true, null, "", new String[]{"-c", TEST_FILE}, INVALID)
|
||||
argumentsOf(CONFIG_PATH, true, null, "", new String[]{"-p", TEST_FILE}, INVALID)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@ class PatternValidatorTest {
|
||||
private static Stream<Arguments> provideTestCases() {
|
||||
return Stream.of(
|
||||
argumentsOf(INCLUDE_PATTERN, false, null, "include-pattern: \"[abd]?.*\"", new String[]{}, VALID),
|
||||
argumentsOf(INCLUDE_PATTERN, true, null, "", new String[]{"-p", "[abd]?.*"}, VALID),
|
||||
argumentsOf(INCLUDE_PATTERN, true, null, "", new String[]{"-i", "[abd]?.*"}, VALID),
|
||||
|
||||
argumentsOf(INCLUDE_PATTERN, false, Pattern.compile(".*"), "", new String[]{}, DEFAULT),
|
||||
argumentsOf(INCLUDE_PATTERN, true, Pattern.compile(".*"), "", new String[]{}, DEFAULT),
|
||||
@@ -45,9 +45,9 @@ class PatternValidatorTest {
|
||||
argumentsOf(INCLUDE_PATTERN, true, null, "", new String[]{}, MISSING),
|
||||
argumentsOf(INCLUDE_PATTERN, false, null, "", new String[]{}, NOT_PRESENT),
|
||||
|
||||
argumentsOf(INCLUDE_PATTERN, true, null, "", new String[]{"-p", "?."}, INVALID),
|
||||
argumentsOf(INCLUDE_PATTERN, true, null, "", new String[]{"-i", "?."}, INVALID),
|
||||
argumentsOf(INCLUDE_PATTERN, false, null, "include-pattern: \"[arst*\"", new String[]{}, INVALID),
|
||||
argumentsOf(INCLUDE_PATTERN, true, Pattern.compile(".?"), "", new String[]{"-p", "?."}, INVALID)
|
||||
argumentsOf(INCLUDE_PATTERN, true, Pattern.compile(".?"), "", new String[]{"-i", "?."}, INVALID)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user