diff --git a/src/main/java/at/pcgamingfreaks/mkvaudiosubtitlechanger/impl/processors/AttributeUpdater.java b/src/main/java/at/pcgamingfreaks/mkvaudiosubtitlechanger/impl/processors/AttributeUpdater.java index 33bbce8..d49f385 100644 --- a/src/main/java/at/pcgamingfreaks/mkvaudiosubtitlechanger/impl/processors/AttributeUpdater.java +++ b/src/main/java/at/pcgamingfreaks/mkvaudiosubtitlechanger/impl/processors/AttributeUpdater.java @@ -30,7 +30,7 @@ public abstract class AttributeUpdater { public AttributeUpdater(InputConfig config, FileProcessor fileProcessor) { this.config = config; this.fileProcessor = fileProcessor; - this.attributeChangeProcessor = new AttributeChangeProcessor(config.getPreferredSubtitles().toArray(new String[0]), config.getForcedKeywords(), config.getCommentaryKeywords(), config.getHearingImpaired()); + this.attributeChangeProcessor = attributeChangeProcessor; this.executor = Executors.newFixedThreadPool(config.getThreads()); } diff --git a/src/main/java/at/pcgamingfreaks/mkvaudiosubtitlechanger/impl/processors/CoherentAttributeUpdater.java b/src/main/java/at/pcgamingfreaks/mkvaudiosubtitlechanger/impl/processors/CoherentAttributeUpdater.java index 355bcd5..5f13ea1 100644 --- a/src/main/java/at/pcgamingfreaks/mkvaudiosubtitlechanger/impl/processors/CoherentAttributeUpdater.java +++ b/src/main/java/at/pcgamingfreaks/mkvaudiosubtitlechanger/impl/processors/CoherentAttributeUpdater.java @@ -14,8 +14,8 @@ import java.util.Set; @Slf4j public class CoherentAttributeUpdater extends SingleFileAttributeUpdater { - public CoherentAttributeUpdater(InputConfig config, FileProcessor processor) { - super(config, processor); + public CoherentAttributeUpdater(InputConfig config, FileProcessor processor, AttributeChangeProcessor attributeChangeProcessor) { + super(config, processor, attributeChangeProcessor); } @Override diff --git a/src/main/java/at/pcgamingfreaks/mkvaudiosubtitlechanger/impl/processors/SingleFileAttributeUpdater.java b/src/main/java/at/pcgamingfreaks/mkvaudiosubtitlechanger/impl/processors/SingleFileAttributeUpdater.java index ece4918..7c4c283 100644 --- a/src/main/java/at/pcgamingfreaks/mkvaudiosubtitlechanger/impl/processors/SingleFileAttributeUpdater.java +++ b/src/main/java/at/pcgamingfreaks/mkvaudiosubtitlechanger/impl/processors/SingleFileAttributeUpdater.java @@ -11,8 +11,8 @@ import java.util.List; @Slf4j public class SingleFileAttributeUpdater extends AttributeUpdater { - public SingleFileAttributeUpdater(InputConfig config, FileProcessor processor) { - super(config, processor); + public SingleFileAttributeUpdater(InputConfig config, FileProcessor processor, AttributeChangeProcessor attributeChangeProcessor) { + super(config, processor, attributeChangeProcessor); } @Override diff --git a/src/main/java/at/pcgamingfreaks/mkvaudiosubtitlechanger/model/ResultStatistic.java b/src/main/java/at/pcgamingfreaks/mkvaudiosubtitlechanger/model/ResultStatistic.java index 428aa38..1e1fe12 100644 --- a/src/main/java/at/pcgamingfreaks/mkvaudiosubtitlechanger/model/ResultStatistic.java +++ b/src/main/java/at/pcgamingfreaks/mkvaudiosubtitlechanger/model/ResultStatistic.java @@ -16,10 +16,6 @@ public class ResultStatistic { private int excluded = 0; private int unknownFailed = 0; - private int noSuitableConfigFound = 0; - private int alreadyFits = 0; - private int failed = 0; - private long startTime = 0; private long runtime = 0; @@ -35,11 +31,7 @@ public class ResultStatistic { } public int total() { - return changePlanned + noSuitableConfigFound + alreadyFits + failed; - } - - public void increaseExcludedBy(int amount) { - excluded += amount; + return changePlanned + unchanged + excluded + unknownFailed; } public synchronized void changePlanned() { diff --git a/src/test/java/at/pcgamingfreaks/mkvaudiosubtitlechanger/impl/processors/AttributeUpdaterTest.java b/src/test/java/at/pcgamingfreaks/mkvaudiosubtitlechanger/impl/processors/AttributeUpdaterTest.java new file mode 100644 index 0000000..fb32ac8 --- /dev/null +++ b/src/test/java/at/pcgamingfreaks/mkvaudiosubtitlechanger/impl/processors/AttributeUpdaterTest.java @@ -0,0 +1,64 @@ +package at.pcgamingfreaks.mkvaudiosubtitlechanger.impl.processors; + +import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.*; +import org.junit.jupiter.api.BeforeEach; +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.function.Supplier; +import java.util.stream.Stream; + +import static at.pcgamingfreaks.mkvaudiosubtitlechanger.util.FileInfoTestUtil.AUDIO_GER; +import static org.junit.jupiter.api.Assertions.*; + +class AttributeUpdaterTest { + + @BeforeEach + void setup() { + ResultStatistic.getInstance(true); + } + + private static Stream checkStatusAndUpdate() { + return Stream.of( + Arguments.of(info(new AttributeConfig("ger", "ger"), AUDIO_GER), supplier(() -> ResultStatistic.getInstance().getChangePlanned())), + Arguments.of(info(new AttributeConfig("ger", "ger"), null), supplier(() -> ResultStatistic.getInstance().getUnchanged())), + Arguments.of(info(null, null), supplier(() -> ResultStatistic.getInstance().getUnchanged())) + ); + } + + @ParameterizedTest + @MethodSource("checkStatusAndUpdate") + void checkStatusAndUpdate(FileInfo fileInfo, Supplier getActual) { + InputConfig config = new InputConfig(); + config.setThreads(1); + config.setSafeMode(true); + AttributeUpdater underTest = new AttributeUpdater(config, null, null) { + @Override + protected List getFiles() { + return List.of(); + } + + @Override + protected void process(File file) { + + } + }; + + underTest.checkStatusAndUpdate(fileInfo); + assertEquals(1, getActual.get()); + } + + private static Supplier supplier(Supplier supplier) { + return supplier; + } + + private static FileInfo info(AttributeConfig config, TrackAttributes attr) { + FileInfo fileInfo = new FileInfo(null); + fileInfo.setMatchedConfig(config); + if(attr != null) fileInfo.getChanges().getDefaultTrack().put(attr, true); + return fileInfo; + } +} \ No newline at end of file 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 47aa3e5..b851085 100644 --- a/src/test/java/at/pcgamingfreaks/mkvaudiosubtitlechanger/impl/processors/CoherentAttributeUpdaterTest.java +++ b/src/test/java/at/pcgamingfreaks/mkvaudiosubtitlechanger/impl/processors/CoherentAttributeUpdaterTest.java @@ -67,7 +67,7 @@ class CoherentAttributeUpdaterTest { CommandRunner commandRunner = new CommandRunner(); new CommandLine(commandRunner).parseArgs("-l", "/arst", "-a", "ger:ger"); InputConfig config = commandRunner.getConfig(); - CoherentAttributeUpdater updater = new CoherentAttributeUpdater(config, fileProcessor); + CoherentAttributeUpdater updater = new CoherentAttributeUpdater(config, fileProcessor, null); Set matchedFiles = new HashSet<>(fileInfoMock.size() * 2); List files = new ArrayList<>(); diff --git a/src/test/java/at/pcgamingfreaks/mkvaudiosubtitlechanger/model/FileInfoTest.java b/src/test/java/at/pcgamingfreaks/mkvaudiosubtitlechanger/model/FileInfoTest.java deleted file mode 100644 index 72ee92a..0000000 --- a/src/test/java/at/pcgamingfreaks/mkvaudiosubtitlechanger/model/FileInfoTest.java +++ /dev/null @@ -1,39 +0,0 @@ -package at.pcgamingfreaks.mkvaudiosubtitlechanger.model; - -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.Arguments; -import org.junit.jupiter.params.provider.MethodSource; - -import java.nio.file.attribute.FileAttribute; -import java.util.Set; -import java.util.stream.Stream; - -import static at.pcgamingfreaks.mkvaudiosubtitlechanger.model.FileStatus.*; -import static at.pcgamingfreaks.mkvaudiosubtitlechanger.util.FileInfoTestUtil.*; -import static at.pcgamingfreaks.mkvaudiosubtitlechanger.util.TestUtil.*; -import static org.junit.jupiter.api.Assertions.*; - -class FileInfoTest { - - private static Stream getStatus() { - return Stream.of( - Arguments.of(CHANGE_NECESSARY, info(new AttributeConfig("ger", "ger"), AUDIO_GER)), - Arguments.of(ALREADY_SUITED, info(new AttributeConfig("ger", "ger"), null)), - Arguments.of(NO_SUITABLE_CONFIG, info(null, null)) - ); - } - - @ParameterizedTest - @MethodSource - void getStatus(FileStatus expected, FileInfo underTest) { - FileStatus actual = underTest.getStatus(); - assertEquals(expected, actual); - } - - private static FileInfo info(AttributeConfig config, TrackAttributes attr) { - FileInfo fileInfo = new FileInfo(null); - fileInfo.setMatchedConfig(config); - if(attr != null) fileInfo.getChanges().getDefaultTrack().put(attr, true); - return fileInfo; - } -} \ No newline at end of file