mirror of
https://github.com/RatzzFatzz/MKVAudioSubtitleChanger.git
synced 2026-02-10 17:55:57 +01:00
Improve status detection
This commit is contained in:
@@ -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());
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -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<Arguments> 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<Integer> getActual) {
|
||||
InputConfig config = new InputConfig();
|
||||
config.setThreads(1);
|
||||
config.setSafeMode(true);
|
||||
AttributeUpdater underTest = new AttributeUpdater(config, null, null) {
|
||||
@Override
|
||||
protected List<File> getFiles() {
|
||||
return List.of();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void process(File file) {
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
underTest.checkStatusAndUpdate(fileInfo);
|
||||
assertEquals(1, getActual.get());
|
||||
}
|
||||
|
||||
private static Supplier<Integer> supplier(Supplier<Integer> 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;
|
||||
}
|
||||
}
|
||||
@@ -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<FileInfo> matchedFiles = new HashSet<>(fileInfoMock.size() * 2);
|
||||
|
||||
List<File> files = new ArrayList<>();
|
||||
|
||||
@@ -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<Arguments> 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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user