Migrate last execution handler to properties

This commit is contained in:
RatzzFatzz
2026-01-12 19:02:06 +01:00
parent 8dbfb22ed8
commit 3c57eb44ef
5 changed files with 48 additions and 53 deletions

View File

@@ -11,24 +11,25 @@ import java.time.Instant;
import static org.junit.jupiter.api.Assertions.*;
class LastExecutionHandlerTest {
private static final String LAST_EXECUTION_YML = "./last-execution.yml";
private static final String LAST_EXECUTION_YML = "./last-execution.properties";
private static final String TEST_MKV_FILE = "/arst/file.mkv";
@AfterEach
void destruct() {
File file = new File("./last-execution.yml");
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"));
LastExecutionHandler underTest = new LastExecutionHandler(LAST_EXECUTION_YML);
assertNull(underTest.get(TEST_MKV_FILE));
underTest.update(TEST_MKV_FILE);
assertNotNull(underTest.get(TEST_MKV_FILE));
underTest.persist();
File file = new File("./last-execution.yml");
File file = new File(LAST_EXECUTION_YML);
assertTrue(file.exists());
assertTrue(Files.readString(file.toPath()).contains("/arst: "));
assertTrue(Files.readString(file.toPath()).contains(TEST_MKV_FILE + "="));
}
@Test
@@ -42,28 +43,28 @@ class LastExecutionHandlerTest {
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());
Files.writeString(file.toPath(), TEST_MKV_FILE + "=" + Instant.now());
String expected = Files.readString(file.toPath()).replace(":", "\\:");
LastExecutionHandler underTest = new LastExecutionHandler(LAST_EXECUTION_YML);
assertNotNull(underTest.get("/arst"));
assertNotNull(underTest.get(TEST_MKV_FILE));
underTest.persist();
File file1 = new File(LAST_EXECUTION_YML);
assertTrue(file1.exists());
assertEquals(expected, Files.readString(file.toPath()));
assertTrue(Files.readString(file.toPath()).contains(expected), "File contains expected value");
}
@Test
void existingFileWithChanges() throws IOException {
File file = new File(LAST_EXECUTION_YML);
file.createNewFile();
Files.writeString(file.toPath(), "/arst: \"" + Instant.now() + "\"");
Files.writeString(file.toPath(), TEST_MKV_FILE + "=" + 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"));
assertNotNull(underTest.get(TEST_MKV_FILE));
underTest.update(TEST_MKV_FILE);
assertNotNull(underTest.get(TEST_MKV_FILE));
underTest.persist();
File file1 = new File(LAST_EXECUTION_YML);
assertTrue(file1.exists());