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,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 java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
@@ -35,9 +34,7 @@ class SubtitleTrackComparatorTest {
|
||||
@ParameterizedTest
|
||||
@MethodSource("compareArguments")
|
||||
void compare(List<TrackAttributes> input, List<TrackAttributes> expected) {
|
||||
List<TrackAttributes> result = input.stream().sorted(comparator.reversed()).collect(Collectors.toList());
|
||||
|
||||
assertArrayEquals(expected.toArray(new TrackAttributes[0]), result.toArray(new TrackAttributes[0]));
|
||||
assertIterableEquals(expected, input.stream().sorted(comparator.reversed()).toList());
|
||||
}
|
||||
|
||||
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]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user