diff --git a/src/test/java/at/pcgamingfreaks/mkvaudiosubtitlechanger/impl/processors/CoherentAttributeUpdaterTest.java b/src/test/java/at/pcgamingfreaks/mkvaudiosubtitlechanger/impl/processors/CoherentAttributeUpdaterTest.java index 7f808c9..08ef0e5 100644 --- a/src/test/java/at/pcgamingfreaks/mkvaudiosubtitlechanger/impl/processors/CoherentAttributeUpdaterTest.java +++ b/src/test/java/at/pcgamingfreaks/mkvaudiosubtitlechanger/impl/processors/CoherentAttributeUpdaterTest.java @@ -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 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 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> tracks, + List> defaultExp, + List> forcedExp, + List> commentaryExp, + List> hearingImpairedExp) { + InputConfig config = new InputConfig(); + config.setThreads(1); + config.setSafeMode(true); + config.setAttributeConfig(attributeConfigs); + FileProcessor fileProcessor = spy(FileProcessor.class); + + List testMkvFiles = new ArrayList<>(); + List testFileInfo = new ArrayList<>(); + for (int i = 0; i < tracks.size(); i++) { + List 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")); + } + + } } \ No newline at end of file