Add handler for only new files parameter

This commit is contained in:
RatzzFatzz
2026-01-08 22:03:06 +01:00
parent 1165dd8380
commit a5aae0acf4
12 changed files with 178 additions and 29 deletions

View File

@@ -71,7 +71,7 @@ class FileFilterTest {
when(file.toPath()).thenReturn(Path.of(TEST_FILE));
long currentTime = System.currentTimeMillis();
FileFilter fileFilter = new FileFilter(excludedDirs, Pattern.compile(pattern), new Date(currentTime + filterDateOffset));
FileFilter fileFilter = new FileFilter(excludedDirs, Pattern.compile(pattern), new Date(currentTime + filterDateOffset), null);
try (MockedStatic<DateUtils> mockedFiles = Mockito.mockStatic(DateUtils.class)) {
mockedFiles

View File

@@ -0,0 +1,72 @@
package at.pcgamingfreaks.mkvaudiosubtitlechanger.impl;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.time.Instant;
import static org.junit.jupiter.api.Assertions.*;
class LastExecutionHandlerTest {
private static final String LAST_EXECUTION_YML = "./last-execution.yml";
@AfterEach
void destruct() {
File file = new File("./last-execution.yml");
if (file.exists()) file.delete();
}
@Test
void missingFile() throws IOException {
LastExecutionHandler underTest = new LastExecutionHandler("./last-execution.yml");
assertNull(underTest.get("/arst"));
underTest.update("/arst");
assertNotNull(underTest.get("/arst"));
underTest.persist();
File file = new File("./last-execution.yml");
assertTrue(file.exists());
assertTrue(Files.readString(file.toPath()).contains("/arst: "));
}
@Test
void emptyFile() throws IOException {
File file = new File(LAST_EXECUTION_YML);
file.createNewFile();
missingFile(); // does the checks needed for empty file case
}
@Test
void existingFileNoChanges() throws IOException {
File file = new File(LAST_EXECUTION_YML);
file.createNewFile();
Files.writeString(file.toPath(), "/arst: \"" + Instant.now() + "\"");
String expected = Files.readString(file.toPath());
LastExecutionHandler underTest = new LastExecutionHandler(LAST_EXECUTION_YML);
assertNotNull(underTest.get("/arst"));
underTest.persist();
File file1 = new File(LAST_EXECUTION_YML);
assertTrue(file1.exists());
assertEquals(expected, Files.readString(file.toPath()));
}
@Test
void existingFileWithChanges() throws IOException {
File file = new File(LAST_EXECUTION_YML);
file.createNewFile();
Files.writeString(file.toPath(), "/arst: \"" + Instant.now() + "\"");
String expected = Files.readString(file.toPath());
LastExecutionHandler underTest = new LastExecutionHandler(LAST_EXECUTION_YML);
assertNotNull(underTest.get("/arst"));
underTest.update("/arst");
assertNotNull(underTest.get("/arst"));
underTest.persist();
File file1 = new File(LAST_EXECUTION_YML);
assertTrue(file1.exists());
assertNotEquals(expected, Files.readString(file.toPath()));
}
}

View File

@@ -1,5 +1,6 @@
package at.pcgamingfreaks.mkvaudiosubtitlechanger.impl.processors;
import at.pcgamingfreaks.mkvaudiosubtitlechanger.impl.LastExecutionHandler;
import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.*;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.params.ParameterizedTest;
@@ -36,7 +37,7 @@ class AttributeUpdaterTest {
InputConfig config = new InputConfig();
config.setThreads(1);
config.setSafeMode(true);
AttributeUpdater underTest = new AttributeUpdater(config, null, null) {
AttributeUpdater underTest = new AttributeUpdater(config, null, null, new LastExecutionHandler("")) {
@Override
protected List<File> getFiles() {
return List.of();

View File

@@ -1,12 +1,12 @@
package at.pcgamingfreaks.mkvaudiosubtitlechanger.impl.processors;
import at.pcgamingfreaks.mkvaudiosubtitlechanger.impl.CommandRunner;
import at.pcgamingfreaks.mkvaudiosubtitlechanger.impl.LastExecutionHandler;
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.apache.commons.lang3.tuple.Pair;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
@@ -66,7 +66,8 @@ class CoherentAttributeUpdaterTest {
new CommandLine(commandRunner).parseArgs("-a", "ger:ger", "/arst");
InputConfig config = commandRunner.getConfig();
AttributeChangeProcessor attributeChangeProcessor = new AttributeChangeProcessor(config.getPreferredSubtitles().toArray(new String[0]), config.getForcedKeywords(), config.getCommentaryKeywords(), config.getHearingImpaired());
CoherentAttributeUpdater updater = new CoherentAttributeUpdater(config, fileProcessor, attributeChangeProcessor);
LastExecutionHandler lastExecutionHandler = new LastExecutionHandler("");
CoherentAttributeUpdater updater = new CoherentAttributeUpdater(config, fileProcessor, attributeChangeProcessor, lastExecutionHandler);
Set<FileInfo> matchedFiles = new HashSet<>(fileInfoMock.size() * 2);
List<File> files = new ArrayList<>();
@@ -193,7 +194,8 @@ class CoherentAttributeUpdaterTest {
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);
LastExecutionHandler lastExecutionHandler = new LastExecutionHandler("");
CoherentAttributeUpdater underTest = new CoherentAttributeUpdater(config, fileProcessor, attributeChangeProcessor, lastExecutionHandler);
underTest.process(new File(""));

View File

@@ -1,10 +1,10 @@
package at.pcgamingfreaks.mkvaudiosubtitlechanger.impl.processors;
import at.pcgamingfreaks.mkvaudiosubtitlechanger.impl.LastExecutionHandler;
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;
@@ -16,7 +16,6 @@ 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;
@@ -78,7 +77,8 @@ class SingleFileAttributeUpdaterTest {
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);
LastExecutionHandler lastExecutionHandler = new LastExecutionHandler("");
SingleFileAttributeUpdater underTest = new SingleFileAttributeUpdater(config, fileProcessor, attributeChangeProcessor, lastExecutionHandler);
underTest.process(fileInfo.getFile());