package de.antco.projekt.importers;

import de.antco.projekt.model.Person;
import org.junit.jupiter.api.Test;
import java.io.File;
import java.io.FileWriter;
import java.util.List;
import static org.junit.jupiter.api.Assertions.*;

class CsvPersonImporterTest {

    @Test
    void testImport() throws Exception {
        File tempFile = File.createTempFile("import_test", ".csv");
        tempFile.deleteOnExit();

        try (FileWriter writer = new FileWriter(tempFile)) {
            writer.write("Max Mustermann;0123456789\n");
            writer.write("Erika Musterfrau;9876543210\n");
        }

        CsvPersonImporter importer = new CsvPersonImporter();
        List<Person> persons = importer.importData(tempFile.getAbsolutePath());

        assertEquals(2, persons.size());
        assertEquals("Max Mustermann", persons.get(0).getName());
        assertEquals("0123456789", persons.get(0).getPhone());
        assertEquals("Erika Musterfrau", persons.get(1).getName());
        assertEquals("9876543210", persons.get(1).getPhone());
    }
}
