mirror of
https://github.com/RatzzFatzz/MKVAudioSubtitleChanger.git
synced 2026-02-10 17:55:57 +01:00
Add tests for single file attribute updater
This commit is contained in:
@@ -59,7 +59,7 @@ public class CoherentAttributeUpdater extends SingleFileAttributeUpdater {
|
|||||||
return; // match was found and process must be stopped
|
return; // match was found and process must be stopped
|
||||||
}
|
}
|
||||||
|
|
||||||
// Couldn't match any config at current level. Resetting changes and trying to one level deeper
|
// Couldn't match any config at current level. Resetting changes and trying one level deeper
|
||||||
matchedFiles.forEach(fileInfo -> {
|
matchedFiles.forEach(fileInfo -> {
|
||||||
fileInfo.resetChanges();
|
fileInfo.resetChanges();
|
||||||
fileInfo.setMatchedConfig(null);
|
fileInfo.setMatchedConfig(null);
|
||||||
|
|||||||
@@ -12,29 +12,12 @@ import java.lang.reflect.Method;
|
|||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
import static at.pcgamingfreaks.mkvaudiosubtitlechanger.util.FileInfoTestUtil.*;
|
import static at.pcgamingfreaks.mkvaudiosubtitlechanger.util.TrackAttributeUtil.*;
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
class AttributeChangeProcessorTest {
|
class AttributeChangeProcessorTest {
|
||||||
|
|
||||||
private static AttributeConfig[] arr(AttributeConfig... configs) {
|
|
||||||
return configs;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static AttributeConfig a(String config) {
|
|
||||||
String[] split = config.split(":");
|
|
||||||
return new AttributeConfig(split[0], split[1]);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static Map.Entry<TrackAttributes, Boolean> on(TrackAttributes track) {
|
|
||||||
return Map.entry(track, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static Map.Entry<TrackAttributes, Boolean> off(TrackAttributes track) {
|
|
||||||
return Map.entry(track, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static Stream<Arguments> findAndApplyDefaultMatch() {
|
private static Stream<Arguments> findAndApplyDefaultMatch() {
|
||||||
return Stream.of(
|
return Stream.of(
|
||||||
Arguments.of(
|
Arguments.of(
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import java.util.List;
|
|||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
import static at.pcgamingfreaks.mkvaudiosubtitlechanger.util.FileInfoTestUtil.AUDIO_GER;
|
import static at.pcgamingfreaks.mkvaudiosubtitlechanger.util.TrackAttributeUtil.AUDIO_GER;
|
||||||
import static at.pcgamingfreaks.mkvaudiosubtitlechanger.util.PathUtils.TEST_FILE;
|
import static at.pcgamingfreaks.mkvaudiosubtitlechanger.util.PathUtils.TEST_FILE;
|
||||||
import static org.junit.jupiter.api.Assertions.*;
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ import java.lang.reflect.Method;
|
|||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
import static at.pcgamingfreaks.mkvaudiosubtitlechanger.util.FileInfoTestUtil.*;
|
import static at.pcgamingfreaks.mkvaudiosubtitlechanger.util.TrackAttributeUtil.*;
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,98 @@
|
|||||||
|
package at.pcgamingfreaks.mkvaudiosubtitlechanger.impl.processors;
|
||||||
|
|
||||||
|
import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.AttributeConfig;
|
||||||
|
import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.FileInfo;
|
||||||
|
import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.InputConfig;
|
||||||
|
import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.TrackAttributes;
|
||||||
|
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 java.io.File;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
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 at.pcgamingfreaks.mkvaudiosubtitlechanger.util.TrackAttributeUtil.*;
|
||||||
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
|
import static org.mockito.Mockito.*;
|
||||||
|
|
||||||
|
class SingleFileAttributeUpdaterTest {
|
||||||
|
|
||||||
|
private static Stream<Arguments> process() {
|
||||||
|
return Stream.of(
|
||||||
|
Arguments.of(
|
||||||
|
arr(a("ger:OFF")), a("ger:OFF"),
|
||||||
|
List.of(AUDIO_GER, SUB_GER_FORCED),
|
||||||
|
Map.ofEntries(on(AUDIO_GER), on(SUB_GER_FORCED)),
|
||||||
|
Map.ofEntries(),
|
||||||
|
Map.ofEntries(),
|
||||||
|
Map.ofEntries()
|
||||||
|
),
|
||||||
|
Arguments.of(
|
||||||
|
arr(a("ger:ger")), a("ger:ger"),
|
||||||
|
List.of(AUDIO_GER, SUB_GER, withName(AUDIO_GER, "SDH"), withName(AUDIO_GER, "commentary"), withName(SUB_GER, "Forced")),
|
||||||
|
Map.ofEntries(on(AUDIO_GER), on(SUB_GER)),
|
||||||
|
Map.ofEntries(on(withName(SUB_GER, "Forced"))),
|
||||||
|
Map.ofEntries(on(withName(AUDIO_GER, "commentary"))),
|
||||||
|
Map.ofEntries(on(withName(AUDIO_GER, "SDH")))
|
||||||
|
),
|
||||||
|
Arguments.of(
|
||||||
|
arr(a("ger:OFF")), a("ger:OFF"),
|
||||||
|
List.of(AUDIO_GER, SUB_GER, withName(AUDIO_GER, "SDH"), withName(AUDIO_GER, "commentary"), withName(SUB_GER, "Forced")),
|
||||||
|
Map.ofEntries(on(AUDIO_GER), on(withName(SUB_GER, "Forced"))),
|
||||||
|
Map.ofEntries(on(withName(SUB_GER, "Forced"))),
|
||||||
|
Map.ofEntries(on(withName(AUDIO_GER, "commentary"))),
|
||||||
|
Map.ofEntries(on(withName(AUDIO_GER, "SDH")))
|
||||||
|
),
|
||||||
|
Arguments.of(
|
||||||
|
arr(a("ger:eng")), null,
|
||||||
|
List.of(AUDIO_GER, SUB_GER, withName(AUDIO_GER, "SDH"), withName(AUDIO_GER, "commentary"), withName(SUB_GER, "Forced")),
|
||||||
|
Map.ofEntries(),
|
||||||
|
Map.ofEntries(on(withName(SUB_GER, "Forced"))),
|
||||||
|
Map.ofEntries(on(withName(AUDIO_GER, "commentary"))),
|
||||||
|
Map.ofEntries(on(withName(AUDIO_GER, "SDH")))
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@ParameterizedTest
|
||||||
|
@MethodSource("process")
|
||||||
|
void process(AttributeConfig[] attributeConfigs, AttributeConfig expectedMatch,
|
||||||
|
List<TrackAttributes> tracks,
|
||||||
|
Map<TrackAttributes, Boolean> defaultExp,
|
||||||
|
Map<TrackAttributes, Boolean> forcedExp,
|
||||||
|
Map<TrackAttributes, Boolean> commentaryExp,
|
||||||
|
Map<TrackAttributes, Boolean> hearingImpairedExp) {
|
||||||
|
InputConfig config = new InputConfig();
|
||||||
|
config.setThreads(1);
|
||||||
|
config.setSafeMode(true);
|
||||||
|
config.setAttributeConfig(attributeConfigs);
|
||||||
|
FileInfo fileInfo = new FileInfo(new File(TEST_DIR));
|
||||||
|
fileInfo.addTracks(tracks);
|
||||||
|
FileProcessor fileProcessor = spy(FileProcessor.class);
|
||||||
|
doReturn(fileInfo).when(fileProcessor).readAttributes(any());
|
||||||
|
AttributeChangeProcessor attributeChangeProcessor = new AttributeChangeProcessor(new String[]{"pref"}, Set.of("forced"), Set.of("commentary"), Set.of("SDH"));
|
||||||
|
SingleFileAttributeUpdater underTest = new SingleFileAttributeUpdater(config, fileProcessor, attributeChangeProcessor);
|
||||||
|
|
||||||
|
underTest.process(fileInfo.getFile());
|
||||||
|
|
||||||
|
assertEquals(expectedMatch, fileInfo.getMatchedConfig());
|
||||||
|
assertEquals(fileInfo.getChanges().getDefaultTrack().size(), defaultExp.size());
|
||||||
|
defaultExp.forEach((key, val) -> assertEquals(val, fileInfo.getChanges().getDefaultTrack().get(key), "Default track flag"));
|
||||||
|
|
||||||
|
assertEquals(fileInfo.getChanges().getForcedTrack().size(), forcedExp.size());
|
||||||
|
forcedExp.forEach((key, val) -> assertEquals(val, fileInfo.getChanges().getForcedTrack().get(key), "Forced track flag"));
|
||||||
|
|
||||||
|
assertEquals(fileInfo.getChanges().getCommentaryTrack().size(), commentaryExp.size());
|
||||||
|
commentaryExp.forEach((key, val) -> assertEquals(val, fileInfo.getChanges().getCommentaryTrack().get(key), "Commentary track flag"));
|
||||||
|
|
||||||
|
assertEquals(fileInfo.getChanges().getHearingImpairedTrack().size(), hearingImpairedExp.size());
|
||||||
|
hearingImpairedExp.forEach((key, val) -> assertEquals(val, fileInfo.getChanges().getHearingImpairedTrack().get(key), "Hearing Impaired track flag"));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,9 +1,12 @@
|
|||||||
package at.pcgamingfreaks.mkvaudiosubtitlechanger.util;
|
package at.pcgamingfreaks.mkvaudiosubtitlechanger.util;
|
||||||
|
|
||||||
|
import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.AttributeConfig;
|
||||||
import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.TrackAttributes;
|
import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.TrackAttributes;
|
||||||
import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.TrackType;
|
import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.TrackType;
|
||||||
|
|
||||||
public class FileInfoTestUtil {
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class TrackAttributeUtil {
|
||||||
public static final TrackAttributes AUDIO_GER = new TrackAttributes(0, "ger", "", false, false, false, false, TrackType.AUDIO);
|
public static final TrackAttributes AUDIO_GER = new TrackAttributes(0, "ger", "", false, false, false, false, TrackType.AUDIO);
|
||||||
public static final TrackAttributes AUDIO_ENG = new TrackAttributes(1, "eng", "", false, false, false, false, TrackType.AUDIO);
|
public static final TrackAttributes AUDIO_ENG = new TrackAttributes(1, "eng", "", false, false, false, false, TrackType.AUDIO);
|
||||||
public static final TrackAttributes AUDIO_GER_DEFAULT = new TrackAttributes(0, "ger", "", true, false, false, false, TrackType.AUDIO);
|
public static final TrackAttributes AUDIO_GER_DEFAULT = new TrackAttributes(0, "ger", "", true, false, false, false, TrackType.AUDIO);
|
||||||
@@ -27,4 +30,22 @@ public class FileInfoTestUtil {
|
|||||||
public static TrackAttributes withName(TrackAttributes track, String trackName) {
|
public static TrackAttributes withName(TrackAttributes track, String trackName) {
|
||||||
return new TrackAttributes(track.id(), track.language(), trackName, track.defaultt(), track.forced(), track.commentary(), track.hearingImpaired(), track.type());
|
return new TrackAttributes(track.id(), track.language(), trackName, track.defaultt(), track.forced(), track.commentary(), track.hearingImpaired(), track.type());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static AttributeConfig[] arr(AttributeConfig... configs) {
|
||||||
|
return configs;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static AttributeConfig a(String config) {
|
||||||
|
String[] split = config.split(":");
|
||||||
|
return new AttributeConfig(split[0], split[1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Map.Entry<TrackAttributes, Boolean> on(TrackAttributes track) {
|
||||||
|
return Map.entry(track, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Map.Entry<TrackAttributes, Boolean> off(TrackAttributes track) {
|
||||||
|
return Map.entry(track, false);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user