mirror of
https://github.com/RatzzFatzz/MKVAudioSubtitleChanger.git
synced 2026-02-10 17:55:57 +01:00
Add tests for coherent file attribute updater
This commit is contained in:
@@ -21,19 +21,17 @@ import java.lang.reflect.Method;
|
||||
import java.util.*;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import static at.pcgamingfreaks.mkvaudiosubtitlechanger.util.PathUtils.TEST_DIR;
|
||||
import static at.pcgamingfreaks.mkvaudiosubtitlechanger.util.TrackAttributeUtil.*;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class CoherentAttributeUpdaterTest {
|
||||
@Mock(lenient = true)
|
||||
FileProcessor fileProcessor;
|
||||
|
||||
@Test
|
||||
void process() {
|
||||
}
|
||||
|
||||
private static Stream<Arguments> findMatch() {
|
||||
return Stream.of(
|
||||
Arguments.of(AttributeConfig.of("ger", "ger"),
|
||||
@@ -91,4 +89,129 @@ class CoherentAttributeUpdaterTest {
|
||||
fileInfo.addTracks(List.of(tracks));
|
||||
return Pair.of(file, fileInfo);
|
||||
}
|
||||
|
||||
private static Stream<Arguments> process() {
|
||||
return Stream.of(
|
||||
Arguments.of(
|
||||
arr(a("ger:ger")), a("ger:ger"),
|
||||
List.of(
|
||||
List.of(AUDIO_GER, SUB_GER),
|
||||
List.of(AUDIO_GER, SUB_GER)
|
||||
),
|
||||
List.of(
|
||||
Map.ofEntries(on(AUDIO_GER), on(SUB_GER)),
|
||||
Map.ofEntries(on(AUDIO_GER), on(SUB_GER))
|
||||
),
|
||||
List.of(
|
||||
Map.ofEntries(),
|
||||
Map.ofEntries()
|
||||
),
|
||||
List.of(
|
||||
Map.ofEntries(),
|
||||
Map.ofEntries()
|
||||
),
|
||||
List.of(
|
||||
Map.ofEntries(),
|
||||
Map.ofEntries()
|
||||
)
|
||||
),
|
||||
Arguments.of(
|
||||
arr(a("eng:eng"), a("ger:ger")), a("ger:ger"),
|
||||
List.of(
|
||||
List.of(SUB_ENG, AUDIO_GER, SUB_GER),
|
||||
List.of(AUDIO_ENG, SUB_ENG, AUDIO_GER, SUB_GER)
|
||||
),
|
||||
List.of(
|
||||
Map.ofEntries(on(AUDIO_GER), on(SUB_GER)),
|
||||
Map.ofEntries(on(AUDIO_GER), on(SUB_GER))
|
||||
),
|
||||
List.of(
|
||||
Map.ofEntries(),
|
||||
Map.ofEntries()
|
||||
),
|
||||
List.of(
|
||||
Map.ofEntries(),
|
||||
Map.ofEntries()
|
||||
),
|
||||
List.of(
|
||||
Map.ofEntries(),
|
||||
Map.ofEntries()
|
||||
)
|
||||
),
|
||||
Arguments.of(
|
||||
arr(a("eng:eng"), a("ger:ger")), a("eng:eng"),
|
||||
List.of(
|
||||
List.of(AUDIO_ENG, withName(SUB_ENG, "SDH"), AUDIO_GER, SUB_GER),
|
||||
List.of(AUDIO_ENG, SUB_ENG, AUDIO_GER, SUB_GER)
|
||||
),
|
||||
List.of(
|
||||
Map.ofEntries(on(AUDIO_ENG), on(withName(SUB_ENG, "SDH"))),
|
||||
Map.ofEntries(on(AUDIO_ENG), on(SUB_ENG))
|
||||
),
|
||||
List.of(
|
||||
Map.ofEntries(),
|
||||
Map.ofEntries()
|
||||
),
|
||||
List.of(
|
||||
Map.ofEntries(),
|
||||
Map.ofEntries()
|
||||
),
|
||||
List.of(
|
||||
Map.ofEntries(on(withName(SUB_ENG, "SDH"))),
|
||||
Map.ofEntries()
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("process")
|
||||
void process(AttributeConfig[] attributeConfigs, AttributeConfig expectedMatch,
|
||||
List<List<TrackAttributes>> tracks,
|
||||
List<Map<TrackAttributes, Boolean>> defaultExp,
|
||||
List<Map<TrackAttributes, Boolean>> forcedExp,
|
||||
List<Map<TrackAttributes, Boolean>> commentaryExp,
|
||||
List<Map<TrackAttributes, Boolean>> hearingImpairedExp) {
|
||||
InputConfig config = new InputConfig();
|
||||
config.setThreads(1);
|
||||
config.setSafeMode(true);
|
||||
config.setAttributeConfig(attributeConfigs);
|
||||
FileProcessor fileProcessor = spy(FileProcessor.class);
|
||||
|
||||
List<File> testMkvFiles = new ArrayList<>();
|
||||
List<FileInfo> testFileInfo = new ArrayList<>();
|
||||
for (int i = 0; i < tracks.size(); i++) {
|
||||
List<TrackAttributes> tracks1 = tracks.get(i);
|
||||
File file = new File(TEST_DIR + i);
|
||||
FileInfo fileInfo = new FileInfo(file);
|
||||
fileInfo.addTracks(tracks1);
|
||||
doReturn(fileInfo).when(fileProcessor).readAttributes(file);
|
||||
|
||||
testMkvFiles.add(file);
|
||||
testFileInfo.add(fileInfo);
|
||||
}
|
||||
doReturn(testMkvFiles).when(fileProcessor).loadFiles(any());
|
||||
|
||||
AttributeChangeProcessor attributeChangeProcessor = new AttributeChangeProcessor(new String[]{"pref"}, Set.of("forced"), Set.of("commentary"), Set.of("SDH"));
|
||||
CoherentAttributeUpdater underTest = new CoherentAttributeUpdater(config, fileProcessor, attributeChangeProcessor);
|
||||
|
||||
underTest.process(new File(""));
|
||||
|
||||
for (int i = 0; i < testFileInfo.size(); i++) {
|
||||
FileInfo fileInfo = testFileInfo.get(i);
|
||||
assertEquals(expectedMatch, fileInfo.getMatchedConfig());
|
||||
assertEquals(fileInfo.getChanges().getDefaultTrack().size(), defaultExp.get(i).size());
|
||||
defaultExp.get(i).forEach((key, val) -> assertEquals(val, fileInfo.getChanges().getDefaultTrack().get(key), "Default track flag"));
|
||||
|
||||
assertEquals(fileInfo.getChanges().getForcedTrack().size(), forcedExp.get(i).size());
|
||||
forcedExp.get(i).forEach((key, val) -> assertEquals(val, fileInfo.getChanges().getForcedTrack().get(key), "Forced track flag"));
|
||||
|
||||
assertEquals(fileInfo.getChanges().getCommentaryTrack().size(), commentaryExp.get(i).size());
|
||||
commentaryExp.get(i).forEach((key, val) -> assertEquals(val, fileInfo.getChanges().getCommentaryTrack().get(key), "Commentary track flag"));
|
||||
|
||||
assertEquals(fileInfo.getChanges().getHearingImpairedTrack().size(), hearingImpairedExp.get(i).size());
|
||||
hearingImpairedExp.get(i).forEach((key, val) -> assertEquals(val, fileInfo.getChanges().getHearingImpairedTrack().get(key), "Hearing Impaired track flag"));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user