package com.epimorphics.registry.language.message;

import org.junit.Test;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.nio.file.Files;

import static org.junit.Assert.*;

public class FileMessageManagerTest {
    private String srcDirPath;
    private FileMessageManager file;

    public FileMessageManagerTest() throws IOException {
        File configDir = Files.createTempDirectory("FileMessageManagerTest").toFile();
        configDir.deleteOnExit();

        File enProps = new File(configDir, "en.properties");

        new FileWriter(enProps)
                .append("name.label = Name\n")
                .append("surname.label = Surname\n")
                .append("welcome.heading = Welcome {0} {1}!")
                .close();

        File frProps = new File(configDir, "fr.properties");

        new FileWriter(frProps)
                .append("name.label = Prenom\n")
                .append("surname.label = Nom\n")
                .append("welcome.heading = Bienvenue {0} {1}!")
                .close();

        this.srcDirPath = configDir.getAbsolutePath();
        this.file = new FileMessageManager(srcDirPath);
    }

    @Test
    public void test() {
        Messages en = file.getMessages("en");
        assertNotNull(en);
        assertEquals("Name", en.get("name.label"));
        assertEquals("Surname", en.get("surname.label"));
        assertEquals("Welcome John Smith!", en.get("welcome.heading", "John", "Smith"));
        assertEquals("[ MESSAGE MISSING ]", en.get("footer.email.field"));

        Messages fr = file.getMessages("fr");
        assertNotNull(fr);
        assertEquals("Prenom", fr.get("name.label"));
        assertEquals("Nom", fr.get("surname.label"));
        assertEquals("Bienvenue Céline Renée!", fr.get("welcome.heading", "Céline", "Renée"));
        assertEquals("[ MESSAGE MISSING ]", fr.get("footer.email.field"));

        Messages gr = file.getMessages("gr");
        assertNull(gr);
    }
}

@@ -251,39 +251,8 @@
 t %7B%0A
-    private String srcDirPath;%0A
     
@@ -1034,63 +1034,8 @@
 );%0A%0A
-        this.srcDirPath = configDir.getAbsolutePath();%0A
     
@@ -1077,18 +1077,35 @@
 ger(
-srcDir
+configDir.getAbsolute
 Path
+()
 );%0A 

Clean up FileMessageManagerTest