package de.gecheckt.pdf.umbenenner.adapter.in.gui.editor;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotSame;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.nio.file.Path;
import java.util.Properties;

import org.junit.jupiter.api.Test;

class GuiConfigurationFileSnapshotTest {

    @Test
    void propertiesAreDefensivelyCopiedOnRead() {
        Properties properties = new Properties();
        properties.setProperty("source.folder", "./source");

        GuiConfigurationFileSnapshot snapshot = new GuiConfigurationFileSnapshot(Path.of("config/application.properties"), properties);

        Properties firstRead = snapshot.properties();
        firstRead.setProperty("source.folder", "./changed");

        Properties secondRead = snapshot.properties();
        assertNotSame(firstRead, secondRead);
        assertEquals("./source", secondRead.getProperty("source.folder"));
        assertTrue(snapshot.hasFilePath(Path.of("config/application.properties")));
    }
}
